authorgravatar for cnx@loang.netNguyễn Gia Phong <cnx@loang.net> 2024-07-09 21:30:46+09:00
committergravatar for cnx@loang.netNguyễn Gia Phong <cnx@loang.net> 2024-07-22 11:50:00+09:00
log759ab41d725604c38fea9be658fe93f046f59293
tree636dd658b832d60a4c2c84eabb5d912e7f190d4c
parentd6fa71cd67b35f6fdb7a19a9728ff66247ab13c8
signaturelock-open Commit is signed but in an unrecognized format.

Allow setting PGID in std.process.Child.spawn


1 files changed, 9 insertions(+), 0 deletions(-)

lib/std/process/Child.zig+9
...@@ -63,6 +63,9 @@ uid: if (native_os == .windows or native_os == .wasi) void else ?posix.uid_t,...@@ -63,6 +63,9 @@ uid: if (native_os == .windows or native_os == .wasi) void else ?posix.uid_t,
63/// Set to change the group id when spawning the child process.63/// Set to change the group id when spawning the child process.
64gid: if (native_os == .windows or native_os == .wasi) void else ?posix.gid_t,64gid: if (native_os == .windows or native_os == .wasi) void else ?posix.gid_t,
6565
66/// Set to change the process group id when spawning the child process.
67pgid: if (native_os == .windows or native_os == .wasi) void else ?posix.pid_t,
68
66/// Set to change the current working directory when spawning the child process.69/// Set to change the current working directory when spawning the child process.
67cwd: ?[]const u8,70cwd: ?[]const u8,
68/// Set to change the current working directory when spawning the child process.71/// Set to change the current working directory when spawning the child process.
...@@ -168,6 +171,7 @@ pub const SpawnError = error{...@@ -168,6 +171,7 @@ pub const SpawnError = error{
168} ||171} ||
169 posix.ExecveError ||172 posix.ExecveError ||
170 posix.SetIdError ||173 posix.SetIdError ||
174 posix.SetPgidError ||
171 posix.ChangeCurDirError ||175 posix.ChangeCurDirError ||
172 windows.CreateProcessError ||176 windows.CreateProcessError ||
173 windows.GetProcessMemoryInfoError ||177 windows.GetProcessMemoryInfoError ||
...@@ -213,6 +217,7 @@ pub fn init(argv: []const []const u8, allocator: mem.Allocator) ChildProcess {...@@ -213,6 +217,7 @@ pub fn init(argv: []const []const u8, allocator: mem.Allocator) ChildProcess {
213 .cwd = null,217 .cwd = null,
214 .uid = if (native_os == .windows or native_os == .wasi) {} else null,218 .uid = if (native_os == .windows or native_os == .wasi) {} else null,
215 .gid = if (native_os == .windows or native_os == .wasi) {} else null,219 .gid = if (native_os == .windows or native_os == .wasi) {} else null,
220 .pgid = if (native_os == .windows or native_os == .wasi) {} else null,
216 .stdin = null,221 .stdin = null,
217 .stdout = null,222 .stdout = null,
218 .stderr = null,223 .stderr = null,
...@@ -675,6 +680,10 @@ fn spawnPosix(self: *ChildProcess) SpawnError!void {...@@ -675,6 +680,10 @@ fn spawnPosix(self: *ChildProcess) SpawnError!void {
675 posix.setreuid(uid, uid) catch |err| forkChildErrReport(err_pipe[1], err);680 posix.setreuid(uid, uid) catch |err| forkChildErrReport(err_pipe[1], err);
676 }681 }
677682
683 if (self.pgid) |pid| {
684 posix.setpgid(0, pid) catch |err| forkChildErrReport(err_pipe[1], err);
685 }
686
678 const err = switch (self.expand_arg0) {687 const err = switch (self.expand_arg0) {
679 .expand => posix.execvpeZ_expandArg0(.expand, argv_buf.ptr[0].?, argv_buf.ptr, envp),688 .expand => posix.execvpeZ_expandArg0(.expand, argv_buf.ptr[0].?, argv_buf.ptr, envp),
680 .no_expand => posix.execvpeZ_expandArg0(.no_expand, argv_buf.ptr[0].?, argv_buf.ptr, envp),689 .no_expand => posix.execvpeZ_expandArg0(.no_expand, argv_buf.ptr[0].?, argv_buf.ptr, envp),