+ if (getenv("XDG_RUNTIME_DIR") == nullptr) {
+ logerror("Environment variable XDG_RUNTIME_DIR not set");
+ goto error;
+ }
+
+ g_afb_instance = new afb_instance;
+ if (g_afb_instance->init() == -1) {
+ logerror("Could not connect to compositor");
+ goto error;
+ }
+
+ {
+ int ret = sd_event_add_io(afb_daemon_get_event_loop(), nullptr,
+ g_afb_instance->display->get_fd(), EPOLLIN,
+ display_event_callback, g_afb_instance);
+ if (ret < 0) {
+ logerror("Could not initialize afb_instance event handler: %d", -ret);
+ goto error;
+ }
+ }
+
+ atexit([] { delete g_afb_instance; });