authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-09-08 00:04:43-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-09-08 00:04:43-04:00
loga81e5161746b89e490bbf167489fd43a9d1821c2
tree55404a0ba24d6dcbc3b96f80e7a6b3861f203d53
parent9fb4d1fd6c521e1bc3b656315b9c693a9e8aa715

fix ChildProcess.spawn on darwin


4 files changed, 103 insertions(+), 35 deletions(-)

std/c/darwin.zig+9
......@@ -32,3 +32,12 @@ pub const timespec = extern struct {
3232 tv_sec: isize,
3333 tv_nsec: isize,
3434};
35
36pub const sigset_t = u32;
37
38/// Renamed from `sigaction` to `Sigaction` to avoid conflict with function name.
39pub const Sigaction = extern struct {
40 handler: extern fn(c_int),
41 sa_mask: sigset_t,
42 sa_flags: c_int,
43};
std/c/index.zig+2
......@@ -38,3 +38,5 @@ pub extern "c" fn dup(fd: c_int) -> c_int;
3838pub extern "c" fn dup2(old_fd: c_int, new_fd: c_int) -> c_int;
3939pub extern "c" fn readlink(noalias path: &const u8, noalias buf: &u8, bufsize: usize) -> isize;
4040pub extern "c" fn realpath(noalias file_name: &const u8, noalias resolved_name: &u8) -> ?&u8;
41pub extern "c" fn sigprocmask(how: c_int, noalias set: &const sigset_t, noalias oset: ?&sigset_t) -> c_int;
42pub extern "c" fn sigaction(sig: c_int, noalias act: &const Sigaction, noalias oact: ?&Sigaction) -> c_int;
std/os/darwin.zig+91-34
......@@ -24,6 +24,19 @@ pub const MAP_NOCACHE = 0x0400; /// don't cache pages for this mapping
2424pub const MAP_NORESERVE = 0x0040; /// don't reserve needed swap area
2525pub const MAP_FAILED = @maxValue(usize);
2626
27pub const WNOHANG = 0x00000001; /// [XSI] no hang in wait/no child to reap
28pub const WUNTRACED = 0x00000002; /// [XSI] notify on stop, untraced child
29
30pub const SA_ONSTACK = 0x0001; /// take signal on signal stack
31pub const SA_RESTART = 0x0002; /// restart system on signal return
32pub const SA_RESETHAND = 0x0004; /// reset to SIG_DFL when taking signal
33pub const SA_NOCLDSTOP = 0x0008; /// do not generate SIGCHLD on child stop
34pub const SA_NODEFER = 0x0010; /// don't mask the signal we're delivering
35pub const SA_NOCLDWAIT = 0x0020; /// don't keep zombies around
36pub const SA_SIGINFO = 0x0040; /// signal handler with SA_SIGINFO args
37pub const SA_USERTRAMP = 0x0100; /// do not bounce off kernel's sigtramp
38pub const SA_64REGSET = 0x0200; /// signal handler with SA_SIGINFO args with 64bit regs information
39
2740pub const O_LARGEFILE = 0x0000;
2841pub const O_PATH = 0x0000;
2942
......@@ -46,40 +59,43 @@ pub const SEEK_SET = 0x0;
4659pub const SEEK_CUR = 0x1;
4760pub const SEEK_END = 0x2;
4861
49pub const SIGHUP = 1;
50pub const SIGINT = 2;
51pub const SIGQUIT = 3;
52pub const SIGILL = 4;
53pub const SIGTRAP = 5;
54pub const SIGABRT = 6;
55pub const SIGIOT = SIGABRT;
56pub const SIGBUS = 7;
57pub const SIGFPE = 8;
58pub const SIGKILL = 9;
59pub const SIGUSR1 = 10;
60pub const SIGSEGV = 11;
61pub const SIGUSR2 = 12;
62pub const SIGPIPE = 13;
63pub const SIGALRM = 14;
64pub const SIGTERM = 15;
65pub const SIGSTKFLT = 16;
66pub const SIGCHLD = 17;
67pub const SIGCONT = 18;
68pub const SIGSTOP = 19;
69pub const SIGTSTP = 20;
70pub const SIGTTIN = 21;
71pub const SIGTTOU = 22;
72pub const SIGURG = 23;
73pub const SIGXCPU = 24;
74pub const SIGXFSZ = 25;
75pub const SIGVTALRM = 26;
76pub const SIGPROF = 27;
77pub const SIGWINCH = 28;
78pub const SIGIO = 29;
79pub const SIGPOLL = 29;
80pub const SIGPWR = 30;
81pub const SIGSYS = 31;
82pub const SIGUNUSED = SIGSYS;
62pub const SIG_BLOCK = 1; /// block specified signal set
63pub const SIG_UNBLOCK = 2; /// unblock specified signal set
64pub const SIG_SETMASK = 3; /// set specified signal set
65
66pub const SIGHUP = 1; /// hangup
67pub const SIGINT = 2; /// interrupt
68pub const SIGQUIT = 3; /// quit
69pub const SIGILL = 4; /// illegal instruction (not reset when caught)
70pub const SIGTRAP = 5; /// trace trap (not reset when caught)
71pub const SIGABRT = 6; /// abort()
72pub const SIGPOLL = 7; /// pollable event ([XSR] generated, not supported)
73pub const SIGIOT = SIGABRT; /// compatibility
74pub const SIGEMT = 7; /// EMT instruction
75pub const SIGFPE = 8; /// floating point exception
76pub const SIGKILL = 9; /// kill (cannot be caught or ignored)
77pub const SIGBUS = 10; /// bus error
78pub const SIGSEGV = 11; /// segmentation violation
79pub const SIGSYS = 12; /// bad argument to system call
80pub const SIGPIPE = 13; /// write on a pipe with no one to read it
81pub const SIGALRM = 14; /// alarm clock
82pub const SIGTERM = 15; /// software termination signal from kill
83pub const SIGURG = 16; /// urgent condition on IO channel
84pub const SIGSTOP = 17; /// sendable stop signal not from tty
85pub const SIGTSTP = 18; /// stop signal from tty
86pub const SIGCONT = 19; /// continue a stopped process
87pub const SIGCHLD = 20; /// to parent on child stop or exit
88pub const SIGTTIN = 21; /// to readers pgrp upon background tty read
89pub const SIGTTOU = 22; /// like TTIN for output if (tp->t_local&LTOSTOP)
90pub const SIGIO = 23; /// input/output possible signal
91pub const SIGXCPU = 24; /// exceeded CPU time limit
92pub const SIGXFSZ = 25; /// exceeded file size limit
93pub const SIGVTALRM = 26; /// virtual time alarm
94pub const SIGPROF = 27; /// profiling time alarm
95pub const SIGWINCH = 28; /// window size changes
96pub const SIGINFO = 29; /// information request
97pub const SIGUSR1 = 30; /// user defined signal 1
98pub const SIGUSR2 = 31; /// user defined signal 2
8399
84100fn wstatus(x: i32) -> i32 { x & 0o177 }
85101const wstopped = 0o177;
......@@ -209,6 +225,47 @@ pub fn realpath(noalias filename: &const u8, noalias resolved_name: &u8) -> usiz
209225 if (c.realpath(filename, resolved_name) == null) @bitCast(usize, -isize(*c._errno())) else 0
210226}
211227
228pub fn sigprocmask(flags: u32, noalias set: &const sigset_t, noalias oldset: ?&sigset_t) -> usize {
229 errnoWrap(c.sigprocmask(@bitCast(c_int, flags), set, oldset))
230}
231
232pub fn sigaction(sig: u5, noalias act: &const Sigaction, noalias oact: ?&Sigaction) -> usize {
233 assert(sig != SIGKILL);
234 assert(sig != SIGSTOP);
235 var cact = c.Sigaction {
236 .handler = @ptrCast(extern fn(c_int), act.handler),
237 .sa_flags = @bitCast(c_int, act.flags),
238 .sa_mask = act.mask,
239 };
240 var coact: c.Sigaction = undefined;
241 const result = errnoWrap(c.sigaction(sig, &cact, &coact));
242 if (result != 0) {
243 return result;
244 }
245 if (oact) |old| {
246 *old = Sigaction {
247 .handler = @ptrCast(extern fn(i32), coact.handler),
248 .flags = @bitCast(u32, coact.sa_flags),
249 .mask = coact.sa_mask,
250 };
251 }
252 return result;
253}
254
255pub const sigset_t = c.sigset_t;
256pub const empty_sigset = sigset_t(0);
257
258/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
259pub const Sigaction = struct {
260 handler: extern fn(i32),
261 mask: sigset_t,
262 flags: u32,
263};
264
265pub fn sigaddset(set: &sigset_t, signo: u5) {
266 *set |= u32(1) << (signo - 1);
267}
268
212269/// Takes the return value from a syscall and formats it back in the way
213270/// that the kernel represents it to libc. Errno was a mistake, let's make
214271/// it go away forever.
std/os/linux.zig+1-1
......@@ -480,7 +480,7 @@ pub fn nanosleep(req: &const timespec, rem: ?&timespec) -> usize {
480480 arch.syscall2(arch.SYS_nanosleep, @ptrToInt(req), @ptrToInt(rem))
481481}
482482
483pub fn sigprocmask(flags: u32, set: &const sigset_t, oldset: ?&sigset_t) -> usize {
483pub fn sigprocmask(flags: u32, noalias set: &const sigset_t, noalias oldset: ?&sigset_t) -> usize {
484484 arch.syscall4(arch.SYS_rt_sigprocmask, flags, @ptrToInt(set), @ptrToInt(oldset), NSIG/8)
485485}
486486