From aa7de33e03c0365e98d05bfb493a5fb5ae09ca3f Mon Sep 17 00:00:00 2001 From: Anurup M Date: Thu, 3 Dec 2020 07:55:04 +0530 Subject: [PATCH] launcher: Add more error logging to launcher backends Add error logging in three different launcher backends: launcher-logind, launcher-weston-launch, and launcher-direct to indicate failures for easier debug Signed-off-by: Anurup M --- libweston/launcher-direct.c | 21 ++++++++++++++++----- libweston/launcher-impl.h | 1 + libweston/launcher-logind.c | 22 ++++++++++++++++++---- libweston/launcher-util.c | 1 + libweston/launcher-weston-launch.c | 15 ++++++++++++--- 5 files changed, 48 insertions(+), 12 deletions(-) diff --git a/libweston/launcher-direct.c b/libweston/launcher-direct.c index d687ce3a..8ed34f5f 100644 --- a/libweston/launcher-direct.c +++ b/libweston/launcher-direct.c @@ -211,8 +211,10 @@ setup_tty(struct launcher_direct *launcher, int tty) loop = wl_display_get_event_loop(launcher->compositor->wl_display); launcher->vt_source = wl_event_loop_add_signal(loop, SIGRTMIN, vt_handler, launcher); - if (!launcher->vt_source) + if (!launcher->vt_source) { + weston_log("failed to add SIGRTMIN signal\n"); goto err_close; + } return 0; @@ -229,8 +231,10 @@ launcher_direct_open(struct weston_launcher *launcher_base, const char *path, in int fd; fd = open(path, flags | O_CLOEXEC); - if (fd == -1) + if (fd == -1) { + weston_log("couldn't open: %s! error=%s\n", path, strerror(errno)); return -1; + } if (geteuid() != 0) { weston_log("WARNING! Succeeded opening %s as non-root user." @@ -239,6 +243,7 @@ launcher_direct_open(struct weston_launcher *launcher_base, const char *path, in } if (fstat(fd, &s) == -1) { + weston_log("couldn't fstat: %s! error=%s\n", path, strerror(errno)); close(fd); return -1; } @@ -283,7 +288,8 @@ launcher_direct_restore(struct weston_launcher *launcher_base) mode.mode = VT_AUTO; if (ioctl(launcher->tty, VT_SETMODE, &mode) < 0) - weston_log("could not reset vt handling\n"); + weston_log("could not reset vt handling! error=%s\n", + strerror(errno)); } static int @@ -300,8 +306,10 @@ launcher_direct_connect(struct weston_launcher **out, struct weston_compositor * struct launcher_direct *launcher; launcher = zalloc(sizeof(*launcher)); - if (launcher == NULL) + if (launcher == NULL) { + weston_log("failed to alloc for launcher\n"); return -ENOMEM; + } launcher->base.iface = &launcher_direct_iface; launcher->compositor = compositor; @@ -338,13 +346,16 @@ launcher_direct_get_vt(struct weston_launcher *base) { struct launcher_direct *launcher = wl_container_of(base, launcher, base); struct stat s; - if (fstat(launcher->tty, &s) < 0) + if (fstat(launcher->tty, &s) < 0) { + weston_log("couldn't fstat launcher tty: %s\n", strerror(errno)); return -1; + } return minor(s.st_rdev); } const struct launcher_interface launcher_direct_iface = { + .name = "direct", .connect = launcher_direct_connect, .destroy = launcher_direct_destroy, .open = launcher_direct_open, diff --git a/libweston/launcher-impl.h b/libweston/launcher-impl.h index 4161caff..a04647ef 100644 --- a/libweston/launcher-impl.h +++ b/libweston/launcher-impl.h @@ -30,6 +30,7 @@ struct weston_launcher; struct launcher_interface { + char *name; int (* connect) (struct weston_launcher **launcher_out, struct weston_compositor *compositor, int tty, const char *seat_id, bool sync_drm); void (* destroy) (struct weston_launcher *launcher); diff --git a/libweston/launcher-logind.c b/libweston/launcher-logind.c index 9b3c52fa..55db326a 100644 --- a/libweston/launcher-logind.c +++ b/libweston/launcher-logind.c @@ -97,6 +97,7 @@ launcher_logind_take_device(struct launcher_logind *wl, uint32_t major, reply = dbus_connection_send_with_reply_and_block(wl->dbus, m, -1, NULL); if (!reply) { + weston_log("logind: TakeDevice on %d:%d failed.\n", major, minor); r = -ENODEV; goto err_unref; } @@ -106,6 +107,7 @@ launcher_logind_take_device(struct launcher_logind *wl, uint32_t major, DBUS_TYPE_BOOLEAN, &paused, DBUS_TYPE_INVALID); if (!b) { + weston_log("logind: error parsing reply to TakeDevice.\n"); r = -ENODEV; goto err_reply; } @@ -173,17 +175,25 @@ launcher_logind_open(struct weston_launcher *launcher, const char *path, int fla int fl, r, fd; r = stat(path, &st); - if (r < 0) + if (r < 0) { + weston_log("logind: cannot stat: %s! error=%s\n", path, strerror(errno)); return -1; + } + if (!S_ISCHR(st.st_mode)) { + weston_log("logind: %s is not a character special file!\n", path); errno = ENODEV; return -1; } fd = launcher_logind_take_device(wl, major(st.st_rdev), minor(st.st_rdev), NULL); - if (fd < 0) - return fd; + if (fd < 0) { + weston_log("logind: TakeDevice on %s failed, error=%s\n", + path, strerror(-fd)); + errno = -fd; + return -1; + } /* Compared to weston_launcher_open() we cannot specify the open-mode * directly. Instead, logind passes us an fd with sane default modes. @@ -195,6 +205,7 @@ launcher_logind_open(struct weston_launcher *launcher, const char *path, int fla fl = fcntl(fd, F_GETFL); if (fl < 0) { r = -errno; + weston_log("logind: cannot get file flags: %s\n", strerror(errno)); goto err_close; } @@ -204,6 +215,7 @@ launcher_logind_open(struct weston_launcher *launcher, const char *path, int fla r = fcntl(fd, F_SETFL, fl); if (r < 0) { r = -errno; + weston_log("logind: cannot set O_NONBLOCK: %s\n", strerror(errno)); goto err_close; } return fd; @@ -816,7 +828,8 @@ err_seat: err_wl: free(wl); err_out: - weston_log("logind: cannot setup systemd-logind helper (%d), using legacy fallback\n", r); + weston_log("logind: cannot setup systemd-logind helper error: (%s), using legacy fallback\n", + strerror(-r)); errno = -r; return -1; } @@ -847,6 +860,7 @@ launcher_logind_get_vt(struct weston_launcher *launcher) } const struct launcher_interface launcher_logind_iface = { + .name = "logind", .connect = launcher_logind_connect, .destroy = launcher_logind_destroy, .open = launcher_logind_open, diff --git a/libweston/launcher-util.c b/libweston/launcher-util.c index 5cbb0abb..2e472aed 100644 --- a/libweston/launcher-util.c +++ b/libweston/launcher-util.c @@ -54,6 +54,7 @@ weston_launcher_connect(struct weston_compositor *compositor, int tty, const struct launcher_interface *iface = *it; struct weston_launcher *launcher; + weston_log("Trying %s launcher...\n", iface->name); if (iface->connect(&launcher, compositor, tty, seat_id, sync_drm) == 0) return launcher; } diff --git a/libweston/launcher-weston-launch.c b/libweston/launcher-weston-launch.c index e3b4e1ac..c7db8da7 100644 --- a/libweston/launcher-weston-launch.c +++ b/libweston/launcher-weston-launch.c @@ -253,12 +253,17 @@ launcher_weston_environment_get_fd(const char *env) int fd, flags; e = getenv(env); - if (!e || !safe_strtoint(e, &fd)) + if (!e || !safe_strtoint(e, &fd)) { + weston_log("could not get launcher fd from env\n"); return -1; + } flags = fcntl(fd, F_GETFD); - if (flags == -1) + if (flags == -1) { + weston_log("could not get fd flags!, env: %s, error: %s\n", + env, strerror(errno)); return -1; + } fcntl(fd, F_SETFD, flags | FD_CLOEXEC); unsetenv(env); @@ -297,6 +302,7 @@ launcher_weston_launch_connect(struct weston_launcher **out, struct weston_compo launcher); if (launcher->source == NULL) { free(launcher); + weston_log("failed to get weston-launcher socket fd event source\n"); return -ENOMEM; } @@ -329,13 +335,16 @@ launcher_weston_launch_get_vt(struct weston_launcher *base) { struct launcher_weston_launch *launcher = wl_container_of(base, launcher, base); struct stat s; - if (fstat(launcher->tty, &s) < 0) + if (fstat(launcher->tty, &s) < 0) { + weston_log("could not fstat launcher tty: %s\n", strerror(errno)); return -1; + } return minor(s.st_rdev); } const struct launcher_interface launcher_weston_launch_iface = { + .name = "weston_launch", .connect = launcher_weston_launch_connect, .destroy = launcher_weston_launch_destroy, .open = launcher_weston_launch_open,