aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrandon Black <bblack@wikimedia.org>2025-09-12 07:19:01 -0500
committerBrandon Black <bblack@wikimedia.org>2025-09-12 07:19:01 -0500
commit04071d64bb83c0600d445a2f4b2541e68a6021bf (patch)
tree8b89e2ad35aeadce808932ee934923945cd632d7
parenta0ec4e270e680960290642468f6df3ce7e7d7664 (diff)
downloadzig-04071d64bb83c0600d445a2f4b2541e68a6021bf.tar.gz
zig-04071d64bb83c0600d445a2f4b2541e68a6021bf.zip
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.
-rw-r--r--lib/std/os/linux.zig4
-rw-r--r--lib/std/posix.zig2
2 files changed, 3 insertions, 3 deletions
diff --git a/lib/std/os/linux.zig b/lib/std/os/linux.zig
index d7d29e0df1..3319f08fc7 100644
--- a/lib/std/os/linux.zig
+++ b/lib/std/os/linux.zig
@@ -1834,8 +1834,8 @@ pub fn setgroups(size: usize, list: [*]const gid_t) usize {
}
}
-pub fn setsid() pid_t {
- return @bitCast(@as(u32, @truncate(syscall0(.setsid))));
+pub fn setsid() usize {
+ return syscall0(.setsid);
}
pub fn getpid() pid_t {
diff --git a/lib/std/posix.zig b/lib/std/posix.zig
index e0fd68db24..77a61b4bf4 100644
--- a/lib/std/posix.zig
+++ b/lib/std/posix.zig
@@ -7000,7 +7000,7 @@ pub const SetSidError = error{
pub fn setsid() SetSidError!pid_t {
const rc = system.setsid();
switch (errno(rc)) {
- .SUCCESS => return rc,
+ .SUCCESS => return @intCast(rc),
.PERM => return error.PermissionDenied,
else => |err| return unexpectedErrno(err),
}