From c82c000bd413579237f5292d8076f045726efe15 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Sat, 11 Apr 2020 22:44:34 -0500 Subject: treat startup command as long-running Not quite a perfect mirror of xinit, where the startup command execs the window manager, and the termination of that process brings down the windowing system, but it might be the Wayland analogue. --- dwl.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/dwl.c b/dwl.c index 0ad6781..627f968 100644 --- a/dwl.c +++ b/dwl.c @@ -8,6 +8,8 @@ #include #include #include +#include +#include #include #include #include @@ -865,6 +867,7 @@ static void server_new_xdg_surface(struct wl_listener *listener, void *data) { int main(int argc, char *argv[]) { wlr_log_init(WLR_DEBUG, NULL); char *startup_cmd = NULL; + pid_t startup_pid = -1; int c; while ((c = getopt(argc, argv, "s:h")) != -1) { @@ -1002,8 +1005,17 @@ int main(int argc, char *argv[]) { * startup command if requested. */ setenv("WAYLAND_DISPLAY", socket, true); if (startup_cmd) { - if (fork() == 0) { + startup_pid = fork(); + if (startup_pid < 0) { + perror("startup: fork"); + wl_display_destroy(server.wl_display); + return 1; + } + if (startup_pid == 0) { execl("/bin/sh", "/bin/sh", "-c", startup_cmd, (void *)NULL); + perror("startup: execl"); + wl_display_destroy(server.wl_display); + return 1; } } /* Run the Wayland event loop. This does not return until you exit the @@ -1014,6 +1026,11 @@ int main(int argc, char *argv[]) { socket); wl_display_run(server.wl_display); + if (startup_cmd) { + kill(startup_pid, SIGTERM); + waitpid(startup_pid, NULL, 0); + } + /* Once wl_display_run returns, we shut down the server. */ wl_display_destroy_clients(server.wl_display); wl_display_destroy(server.wl_display); -- cgit v1.2.3