From ba5360ac03286364abd9fde6b500e2c0fabe56b1 Mon Sep 17 00:00:00 2001 From: Marcus Fritzsch Date: Thu, 6 Jul 2017 09:38:15 +0200 Subject: [PATCH] main: further simplification Signed-off-by: Marcus Fritzsch --- src/main.cpp | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 03aa202..1ac26f1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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(); -- 2.16.6