Skip to content

fork example might be violating its own safety rules #2782

Open

Description

@FeldrinH

The example for fork (https://docs.rs/nix/latest/nix/unistd/fn.fork.html) contains this in the child arm of the match:

   Ok(ForkResult::Child) => {
       // Unsafe to use `println!` (or `unwrap`) here. See Safety.
       write(std::io::stdout(), "I'm a new child process\n".as_bytes()).ok();
       unsafe { libc::_exit(0) };
   }

To be safe, this block should use only async-signal-safe functions, however, I'm not sure if writing to std::io::stdout() is async-signal-safe. The write syscall itself is signal safe, but Rust muddies the waters, because std::io::stdout is wrapped in a reentrant lock, which may or may not cause issues.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions