Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement CommandExt::{exec, before_exec} #31409

Merged
merged 9 commits into from
Feb 11, 2016

Commits on Feb 10, 2016

  1. std: Refactor process spawning on Unix

    * Build up the argp/envp pointers while the `Command` is being constructed
      rather than only when `spawn` is called. This will allow better sharing of
      code between fork/exec paths.
    * Rename `child_after_fork` to `exec` and have it only perform the exec half of
      the spawning. This also means the return type has changed to `io::Error`
      rather than `!` to represent errors that happen.
    alexcrichton committed Feb 10, 2016
    Configuration menu
    Copy the full SHA
    6c41984 View commit details
    Browse the repository at this point in the history
  2. std: Implement CommandExt::before_exec

    This is a Unix-specific function which adds the ability to register a closure to
    run pre-exec to configure the child process as required (note that these
    closures are run post-fork).
    
    cc rust-lang#31398
    alexcrichton committed Feb 10, 2016
    Configuration menu
    Copy the full SHA
    b1898db View commit details
    Browse the repository at this point in the history
  3. std: Push Child's exit status to sys::process

    On Unix we have to be careful to not call `waitpid` twice, but we don't have to
    be careful on Windows due to the way process handles work there. As a result the
    cached `Option<ExitStatus>` is only necessary on Unix, and it's also just an
    implementation detail of the Unix module.
    
    At the same time. also update some code in `kill` on Unix to avoid a wonky
    waitpid with WNOHANG. This was added in 0e190b9 to solve rust-lang#13124, but the
    `signal(0)` method is not supported any more so there's no need to for this
    workaround. I believe that this is no longer necessary as it's not really doing
    anything.
    alexcrichton committed Feb 10, 2016
    Configuration menu
    Copy the full SHA
    627515a View commit details
    Browse the repository at this point in the history
  4. std: Rename Stdio::None to Stdio::Null

    This better reflects what it's actually doing as we don't actually have an
    option for "leave this I/O slot as an empty hole".
    alexcrichton committed Feb 10, 2016
    Configuration menu
    Copy the full SHA
    b8bd8f3 View commit details
    Browse the repository at this point in the history
  5. std: Lift out Windows' CreateProcess lock a bit

    The function `CreateProcess` is not itself unsafe to call from many threads, the
    article in question is pointing out that handles can be inherited by unintended
    child processes. This is basically the same race as the standard Unix
    open-then-set-cloexec race.
    
    Since the intention of the lock is to protect children from inheriting
    unintended handles, the lock is now lifted out to before the creation of the
    child I/O handles (which will all be inheritable). This will ensure that we only
    have one process in Rust at least creating inheritable handles at a time,
    preventing unintended inheritance to children.
    alexcrichton committed Feb 10, 2016
    Configuration menu
    Copy the full SHA
    18f9a79 View commit details
    Browse the repository at this point in the history
  6. std: Push process stdio setup in std::sys

    Most of this is platform-specific anyway, and we generally have to jump through
    fewer hoops to do the equivalent operation on Windows. One benefit for Windows
    today is that this new structure avoids an extra `DuplicateHandle` when creating
    pipes. For Unix, however, the behavior should be the same.
    
    Note that this is just a pure refactoring, no functionality was added or
    removed.
    alexcrichton committed Feb 10, 2016
    Configuration menu
    Copy the full SHA
    d15db1d View commit details
    Browse the repository at this point in the history
  7. std: Implement CommandExt::exec

    This commit implements the `exec` function proposed in [RFC 1359][rfc] which is
    a function on the `CommandExt` trait to execute all parts of a `Command::spawn`
    without the `fork` on Unix. More details on the function itself can be found in
    the comments in the commit.
    
    [rfc]: rust-lang/rfcs#1359
    
    cc rust-lang#31398
    alexcrichton committed Feb 10, 2016
    Configuration menu
    Copy the full SHA
    b37477c View commit details
    Browse the repository at this point in the history
  8. std: Use macros from libc instead of locally

    Helps cut down on #[cfg]!
    alexcrichton committed Feb 10, 2016
    Configuration menu
    Copy the full SHA
    efb23db View commit details
    Browse the repository at this point in the history
  9. std: Move constant back to where it needs to be

    Lost track of this during the std::process refactorings
    alexcrichton committed Feb 10, 2016
    Configuration menu
    Copy the full SHA
    d9c6a51 View commit details
    Browse the repository at this point in the history