Skip to content

Commit e8a4e47

Browse files
blblackalexrp
authored andcommitted
Add setsid to std.(c|posix)
The interface and errors for this seem to be very universal and generic. Note Linux already has this defined as a syscall as well.
1 parent c6a18e9 commit e8a4e47

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

lib/std/c.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10808,6 +10808,7 @@ pub extern "c" fn if_nametoindex([*:0]const u8) c_int;
1080810808

1080910809
pub extern "c" fn getpid() pid_t;
1081010810
pub extern "c" fn getppid() pid_t;
10811+
pub extern "c" fn setsid() pid_t;
1081110812

1081210813
/// These are implementation defined but share identical values in at least musl and glibc:
1081310814
/// - https://git.musl-libc.org/cgit/musl/tree/include/locale.h?id=ab31e9d6a0fa7c5c408856c89df2dfb12c344039#n18

lib/std/posix.zig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7089,6 +7089,20 @@ pub fn tcsetpgrp(handle: fd_t, pgrp: pid_t) TermioSetPgrpError!void {
70897089
}
70907090
}
70917091

7092+
pub const SetSidError = error{
7093+
/// The calling process is already a process group leader, or the process group ID of a process other than the calling process matches the process ID of the calling process.
7094+
PermissionDenied,
7095+
} || UnexpectedError;
7096+
7097+
pub fn setsid() SetSidError!pid_t {
7098+
const rc = system.setsid();
7099+
switch (errno(rc)) {
7100+
.SUCCESS => return rc,
7101+
.PERM => return error.PermissionDenied,
7102+
else => |err| return unexpectedErrno(err),
7103+
}
7104+
}
7105+
70927106
pub fn signalfd(fd: fd_t, mask: *const sigset_t, flags: u32) !fd_t {
70937107
const rc = system.signalfd(fd, mask, flags);
70947108
switch (errno(rc)) {

0 commit comments

Comments
 (0)