zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 2c22c3dabf08156eee00b927baf7d6a845a4c98d (tree)
parent 08d8b412e9217018d760666094b89918de02f10e
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Sat,  3 Jan 2026 18:07:02 -0800

std.Io.Threaded: make processReplace cancelable

In between each attempt to call execve() on a particular file path, it
will check cancelation before trying the next PATH.

Diffstat:
Mlib/std/Io/Threaded.zig | 8+++++---
1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/lib/std/Io/Threaded.zig b/lib/std/Io/Threaded.zig @@ -1428,7 +1428,7 @@ pub fn io(t: *Threaded) Io { .tryLockStderr = tryLockStderr, .unlockStderr = unlockStderr, .processSetCurrentDir = processSetCurrentDir, - .processReplace = processReplace, // TODO audit for cancelation and unreachable + .processReplace = processReplace, .processReplacePath = processReplacePath, // TODO audit for cancelation and unreachable .processSpawn = processSpawn, // TODO audit for cancelation and unreachable .processSpawnPath = processSpawnPath, // TODO audit for cancelation and unreachable @@ -12946,7 +12946,9 @@ fn spawnPosix(t: *Threaded, options: process.SpawnOptions) process.SpawnError!Sp const pid_result = try posix.fork(); if (pid_result == 0) { - // we are the child + // We are the child. + if (Thread.current) |current_thread| current_thread.cancel_protection = .blocked; + setUpChildIo(options.stdin, stdin_pipe[0], posix.STDIN_FILENO, dev_null_fd) catch |err| forkBail(err_pipe[1], err); setUpChildIo(options.stdout, stdout_pipe[1], posix.STDOUT_FILENO, dev_null_fd) catch |err| forkBail(err_pipe[1], err); setUpChildIo(options.stderr, stderr_pipe[1], posix.STDERR_FILENO, dev_null_fd) catch |err| forkBail(err_pipe[1], err); @@ -14585,8 +14587,8 @@ pub fn posixExecvPath( child_argv: [*:null]const ?[*:0]const u8, envp: [*:null]const ?[*:0]const u8, ) process.ReplaceError { + try Thread.checkCancel(); switch (posix.errno(posix.system.execve(path, child_argv, envp))) { - .SUCCESS => unreachable, .FAULT => |err| return errnoBug(err), // Bad pointer parameter. .@"2BIG" => return error.SystemResources, .MFILE => return error.ProcessFdQuotaExceeded,