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 8 pull requests #83537

Closed
wants to merge 29 commits into from

Commits on Mar 15, 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 15, 2021
    Configuration menu
    Copy the full SHA
    5e788f2 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 15, 2021
    Configuration menu
    Copy the full SHA
    3426bf7 View commit details
    Browse the repository at this point in the history
  3. Add PidFd type and seal traits

    Improve docs
    voidc committed Mar 15, 2021
    Configuration menu
    Copy the full SHA
    704d6c5 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    766cc25 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    d850f6b View commit details
    Browse the repository at this point in the history

Commits on Mar 16, 2021

  1. Fix test header and imports

    voidc committed Mar 16, 2021
    Configuration menu
    Copy the full SHA
    5ac8a31 View commit details
    Browse the repository at this point in the history
  2. Split do_fork into two

    voidc committed Mar 16, 2021
    Configuration menu
    Copy the full SHA
    a266bd8 View commit details
    Browse the repository at this point in the history
  3. Make do_fork unsafe

    voidc committed Mar 16, 2021
    Configuration menu
    Copy the full SHA
    cfb2d72 View commit details
    Browse the repository at this point in the history

Commits on Mar 17, 2021

  1. cargo update -p parking_lot -p parking_lot_core

    Changelog: https://github.com/Amanieu/parking_lot/blob/master/CHANGELOG.md#parking_lot_core-083-2021-02-12
    The full log:
    ```
    Removing cloudabi v0.1.0
    Updating parking_lot v0.11.0 -> v0.11.1
    Updating parking_lot_core v0.8.0 -> v0.8.3
    ```
    JohnTitor committed Mar 17, 2021
    Configuration menu
    Copy the full SHA
    79348f4 View commit details
    Browse the repository at this point in the history
  2. cargo update -p bytecount

    Commit range: llogiq/bytecount@b0f5fba...8dcd437
    
    The full log:
    ```
    Updating bytecount v0.6.0 -> v0.6.2
    Adding libm v0.1.4
    Removing packed_simd v0.3.3
    Adding packed_simd_2 v0.3.4
    ```
    JohnTitor committed Mar 17, 2021
    Configuration menu
    Copy the full SHA
    2b0e27e View commit details
    Browse the repository at this point in the history

Commits on Mar 19, 2021

  1. Configuration menu
    Copy the full SHA
    4238a8f View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    58c1352 View commit details
    Browse the repository at this point in the history

Commits on Mar 20, 2021

  1. Use a single codegen unit to reduce non-determinism in srcloc.rs test

    When building with multiple codegen units the test case can fail with
    only a subset of all errors. Use a single codegen unit as a workaround.
    tmiasko committed Mar 20, 2021
    Configuration menu
    Copy the full SHA
    addf680 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    3d64f8d View commit details
    Browse the repository at this point in the history

Commits on Mar 21, 2021

  1. Simplify and fix byte skipping in format! string parser

    Fixes '\\' handling in format strings.
    
    Fixes rust-lang#83340
    osa1 committed Mar 21, 2021
    Configuration menu
    Copy the full SHA
    ae8ef70 View commit details
    Browse the repository at this point in the history
  2. format macro argument parsing fix

    When the character next to `{}` is "shifted" (when mapping a byte index
    in the format string to span) we should avoid shifting the span end
    index, so first map the index of `}` to span, then bump the span,
    instead of first mapping the next byte index to a span (which causes
    bumping the end span too much).
    
    Regression test added.
    
    Fixes rust-lang#83344
    osa1 committed Mar 21, 2021
    Configuration menu
    Copy the full SHA
    6c45ebe View commit details
    Browse the repository at this point in the history

Commits on Mar 22, 2021

  1. Configuration menu
    Copy the full SHA
    18748c9 View commit details
    Browse the repository at this point in the history
  2. Update library/alloc/src/fmt.rs

    alamb committed Mar 22, 2021
    Configuration menu
    Copy the full SHA
    93737dc View commit details
    Browse the repository at this point in the history

