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