Skip to content

Commit b9d526d

Browse files
committed
std.os.linux.setsid(): return raw syscall0 result
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.
1 parent 6b8cef8 commit b9d526d

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

lib/std/os/linux.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1834,8 +1834,8 @@ pub fn setgroups(size: usize, list: [*]const gid_t) usize {
18341834
}
18351835
}
18361836

1837-
pub fn setsid() pid_t {
1838-
return @bitCast(@as(u32, @truncate(syscall0(.setsid))));
1837+
pub fn setsid() usize {
1838+
return syscall0(.setsid);
18391839
}
18401840

18411841
pub fn getpid() pid_t {

lib/std/posix.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7000,7 +7000,7 @@ pub const SetSidError = error{
70007000
pub fn setsid() SetSidError!pid_t {
70017001
const rc = system.setsid();
70027002
switch (errno(rc)) {
7003-
.SUCCESS => return rc,
7003+
.SUCCESS => return @intCast(rc),
70047004
.PERM => return error.PermissionDenied,
70057005
else => |err| return unexpectedErrno(err),
70067006
}

0 commit comments

Comments
 (0)