From 7a46fccdba35b46d91226d10c1c9b90e43418c09 Mon Sep 17 00:00:00 2001 From: Peter Hofmann Date: Tue, 18 Jun 2024 19:09:32 +0200 Subject: Run startup_cmd in new session and kill the entire group When a user's startup_cmd is a little more complex, e.g. a shell script, and forks off several processes, then killing only the main child pid might leave unwanted processes behind on exit. Not all children will notice when their parent or the compositor has quit. To fix this, put startup_cmd into its own session and process group, and kill the entire group on exit. --- dwl.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dwl.c b/dwl.c index 5a31aee..79ccb34 100644 --- a/dwl.c +++ b/dwl.c @@ -674,7 +674,7 @@ cleanup(void) #endif wl_display_destroy_clients(dpy); if (child_pid > 0) { - kill(child_pid, SIGTERM); + kill(-child_pid, SIGTERM); waitpid(child_pid, NULL, 0); } wlr_xcursor_manager_destroy(cursor_mgr); @@ -2141,6 +2141,7 @@ run(char *startup_cmd) if ((child_pid = fork()) < 0) die("startup: fork:"); if (child_pid == 0) { + setsid(); dup2(piperw[0], STDIN_FILENO); close(piperw[0]); close(piperw[1]); -- cgit v1.2.3