Commits on Mar 24, 2021

  1. Tell GitHub to highlight config.toml.example as TOML

    This should be a nice small quality of life improvement when looking at
    `config.toml.example` on GitHub or looking at diffs of it in PRs.
    camelid committed Mar 24, 2021
    Configuration menu
    Copy the full SHA
    b3ae90b View commit details
    Browse the repository at this point in the history
  2. rustdoc: Use diagnostics for error when including sources

    This error probably almost never happens, but we should still use the
    diagnostic infrastructure. My guess is that the error was added back
    before rustdoc used the rustc diagnostic infrastructure (it was all
    `println!` and `eprintln!` back then!) and since it likely rarely occurs
    and this code doesn't change that much, no one thought to transition it
    to using diagnostics.
    
    Note that the old error was actually a warning (it didn't stop the rest
    of doc building). It seems very unlikely that this would fail without
    the rest of the doc build failing, so it makes more sense for it to be a
    hard error.
    
    The error looks like this:
    
        error: failed to render source code for `src/test/rustdoc/smart-punct.rs`: "bar": foo
          --> src/test/rustdoc/smart-punct.rs:3:1
           |
        3  | / #![crate_name = "foo"]
        4  | |
        5  | | //! This is the "start" of the 'document'! How'd you know that "it's" ...
        6  | | //!
        ...  |
        22 | | //! I say "don't smart-punct me -- please!"
        23 | | //! ```
           | |_______^
    
    I wasn't sure how to trigger the error, so to create that message I
    temporarily made rustdoc always emit it. That's also why it says "bar"
    and "foo" instead of a real error message.
    
    Note that the span of the diagnostic starts at line 3 because line 1 of
    that file is a (non-doc) comment and line 2 is a blank line.
    camelid committed Mar 24, 2021
    Configuration menu
    Copy the full SHA
    3d8ce0a View commit details
    Browse the repository at this point in the history

Commits on Mar 25, 2021

  1. Remove broken test

    The test calls libc::getpid() in the pre_exec hook and asserts that the returned value is different from the PID of the parent.
    However, libc::getpid() returns the wrong value.
    Before version 2.25, glibc caches the PID of the current process with the goal of avoiding additional syscalls.
    The cached value is only updated when the wrapper functions for fork or clone are called.
    In PR rust-lang#81825 we switch to directly using the clone3 syscall.
    Thus, the cache is not updated and getpid returns the PID of the parent.
    source: https://man7.org/linux/man-pages/man2/getpid.2.html#NOTES
    voidc committed Mar 25, 2021
    Configuration menu
    Copy the full SHA
    8bc4de7 View commit details
    Browse the repository at this point in the history

