diff options
| author | Devin J. Pohly <djpohly@gmail.com> | 2020-04-11 22:44:34 -0500 | 
|---|---|---|
| committer | Devin J. Pohly <djpohly@gmail.com> | 2020-04-11 22:44:34 -0500 | 
| commit | c82c000bd413579237f5292d8076f045726efe15 (patch) | |
| tree | f65ece8dc184e8c3f216d87a01708e79254dbd44 | |
| parent | 251d15c1fdecf4c05734313f5bdb73469c68991c (diff) | |
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.
| -rw-r--r-- | dwl.c | 19 | 
1 files changed, 18 insertions, 1 deletions
| @@ -8,6 +8,8 @@  #include <stdio.h>  #include <time.h>  #include <unistd.h> +#include <sys/signal.h> +#include <sys/wait.h>  #include <linux/input-event-codes.h>  #include <wayland-server-core.h>  #include <wlr/backend.h> @@ -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); | 
