Systemcluster / wrappe

Packer for creating self-contained single-binary applications from executables and directories. Distribute your application without the need for an installer, with smaller file size and faster startup than many alternatives 📦

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Parent process ends before child has completed

Silic0nS0ldier opened this issue · comments

Bug description
Wrapper terminates before command completed, leaving it running in the background. Behaves similar a bash command is made to execute in the background by adding & at the end of a command.

Reproduction steps
Wrap a script which produces a non-zero exit code (time may be a factor while the wrapper finishes up, adding a delay should help is this is the case) and run it. Check the reported exit code.

Additional context
Observed on MacOS.

Looks to be a known behaviour. https://doc.rust-lang.org/stable/std/process/struct.Child.html#warning

On Linux there is exec which fully replaces the existing process, killing the caller in the process.

On Windows (if I've read the docs right, I almost certainly have not) there is no equivalent to exec, however child processes won't be closed until an explicit function is called (e.g. ExitProcess) or the past thread in a process terminates.

Best I can tell there isn't anything in Rust standard API which covers this in a cross platform manner. child.wait() would technically fix this, but it would also prevent stdin usage (it gets killed to eliminate a potential deadlock). There is also try_wait but contrary to its name its a non-blocking "are we done yet" check, a loop would be required. Shame wait can't be used with stdin left alone, it all comes down to literally one line.

commented

Closed by 2a6936a for general behavior and 533ca8b with forking on applicable platforms.