git.lucas.co / cce-compositor
Wayland compositor (wlroots)
git clone https://git.lucas.co/cce-compositor.git

commitf443206ca12309f9689e3e78e592cd2d3c0fe402
parent151d095ccb
authorIsaac Freund <[email protected]>
date2020-07-05 15:44
server: send SIGTERM to startup process on exit

 doc/river.1.scd | 9 ++++++---
 river/main.zig  | 9 ++++++---
 2 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/doc/river.1.scd b/doc/river.1.scd
index e79e6cb..2219c30 100644
--- a/doc/river.1.scd
+++ b/doc/river.1.scd
@@ -16,9 +16,12 @@ bspwm based on wlroots and written in Zig.
 
 *-c* _shell_command_
 	Run a shell command or give the path to a script that will be run
-	before river gets started. This is where you define keymaps using
-	*riverctl*(1) and autostart programs. Make sure the script is
-	executable.
+	after river's wayland server is initialized but before entering the
+	main loop. You may use this to configure river and define keymaps
+	using *riverctl*(1), start programs such as a status bar, or perhaps
+	run a service manager. If the process started by this flag is still
+	running when river exits, river will send SIGTERM and and wait for it
+	to terminate.
 
 *-l* _log_level_
 	Set the log level of river to a value from 0 to 7 with 0 being the
diff --git a/river/main.zig b/river/main.zig
index d7875da..e01b95a 100644
--- a/river/main.zig
+++ b/river/main.zig
@@ -85,12 +85,15 @@ pub fn main() anyerror!void {
 
     try server.start();
 
-    if (startup_command) |cmd| {
+    const startup_process = if (startup_command) |cmd| blk: {
         const child_args = [_][]const u8{ "/bin/sh", "-c", cmd };
         const child = try std.ChildProcess.init(&child_args, util.gpa);
-        defer child.deinit();
         try std.ChildProcess.spawn(child);
-    }
+        break :blk child;
+    } else null;
+    defer if (startup_process) |child| {
+        _ = child.kill() catch |e| log.err(.server, "failed to terminate startup process: {}", .{e});
+    };
 
     log.info(.server, "running...", .{});