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

Rollup of 7 pull requests #83119

Closed
wants to merge 20 commits into from

Commits on Mar 10, 2021

  1. Add Linux-specific pidfd process extensions

    Background:
    
    Over the last year, pidfd support was added to the Linux kernel. This
    allows interacting with other processes. In particular, this allows
    waiting on a child process with a timeout in a race-free way, bypassing
    all of the awful signal-handler tricks that are usually required.
    
    Pidfds can be obtained for a child process (as well as any other
    process) via the `pidfd_open` syscall. Unfortunately, this requires
    several conditions to hold in order to be race-free (i.e. the pid is not
    reused).
    Per `man pidfd_open`:
    
    ```
    · the disposition of SIGCHLD has not been explicitly set to SIG_IGN
     (see sigaction(2));
    
    · the SA_NOCLDWAIT flag was not specified while establishing a han‐
     dler for SIGCHLD or while setting the disposition of that signal to
     SIG_DFL (see sigaction(2)); and
    
    · the zombie process was not reaped elsewhere in the program (e.g.,
     either by an asynchronously executed signal handler or by wait(2)
     or similar in another thread).
    
    If any of these conditions does not hold, then the child process
    (along with a PID file descriptor that refers to it) should instead
    be created using clone(2) with the CLONE_PIDFD flag.
    ```
    
    Sadly, these conditions are impossible to guarantee once any libraries
    are used. For example, C code runnng in a different thread could call
    `wait()`, which is impossible to detect from Rust code trying to open a
    pidfd.
    
    While pid reuse issues should (hopefully) be rare in practice, we can do
    better. By passing the `CLONE_PIDFD` flag to `clone()` or `clone3()`, we
    can obtain a pidfd for the child process in a guaranteed race-free
    manner.
    
    This PR:
    
    This PR adds Linux-specific process extension methods to allow obtaining
    pidfds for processes spawned via the standard `Command` API. Other than
    being made available to user code, the standard library does not make
    use of these pidfds in any way. In particular, the implementation of
    `Child::wait` is completely unchanged.
    
    Two Linux-specific helper methods are added: `CommandExt::create_pidfd`
    and `ChildExt::pidfd`. These methods are intended to serve as a building
    block for libraries to build higher-level abstractions - in particular,
    waiting on a process with a timeout.
    
    I've included a basic test, which verifies that pidfds are created iff
    the `create_pidfd` method is used. This test is somewhat special - it
    should always succeed on systems with the `clone3` system call
    available, and always fail on systems without `clone3` available. I'm
    not sure how to best ensure this programatically.
    
    This PR relies on the newer `clone3` system call to pass the `CLONE_FD`,
    rather than the older `clone` system call. `clone3` was added to Linux
    in the same release as pidfds, so this shouldn't unnecessarily limit the
    kernel versions that this code supports.
    
    Unresolved questions:
    * What should the name of the feature gate be for these newly added
      methods?
    * Should the `pidfd` method distinguish between an error occurring
      and `create_pidfd` not being called?
    Aaron1011 authored and voidc committed Mar 10, 2021
    Configuration menu
    Copy the full SHA
    b03dba6 View commit details
    Browse the repository at this point in the history
  2. Typo fix

    Co-authored-by: bjorn3 <bjorn3@users.noreply.github.com>
    2 people authored and voidc committed Mar 10, 2021
    Configuration menu
    Copy the full SHA
    2e20fe3 View commit details
    Browse the repository at this point in the history
  3. Add PidFd type and seal traits

    Improve docs
    voidc committed Mar 10, 2021
    Configuration menu
    Copy the full SHA
    ed86f6e View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    f23b30c View commit details
    Browse the repository at this point in the history

Commits on Mar 11, 2021

  1. Inline Attribute::has_name

    tmiasko committed Mar 11, 2021
    Configuration menu
    Copy the full SHA
    1ba71ab View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    4943190 View commit details
    Browse the repository at this point in the history

Commits on Mar 12, 2021

  1. Configuration menu
    Copy the full SHA
    0466b6a View commit details
    Browse the repository at this point in the history

