Repository navigation
rename std.ChildProcess.exec to avoid ambiguity with posix exec which replaces current image with new process #5853
Copy link
Copy link
Closed
Labels
acceptedThis proposal is planned.This proposal is planned.breakingImplementing this issue could cause existing code to no longer compile or have different behavior.Implementing this issue could cause existing code to no longer compile or have different behavior.proposalThis issue suggests language modifications. If it also has the "accepted" label then it is planned.This issue suggests language modifications. If it also has the "accepted" label then it is planned.standard libraryThis issue involves writing Zig code for the standard library.This issue involves writing Zig code for the standard library.
Milestone
Description
The std.ChildProcess.exec function doesn't follow the expected behaviour of replacing the executable with the new program being exec'ed. See the SO question "Differences between fork and exec" for details on how fork and exec should behave.
Currently, std.ChildProcess.exec creates a std.ChildProcess instance and then calls its spawn method - returning an ExecResult struct:
Lines 186 to 206 in f23987d
| pub fn exec(args: struct { | |
| allocator: *mem.Allocator, | |
| argv: []const []const u8, | |
| cwd: ?[]const u8 = null, | |
| cwd_dir: ?fs.Dir = null, | |
| env_map: ?*const BufMap = null, | |
| max_output_bytes: usize = 50 * 1024, | |
| expand_arg0: Arg0Expand = .no_expand, | |
| }) !ExecResult { | |
| const child = try ChildProcess.init(args.argv, args.allocator); | |
| defer child.deinit(); | |
| child.stdin_behavior = .Ignore; | |
| child.stdout_behavior = .Pipe; | |
| child.stderr_behavior = .Pipe; | |
| child.cwd = args.cwd; | |
| child.cwd_dir = args.cwd_dir; | |
| child.env_map = args.env_map; | |
| child.expand_arg0 = args.expand_arg0; | |
| try child.spawn(); |
I expect that std.ChildProcess.exec should not fork or spawn, and it should have a !noreturn result (perhaps ExecError!noreturn with ExecError being much the same as a SpawnError).
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
acceptedThis proposal is planned.This proposal is planned.breakingImplementing this issue could cause existing code to no longer compile or have different behavior.Implementing this issue could cause existing code to no longer compile or have different behavior.proposalThis issue suggests language modifications. If it also has the "accepted" label then it is planned.This issue suggests language modifications. If it also has the "accepted" label then it is planned.standard libraryThis issue involves writing Zig code for the standard library.This issue involves writing Zig code for the standard library.
Activity
tgschultz commentedon Jul 14, 2020
However, coming from a Windows environment, this is not the behavior I expect. Should std.ChildProcess.exec be expected to follow POSIX definitions?
Perhaps instead of making it noreturn, it can simply be renamed to
ChildProcess.spawnorChildProcess.createto avoid confusion.daurnimator commentedon Aug 16, 2020
Yeah it might be best if we avoid
execat all.Give that the module is
ChildProcess, I don't think any "replaceCurrentProcess" doesn't make sense and belongs elsewhere (process.zig?).[-]`std.ChildProcess.exec` calls `spawn` (fork/exec) instead of `exec`[/-][+]rename `std.ChildProcess.exec` to avoid ambiguity with posix exec which replaces current image with new process[/+]nektro commentedon Dec 30, 2021
any thoughts on
run? doing some reworking in the above PRtysonclugg commentedon Aug 1, 2022
Why not follow POSIX conventions?
Even in Windows, some form of POSIX has been available for the last 29 years (since Windows NT 3.1).
I didn't ask for exec to be renamed.
tysonclugg commentedon Aug 1, 2022
Regarding the POSIX question, I see a number of possible outcomes:
std.ChildProcess.execthat don't follow established conventions, and people coming from C/C++ backgrounds (ie: the primary target audience) keep getting tripped up because of the differences.To be clear, I'm absolutely fine with 1 and 2. I'm very much against 3, and obviously can't have an opinion on 4 until a proposal is made.
tysonclugg commentedon Aug 1, 2022
If
std.ChildProcessis considered a "helper" library of abstract methods (option 4) and not a clean mapping of syscalls (option 1), then renamingexecto something else to avoid the issues of option 3 makes more sense. Perhapsrunmight be a good name in that case, but it should be very clear from both the method names, the documentation, and the website (where any C/C++ comparisons are made) that these abstract methods are not 1-1 replacements of the C/C++ equivalents.matu3ba commentedon Jan 3, 2023
True,
runis also used byPythonand its nice and short. Rust usesCommand::new, which I find not nice.I'll create a PR.
child_process + Build: rename exec to run + all related code
zig 0.12: ChildProcess exec is renamed in run