authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-02-27 11:14:14-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-02-27 11:14:14-05:00
log439621e44a68b436f958a84fcdb0bdac83613aea
tree3c320f1bc1b9bd63647297a55ba400f3871802de
parent1eecfdaa9b9c04e50058695b8df9978ef47f121a

remove signal hanlding stuff from std.os.ChildProcess


1 files changed, 0 insertions(+), 50 deletions(-)

std/os/child_process.zig-50
......@@ -32,9 +32,6 @@ pub const ChildProcess = struct {
3232
3333 pub argv: []const []const u8,
3434
35 /// Possibly called from a signal handler. Must set this before calling `spawn`.
36 pub onTerm: ?fn(&ChildProcess)void,
37
3835 /// Leave as null to use the current env map using the supplied allocator.
3936 pub env_map: ?&const BufMap,
4037
......@@ -102,7 +99,6 @@ pub const ChildProcess = struct {
10299 .err_pipe = undefined,
103100 .llnode = undefined,
104101 .term = null,
105 .onTerm = null,
106102 .env_map = null,
107103 .cwd = null,
108104 .uid = if (is_windows) {} else null,
......@@ -124,7 +120,6 @@ pub const ChildProcess = struct {
124120 self.gid = user_info.gid;
125121 }
126122
127 /// onTerm can be called before `spawn` returns.
128123 /// On success must call `kill` or `wait`.
129124 pub fn spawn(self: &ChildProcess) !void {
130125 if (is_windows) {
......@@ -165,9 +160,6 @@ pub const ChildProcess = struct {
165160 }
166161
167162 pub fn killPosix(self: &ChildProcess) !Term {
168 block_SIGCHLD();
169 defer restore_SIGCHLD();
170
171163 if (self.term) |term| {
172164 self.cleanupStreams();
173165 return term;
......@@ -246,9 +238,6 @@ pub const ChildProcess = struct {
246238 }
247239
248240 fn waitPosix(self: &ChildProcess) !Term {
249 block_SIGCHLD();
250 defer restore_SIGCHLD();
251
252241 if (self.term) |term| {
253242 self.cleanupStreams();
254243 return term;
......@@ -298,10 +287,6 @@ pub const ChildProcess = struct {
298287
299288 fn handleWaitResult(self: &ChildProcess, status: i32) void {
300289 self.term = self.cleanupAfterWait(status);
301
302 if (self.onTerm) |onTerm| {
303 onTerm(self);
304 }
305290 }
306291
307292 fn cleanupStreams(self: &ChildProcess) void {
......@@ -347,9 +332,6 @@ pub const ChildProcess = struct {
347332 }
348333
349334 fn spawnPosix(self: &ChildProcess) !void {
350 // TODO atomically set a flag saying that we already did this
351 install_SIGCHLD_handler();
352
353335 const stdin_pipe = if (self.stdin_behavior == StdIo.Pipe) try makePipe() else undefined;
354336 errdefer if (self.stdin_behavior == StdIo.Pipe) { destroyPipe(stdin_pipe); };
355337
......@@ -387,11 +369,9 @@ pub const ChildProcess = struct {
387369 const err_pipe = try makePipe();
388370 errdefer destroyPipe(err_pipe);
389371
390 block_SIGCHLD();
391372 const pid_result = posix.fork();
392373 const pid_err = posix.getErrno(pid_result);
393374 if (pid_err > 0) {
394 restore_SIGCHLD();
395375 return switch (pid_err) {
396376 posix.EAGAIN, posix.ENOMEM, posix.ENOSYS => error.SystemResources,
397377 else => os.unexpectedErrorPosix(pid_err),
......@@ -399,7 +379,6 @@ pub const ChildProcess = struct {
399379 }
400380 if (pid_result == 0) {
401381 // we are the child
402 restore_SIGCHLD();
403382
404383 setUpChildIo(self.stdin_behavior, stdin_pipe[0], posix.STDIN_FILENO, dev_null_fd) catch
405384 |err| forkChildErrReport(err_pipe[1], err);
......@@ -451,8 +430,6 @@ pub const ChildProcess = struct {
451430 // TODO make this atomic so it works even with threads
452431 children_nodes.prepend(&self.llnode);
453432
454 restore_SIGCHLD();
455
456433 if (self.stdin_behavior == StdIo.Pipe) { os.close(stdin_pipe[0]); }
457434 if (self.stdout_behavior == StdIo.Pipe) { os.close(stdout_pipe[1]); }
458435 if (self.stderr_behavior == StdIo.Pipe) { os.close(stderr_pipe[1]); }
......@@ -824,30 +801,3 @@ fn handleTerm(pid: i32, status: i32) void {
824801 }
825802 }
826803}
827
828const sigchld_set = x: {
829 var signal_set = posix.empty_sigset;
830 posix.sigaddset(&signal_set, posix.SIGCHLD);
831 break :x signal_set;
832};
833
834fn block_SIGCHLD() void {
835 const err = posix.getErrno(posix.sigprocmask(posix.SIG_BLOCK, &sigchld_set, null));
836 assert(err == 0);
837}
838
839fn restore_SIGCHLD() void {
840 const err = posix.getErrno(posix.sigprocmask(posix.SIG_UNBLOCK, &sigchld_set, null));
841 assert(err == 0);
842}
843
844const sigchld_action = posix.Sigaction {
845 .handler = sigchld_handler,
846 .mask = posix.empty_sigset,
847 .flags = posix.SA_RESTART | posix.SA_NOCLDSTOP,
848};
849
850fn install_SIGCHLD_handler() void {
851 const err = posix.getErrno(posix.sigaction(posix.SIGCHLD, &sigchld_action, null));
852 assert(err == 0);
853}