Commits on Mar 13, 2021

  1. Configuration menu
    Copy the full SHA
    c74fdf0 View commit details
    Browse the repository at this point in the history

Commits on Mar 14, 2021

  1. Configuration menu
    Copy the full SHA
    71a784d View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    5ec0540 View commit details
    Browse the repository at this point in the history
  3. Minor refactoring in try_index_step

    Merges `if-let` and `if x.is_some() { ... }` blocks
    osa1 committed Mar 14, 2021
    Configuration menu
    Copy the full SHA
    6ddd840 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    14038c7 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    a4cc3ca View commit details
    Browse the repository at this point in the history
  6. Rollup merge of rust-lang#81825 - voidc:pidfd, r=joshtriplett

    Add Linux-specific pidfd process extensions (take 2)
    
    Continuation of rust-lang#77168.
    I addressed the following concerns from the original PR:
    
    - make `CommandExt` and `ChildExt` sealed traits
    - wrap file descriptors in `PidFd` struct representing ownership over the fd
    - add `take_pidfd` to take the fd out of `Child`
    - close fd when dropped
    
    Tracking Issue: rust-lang#82971
    Dylan-DPC authored Mar 14, 2021
    Configuration menu
    Copy the full SHA
    ca4cdc2 View commit details
    Browse the repository at this point in the history
  7. Rollup merge of rust-lang#82399 - petrochenkov:modin2, r=Aaron1011

    expand: Resolve and expand inner attributes on out-of-line modules
    
    Fixes rust-lang#81661
    r? `@Aaron1011`
    Dylan-DPC authored Mar 14, 2021
    Configuration menu
    Copy the full SHA
    377542a View commit details
    Browse the repository at this point in the history
  8. Rollup merge of rust-lang#83054 - tmiasko:rustc_layout_scalar_valid_r…

    …ange, r=davidtwco
    
    Validate rustc_layout_scalar_valid_range_{start,end} attributes
    
    Fixes rust-lang#82251, rust-lang#82981.
    Dylan-DPC authored Mar 14, 2021
    Configuration menu
    Copy the full SHA
    68422d2 View commit details
    Browse the repository at this point in the history
  9. Rollup merge of rust-lang#83062 - JohnTitor:improve-reassign-err, r=d…

    …avidtwco
    
    Improve the wording for the `can't reassign` error
    
    Follow-up for rust-lang#71976 (comment).
    Fixes rust-lang#66736
    Dylan-DPC authored Mar 14, 2021
    Configuration menu
    Copy the full SHA
    5f27f0e View commit details
    Browse the repository at this point in the history
  10. Rollup merge of rust-lang#83092 - petrochenkov:qspan, r=estebank

    More precise spans for HIR paths
    
    `Ty::assoc_item` is lowered to `<Ty>::assoc_item` in HIR, but `Ty` got span from the whole path.
    This PR fixes that, and adjusts some diagnostic code that relied on `Ty` having the whole path span.
    
    This is a pre-requisite for rust-lang#82868 (we cannot report suggestions like `Tr::assoc` -> `<dyn Tr>::assoc` with the current imprecise spans).
    r? `@estebank`
    Dylan-DPC authored Mar 14, 2021
    Configuration menu
    Copy the full SHA
    f540402 View commit details
    Browse the repository at this point in the history
  11. Rollup merge of rust-lang#83110 - hyksm:fix-typo, r=jonas-schievink

    Fix typos in `library/core/src/ptr/mod.rs` and `library/std/src/sys_common/thread_local_dtor.rs`
    
    adress -> address
    Dylan-DPC authored Mar 14, 2021
    Configuration menu
    Copy the full SHA
    a084fbb View commit details
    Browse the repository at this point in the history
  12. Rollup merge of rust-lang#83113 - osa1:refactor_try_index_step, r=jon…

    …as-schievink
    
    Minor refactoring in try_index_step
    
    Merges `if-let` and `if x.is_some() { ... }` blocks
    Dylan-DPC authored Mar 14, 2021
    Configuration menu
    Copy the full SHA
    eb3e358 View commit details
    Browse the repository at this point in the history