main: further simplification
authorMarcus Fritzsch <marcus_fritzsch@mentor.com>
Thu, 6 Jul 2017 07:38:15 +0000 (09:38 +0200)
committerMarcus Fritzsch <marcus_fritzsch@mentor.com>
Tue, 8 Aug 2017 15:24:00 +0000 (17:24 +0200)
Signed-off-by: Marcus Fritzsch <marcus_fritzsch@mentor.com>
src/main.cpp

index 03aa202..1ac26f1 100644 (file)
@@ -154,33 +154,44 @@ int binding_init_() {
 
    if (g_wayland != nullptr) {
       AFB_ERROR("Wayland context already initialized?");
-      return -1;
+      return 0;
    }
 
    if (getenv("XDG_RUNTIME_DIR") == nullptr) {
       AFB_ERROR("Environment variable XDG_RUNTIME_DIR not set");
-      return -1;
+      goto error;
    }
 
    g_wayland = new wayland;
    if (g_wayland->init() == -1) {
       AFB_ERROR("Could not connect to compositor");
-      delete g_wayland;
-      return -1;
+      goto error;
    }
 
    if (char const *e = init_layout()) {
       AFB_ERROR("Could not init layout: %s", e);
-      return -1;
+      goto error;
    }
 
-   sd_event_add_io(afb_daemon_get_event_loop(), nullptr,
-                   g_wayland->display->get_fd(), EPOLLIN,
-                   display_event_callback, g_wayland);
+   {
+      int ret = sd_event_add_io(afb_daemon_get_event_loop(), nullptr,
+                                g_wayland->display->get_fd(), EPOLLIN,
+                                display_event_callback, g_wayland);
+      if (ret < 0) {
+                 AFB_ERROR("Could not initialize wayland event handler: %s",
+                           std::strerror(-ret));
+         goto error;
+      }
+   }
 
    atexit([] { delete g_wayland; });
 
    return 0;
+
+error:
+   delete g_wayland;
+   g_wayland = nullptr;
+   return -1;
 }
 
 int binding_init() noexcept {
@@ -248,7 +259,7 @@ void debug_status(struct afb_req req) noexcept {
    }
 }
 
-void debug_surfaces(afb_req req) {
+void debug_surfaces(afb_req req) noexcept {
    CHECK_WAYLAND();
 
    auto a = json_object_new_array();
@@ -262,7 +273,7 @@ void debug_surfaces(afb_req req) {
    afb_req_success(req, a, "surfaces");
 }
 
-void debug_layers(afb_req req) {
+void debug_layers(afb_req req) noexcept {
    CHECK_WAYLAND();
 
    auto a = json_object_new_array();