Commits on Mar 26, 2021

  1. 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 committed Mar 26, 2021
    Configuration menu
    Copy the full SHA
    42542cc View commit details
    Browse the repository at this point in the history
  2. Rollup merge of rust-lang#82993 - camelid:source-use-diag, r=jyn514

    rustdoc: Use diagnostics for error when including sources
    
    This error probably almost never happens, but we should still use the
    diagnostic infrastructure. My guess is that the error was added back
    before rustdoc used the rustc diagnostic infrastructure (it was all
    `println!` and `eprintln!` back then!) and since it likely rarely occurs
    and this code doesn't change that much, no one thought to transition it
    to using diagnostics.
    
    Note that the old error was actually a warning (it didn't stop the rest
    of doc building). It seems very unlikely that this would fail without
    the rest of the doc build failing, so it makes more sense for it to be a
    hard error.
    
    The error looks like this:
    
        error: failed to render source code for `src/test/rustdoc/smart-punct.rs`: "bar": foo
          --> src/test/rustdoc/smart-punct.rs:3:1
           |
        3  | / #![crate_name = "foo"]
        4  | |
        5  | | //! This is the "start" of the 'document'! How'd you know that "it's" ...
        6  | | //!
        ...  |
        22 | | //! I say "don't smart-punct me -- please!"
        23 | | //! ```
           | |_______^
    
    I wasn't sure how to trigger the error, so to create that message I
    temporarily made rustdoc always emit it. That's also why it says "bar"
    and "foo" instead of a real error message.
    
    Note that the span of the diagnostic starts at line 3 because line 1 of
    that file is a (non-doc) comment and line 2 is a blank line.
    Dylan-DPC committed Mar 26, 2021
    Configuration menu
    Copy the full SHA
    bfd56fa View commit details
    Browse the repository at this point in the history
  3. Rollup merge of rust-lang#83239 - JohnTitor:reduce-deps, r=Mark-Simul…

    …acrum
    
    Remove/replace some outdated crates from the dependency tree
    
    - Remove `cloudabi` by updating `parking_lot` to 0.11.1.
    - Replace `packed_simd` with `packed_simd2` by updating `bytecount` to 0.6.2.
    Dylan-DPC committed Mar 26, 2021
    Configuration menu
    Copy the full SHA
    91c019e View commit details
    Browse the repository at this point in the history
  4. Rollup merge of rust-lang#83328 - tmiasko:asm-test, r=joshtriplett

    Fixes to inline assmebly tests
    
    * Join test thread to make assertion effective in sym.rs test case
    * Use a single codegen unit to reduce non-determinism in srcloc.rs test rust-lang#82886
    Dylan-DPC committed Mar 26, 2021
    Configuration menu
    Copy the full SHA
    65bda37 View commit details
    Browse the repository at this point in the history
  5. Rollup merge of rust-lang#83343 - osa1:issue83340, r=jackh726

    Simplify and fix byte skipping in format! string parser
    
    Fixes '\\' handling in format strings.
    
    Fixes rust-lang#83340
    Dylan-DPC committed Mar 26, 2021
    Configuration menu
    Copy the full SHA
    82fac65 View commit details
    Browse the repository at this point in the history
  6. Rollup merge of rust-lang#83348 - osa1:issue83344, r=jackh726

    format macro argument parsing fix
    
    When the character next to `{}` is "shifted" (when mapping a byte index
    in the format string to span) we should avoid shifting the span end
    index, so first map the index of `}` to span, then bump the span,
    instead of first mapping the next byte index to a span (which causes
    bumping the end span too much).
    
    Regression test added.
    
    Fixes rust-lang#83344
    
    ---
    
    r? `@estebank`
    Dylan-DPC committed Mar 26, 2021
    Configuration menu
    Copy the full SHA
    e7e9dd6 View commit details
    Browse the repository at this point in the history
  7. Rollup merge of rust-lang#83388 - alamb:alamb/fmt-dcs, r=Mark-Simulacrum

    Make # pretty print format easier to discover
    
    # Rationale:
    
    I use (cargo cult?) three formats in rust:  `{}`, debug `{:?}`, and pretty-print debug `{:#?}`. I discovered `{:#?}` in some blog post or guide when I started working in Rust. While `#` is documented I think it is hard to discover. So taking the good advice of `@carols10cents`  I am trying to improve the docs with a PR
    
    As a reminder "pretty print" means that where `{:?}` will print something like
    ```
    foo: { b1: 1, b2: 2}
    ```
    
    `{:#?}` will prints something like
    ```
    foo {
      b1: 1
      b2: 3
    }
    ```
    
    # Changes
    Add an example to `fmt` to try and make it easier to discover `#`
    Dylan-DPC committed Mar 26, 2021
    Configuration menu
    Copy the full SHA
    1f1bfb9 View commit details
    Browse the repository at this point in the history
  8. Rollup merge of rust-lang#83431 - camelid:config-example-gitattribute…

    …s, r=Mark-Simulacrum
    
    Tell GitHub to highlight `config.toml.example` as TOML
    
    This should be a nice small quality of life improvement when looking at
    `config.toml.example` on GitHub or looking at diffs of it in PRs.
    Dylan-DPC committed Mar 26, 2021
    Configuration menu
    Copy the full SHA
    296f148 View commit details
    Browse the repository at this point in the history