fixed zombie/defunct rofis by double-forking
Browse files
+6 −0 src/wm/actions.zig
| @@ -31,6 +31,8 @@ pub fn spawnCommand(wm: *WindowManager, cmd: []const u8) void { | ||
| 31 | 31 | std.debug.print("running cmd: {s}\n", .{cmd}); |
| 32 | 32 | const pid = std.posix.fork() catch return; |
| 33 | 33 | if (pid == 0) { |
| 34 | + const grandchild = std.posix.fork() catch std.posix.exit(1); | |
| 35 | + if (grandchild != 0) std.posix.exit(0); | |
| 34 | 36 | spawnChildSetup(wm); |
| 35 | 37 | var cmd_buf: [1024]u8 = undefined; |
| 36 | 38 | if (cmd.len >= cmd_buf.len) { |
| @@ -42,11 +44,14 @@ pub fn spawnCommand(wm: *WindowManager, cmd: []const u8) void { | ||
| 42 | 44 | _ = std.posix.execvpeZ("sh", &argv, std.c.environ) catch {}; |
| 43 | 45 | std.posix.exit(1); |
| 44 | 46 | } |
| 47 | + _ = std.posix.waitpid(pid, 0); | |
| 45 | 48 | } |
| 46 | 49 | |
| 47 | 50 | pub fn spawnTerminal(wm: *WindowManager) void { |
| 48 | 51 | const pid = std.posix.fork() catch return; |
| 49 | 52 | if (pid == 0) { |
| 53 | + const grandchild = std.posix.fork() catch std.posix.exit(1); | |
| 54 | + if (grandchild != 0) std.posix.exit(0); | |
| 50 | 55 | spawnChildSetup(wm); |
| 51 | 56 | var term_buf: [256]u8 = undefined; |
| 52 | 57 | const terminal = wm.config.terminal; |
| @@ -60,6 +65,7 @@ pub fn spawnTerminal(wm: *WindowManager) void { | ||
| 60 | 65 | _ = std.posix.execvpeZ(term_ptr, &argv, std.c.environ) catch {}; |
| 61 | 66 | std.posix.exit(1); |
| 62 | 67 | } |
| 68 | + _ = std.posix.waitpid(pid, 0); | |
| 63 | 69 | } |
| 64 | 70 | |
| 65 | 71 | pub fn movestack(direction: i32, wm: *WindowManager) void { |