| author | |
| committer | |
| log | 04071d64bb83c0600d445a2f4b2541e68a6021bf |
| tree | 8b89e2ad35aeadce808932ee934923945cd632d7 |
| parent | a0ec4e270e680960290642468f6df3ce7e7d7664 |
When not linking libc on 64-bit Linux and calling posix.setsid(),
we get a type error at compile time inside of posix.errno(). This
is because posix.errno()'s non-libc branch expects a usize-sized
value, which is what all the error-returning os.linux syscalls
return, and linux.setsid() instead returned a pid_t, which is only
32 bits wide.
This and the other 3 pid-related calls just below it (getpid(),
getppid(), and gettid()) are the only Linux syscall examples here
that are casting their return values to pid_t. For the other 3
this makes sense: those calls are documented to have no possible
errors and always return a valid pid_t value.
However, setsid() actually can return the error EPERM, and
therefore needs to return the raw value from syscall0 for
posix.errno() to process like normal.
Additionally, posix.setsid() needs an @intCast(rc) for the success
case as a result, like most other such cases.2 files changed, 3 insertions(+), 3 deletions(-)
lib/std/os/linux.zig+2-2| ... | @@ -1834,8 +1834,8 @@ pub fn setgroups(size: usize, list: [*]const gid_t) usize { | ... | @@ -1834,8 +1834,8 @@ pub fn setgroups(size: usize, list: [*]const gid_t) usize { |
| 1834 | } | 1834 | } |
| 1835 | } | 1835 | } |
| 1836 | 1836 | ||
| 1837 | pub fn setsid() pid_t { | 1837 | pub fn setsid() usize { |
| 1838 | return @bitCast(@as(u32, @truncate(syscall0(.setsid)))); | 1838 | return syscall0(.setsid); |
| 1839 | } | 1839 | } |
| 1840 | 1840 | ||
| 1841 | pub fn getpid() pid_t { | 1841 | pub fn getpid() pid_t { |
lib/std/posix.zig+1-1| ... | @@ -7000,7 +7000,7 @@ pub const SetSidError = error{ | ... | @@ -7000,7 +7000,7 @@ pub const SetSidError = error{ |
| 7000 | pub fn setsid() SetSidError!pid_t { | 7000 | pub fn setsid() SetSidError!pid_t { |
| 7001 | const rc = system.setsid(); | 7001 | const rc = system.setsid(); |
| 7002 | switch (errno(rc)) { | 7002 | switch (errno(rc)) { |
| 7003 | .SUCCESS => return rc, | 7003 | .SUCCESS => return @intCast(rc), |
| 7004 | .PERM => return error.PermissionDenied, | 7004 | .PERM => return error.PermissionDenied, |
| 7005 | else => |err| return unexpectedErrno(err), | 7005 | else => |err| return unexpectedErrno(err), |
| 7006 | } | 7006 | } |