about summary refs log tree commit diff
path: root/library/std/src/sys/unix/process
AgeCommit message (Collapse)AuthorLines
2023-01-11Change `src/test` to `tests` in source files, fix tidy and testsAlbert Larsan-1/+1
2022-12-27More verbose `Debug` implementation of `std::process:Command`kraktus-7/+60
based on commit: https://github.com/zackmdavis/rust/commit/ccc019aabfdd550944c049625e66c92c815ea1d0 from https://github.com/zackmdavis close https://github.com/rust-lang/rust/issues/42200 Add env variables and cwd to the shell-like debug output. Also use the alternate syntax to display a more verbose display, while not showing internal fields and hiding fields when they have their default value.
2022-12-17Rollup merge of #105458 - Ayush1325:blocking_spawn, r=Mark-SimulacrumMatthias Krüger-0/+19
Allow blocking `Command::output` ### Problem Currently, `Command::output` is internally implemented using `Command::spawn`. This is problematic because some targets (like UEFI) do not actually support multitasking and thus block while the program is executing. This coupling does not make much sense as `Command::output` is supposed to block until the execution is complete anyway and thus does not need to rely on a non-blocking `Child` or any other intermediate. ### Solution This PR moves the implementation of `Command::output` to `std::sys`. This means targets can choose to implement only `Command::output` without having to implement `Command::spawn`. ### Additional Information This was originally conceived when working on https://github.com/rust-lang/rust/pull/100316. Currently, the only target I know about that will benefit from this change is UEFI. This PR can also be used to implement more efficient `Command::output` since the intermediate `Process` is not actually needed anymore, but that is outside the scope of this PR. Since this is not a public API change, I'm not sure if an RFC is needed or not.
2022-12-12explain mem::forget(env_lock) in fork/execRalf Jung-3/+4
2022-12-11Implement blocking outputAyush Singh-0/+19
This allows decoupling `Command::spawn` and `Command::output`. This is useful for targets which do support launching programs in blocking mode but do not support multitasking (Eg: UEFI). This was originally conceived when working on https://github.com/rust-lang/rust/pull/100316 Signed-off-by: Ayush Singh <ayushsingh1325@gmail.com>
2022-10-20Change process spawning to inherit the parent's signal mask by defaultRain-66/+87
Previously, the signal mask is always reset when a child process is started. This breaks tools like `nohup` which expect `SIGHUP` to be blocked. With this change, the default behavior changes to inherit the signal mask. This also changes the signal disposition for `SIGPIPE` to only be changed if the `#[unix_sigpipe]` attribute isn't set.
2022-10-14more dupe word typosRageking8-1/+1
2022-09-20Remove use of `io::ErrorKind::Other` in stdPatiga-2/+2
The documentation states that this `ErrorKind` is not used by the standard library. Instead, `io::ErrorKind::Uncategorized` should be used.
2022-08-28Use posix_spawn for absolute paths on macOSRain-1/+60
Currently, on macOS, Rust never uses the fast posix_spawn path if a directory change is requested due to a bug in Apple's libc. However, the bug is only triggered if the program is a relative path. This PR makes it so that the fast path continues to work if the program is an absolute path or a lone filename. This was an alternative proposed in https://github.com/rust-lang/rust/pull/80537#issue-776674009, and it makes a measurable performance difference in some of my code that spawns thousands of processes.
2022-08-21Fix redundant comparisonThom Chiovoloni-1/+1
2022-08-19Align android `sigaddset` impl with the reference impl from BionicThom Chiovoloni-3/+23
2022-06-13Horizon OS STD supportMeziu-9/+7
Co-authored-by: Ian Chamberlain <ian.h.chamberlain@gmail.com> Co-authored-by: Mark Drobnak <mark.drobnak@gmail.com>
2022-06-05Remove SIGIO reference on HaikuRyan Zoeller-0/+1
Haiku doesn't define SIGIO. The nix crate already employs this workaround: https://github.com/nix-rust/nix/blob/5dedbc7850448ae3922ab0a833f3eb971bf7e25f/src/sys/signal.rs#L92-L94
2022-06-03Auto merge of #95833 - notriddle:notriddle/human-readable-signals, r=yaahcbors-6/+82
std: `<ExitStatus as Display>::fmt` name the signal it died from Related to #95601
2022-06-02Fix MIPS-specific signal bugMichael Howell-1/+10
2022-06-01std: show signal number along with nameMichael Howell-46/+50
2022-05-09Use Rust 2021 prelude in std itself.Mara Bos-5/+0
2022-04-25Remove references to git.ioEric Huss-1/+2
2022-04-23std: `<ExitStatus as Display>::fmt` name the signal it died fromMichael Howell-3/+66
2022-04-17Auto merge of #93530 - anonion0:pthread_sigmask_fix, r=JohnTitorbors-4/+5
fix error handling for pthread_sigmask(3) Errors from `pthread_sigmask(3)` were handled using `cvt()`, which expects a return value of `-1` on error and uses `errno`. However, `pthread_sigmask(3)` returns `0` on success and an error number otherwise. Fix it by replacing `cvt()` with `cvt_nz()`.
2022-04-17move import to fix warning with emscripten targetRalf Sager-1/+2
2022-03-19Rollup merge of #93858 - krallin:process-process_group, r=dtolnayDylan DPC-2/+80
Add a `process_group` method to UNIX `CommandExt` - Tracking issue: #93857 - RFC: https://github.com/rust-lang/rfcs/pull/3228 Add a `process_group` method to `std::os::unix::process::CommandExt` that allows setting the process group id (i.e. calling `setpgid`) in the child, thus enabling users to set process groups while leveraging the `posix_spawn` fast path.
2022-03-19Rollup merge of #92612 - atopia:update-lib-l4re, r=dtolnayDylan DPC-1/+4
Update stdlib for the l4re target This PR contains the work by ``@humenda`` and myself to update standard library support for the x86_64-unknown-l4re-uclibc tier 3 target, split out from humenda/rust as requested in #85967. The changes have been rebased on current master and updated in follow up commits by myself. The publishing of the changes is authorized and preferred by the original author. To preserve attribution, when standard library changes were introduced as part of other changes to the compiler, I have kept the changes concerning the standard library and altered the commit messages as indicated. Any incompatibilities have been remedied in follow up commits, so that the PR as a whole should result in a clean update of the target.
2022-03-17feat: Add use of bool::then in sys/unix/processwcampbell-3/+3
Remove else { None } in favor of using bool::then()
2022-03-14Add a `process_group` method to UNIX `CommandExt`Thomas Orozco-2/+80
2022-03-10Use implicit capture syntax in format_argsT-O-R-U-S-8/+8
This updates the standard library's documentation to use the new syntax. The documentation is worthwhile to update as it should be more idiomatic (particularly for features like this, which are nice for users to get acquainted with). The general codebase is likely more hassle than benefit to update: it'll hurt git blame, and generally updates can be done by folks updating the code if (and when) that makes things more readable with the new format. A few places in the compiler and library code are updated (mostly just due to already having been done when this commit was first authored).
2022-03-09drop unused libc imports on L4ReBenjamin Lamowski-1/+4
As a capability-based microkernel OS, L4Re only has incomplete support for POSIX APIs, in particular it does not implement UIDs and GIDs.
2022-03-01Provide C FFI types via core::ffi, not just in stdJosh Triplett-3/+3
The ability to interoperate with C code via FFI is not limited to crates using std; this allows using these types without std. The existing types in `std::os::raw` become type aliases for the ones in `core::ffi`. This uses type aliases rather than re-exports, to allow the std types to remain stable while the core types are unstable. This also moves the currently unstable `NonZero_` variants and `c_size_t`/`c_ssize_t`/`c_ptrdiff_t` types to `core::ffi`, while leaving them unstable.
2022-02-09Rollup merge of #93445 - yaahc:exitcode-constructor, r=dtolnayYuki Okushi-0/+6
Add From<u8> for ExitCode This should cover a mostly cross-platform subset of supported exit codes. We decided to stick with `u8` initially since its the common subset between all platforms that we support (excluding wasm which I think only works with `true` or `false`). Posix is supposed to take i32s, but in practice many unix platforms mask out all but the low 8 bits or in some cases the 8-15th bits. Windows takes a u32 instead of an i32. Bourne-compatible shells also report signals as exitcode 128 + `signal_no`, so there's some ambiguity there when returning exit codes > 127, but it is possible to disambiguate them on the other side so we decided against restricting the possible codes further than to `u8`. ## Related - Detailed analysis of exit code support on various platforms: https://internals.rust-lang.org/t/mini-pre-rfc-redesigning-process-exitstatus/5426 - https://github.com/rust-lang/rust/issues/48711 - https://github.com/rust-lang/rust/issues/43301 - https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/Termination.2FExit.20Status.20Stabilization
2022-02-06Add From<u8> for ExitCodeJane Lusby-0/+6
This should cover a mostly cross-platform subset of supported exit codes.
2022-02-04Hide Repr details from io::Error, and rework `io::Error::new_const`.Thom Chiovoloni-20/+17
2022-01-31fix error handling for pthread_sigmask(3)Ralf Sager-5/+5
Errors from pthread_sigmask(3) were handled using cvt(), which expects a return value of -1 on error and uses errno. However, pthread_sigmask(3) returns 0 on success and an error number otherwise. Fix it by replacing cvt() with cvt_nz().
2022-01-21Old versions of Android generate SIGSEGV from libc::abortAmanieu d'Antras-1/+6
2021-12-14Fix a bunch of typosFrank Steffahn-1/+1
2021-11-12Refactor weak symbols in std::sys::unixJosh Stone-2/+2
This makes a few changes to the weak symbol macros in `sys::unix`: - `dlsym!` is added to keep the functionality for runtime `dlsym` lookups, like for `__pthread_get_minstack@GLIBC_PRIVATE` that we don't want to show up in ELF symbol tables. - `weak!` now uses `#[linkage = "extern_weak"]` symbols, so its runtime behavior is just a simple null check. This is also used by `syscall!`. - On non-ELF targets (macos/ios) where that linkage is not known to behave, `weak!` is just an alias to `dlsym!` for the old behavior. - `raw_syscall!` is added to always call `libc::syscall` on linux and android, for cases like `clone3` that have no known libc wrapper. The new `weak!` linkage does mean that you'll get versioned symbols if you build with a newer glibc, like `WEAK DEFAULT UND statx@GLIBC_2.28`. This might seem problematic, but old non-weak symbols can tie the build to new versions too, like `dlsym@GLIBC_2.34` from their recent library unification. If you build with an old glibc like `dist-x86_64-linux` does, you'll still get unversioned `WEAK DEFAULT UND statx`, which may be resolved based on the runtime glibc. I also found a few functions that don't need to be weak anymore: - Android can directly use `ftruncate64`, `pread64`, and `pwrite64`, as these were added in API 12, and our baseline is API 14. - Linux can directly use `splice`, added way back in glibc 2.5 and similarly old musl. Android only added it in API 21 though.
2021-11-12Rollup merge of #90704 - ijackson:exitstatus-comments, r=joshtriplettMatthias Krüger-0/+3
Unix ExitStatus comments and a tiny docs fix Some nits left over from #88300
2021-11-11unix::ExitStatus: Add comment saying that it's a wait statusIan Jackson-0/+3
With cross-reference. Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-11-05Also note tool expectations of fork vs clone3Josh Stone-0/+2
Co-authored-by: Josh Triplett <josh@joshtriplett.org>
2021-11-05Update another comment on fork vs. clone3Josh Stone-2/+2
2021-11-05Only use `clone3` when needed for pidfdJosh Stone-7/+6
In #89522 we learned that `clone3` is interacting poorly with Gentoo's `sandbox` tool. We only need that for the unstable pidfd extensions, so otherwise avoid that and use a normal `fork`.
2021-10-15[fuchsia] Update process info structJoshua Seaton-4/+7
The fuchsia platform is in the process of softly transitioning over to using a new value for ZX_INFO_PROCESS with a new corresponding struct. This change migrates libstd. See fxrev.dev/510478 and fxbug.dev/30751 for more detail.
2021-10-05Rollup merge of #88828 - FabianWolff:issue-88585, r=dtolnayManish Goregaokar-3/+13
Use `libc::sigaction()` instead of `sys::signal()` to prevent a deadlock Fixes #88585. POSIX [specifies](https://man7.org/linux/man-pages/man3/fork.3p.html) that after forking, > to avoid errors, the child process may only execute async-signal-safe operations until such time as one of the exec functions is called. Rust's standard library does not currently adhere to this, as evidenced by #88585. The child process calls [`sys::signal()`](https://github.com/rust-lang/rust/blob/7bf0736e130e2203c58654f7353dbf9575e49d5c/library/std/src/sys/unix/android.rs#L76), which on Android calls [`libc::dlsym()`](https://github.com/rust-lang/rust/blob/7bf0736e130e2203c58654f7353dbf9575e49d5c/library/std/src/sys/unix/weak.rs#L101), which is [**not**](https://man7.org/linux/man-pages/man7/signal-safety.7.html) async-signal-safe, and in fact causes a deadlock in the example in #88585. I think the easiest solution here would be to just call `libc::sigaction()` instead, which [is](https://man7.org/linux/man-pages/man7/signal-safety.7.html) async-signal-safe, provides the functionality we need, and is apparently available on all Android versions because it is also used e.g. [here](https://github.com/rust-lang/rust/blob/7bf0736e130e2203c58654f7353dbf9575e49d5c/library/std/src/sys/unix/stack_overflow.rs#L112-L114).
2021-10-03Rollup merge of #88305 - ijackson:exitstatus-debug, r=dtolnayManish Goregaokar-3/+21
Manual Debug for Unix ExitCode ExitStatus ExitStatusError These structs have misleading names. An ExitStatus[Error] is actually a Unix wait status; an ExitCode is actually an exit status. These misleading names appear in the `Debug` output. The `Display` impls on Unix have been improved, but the `Debug` impls are still misleading, as reported in #74832. Fix this by pretending that these internal structs are called `unix_exit_status` and `unix_wait_status` as applicable. (We can't actually rename the structs because of the way that the cross-platform machinery works: the names are cross-platform.) After this change, this program ``` #![feature(exit_status_error)] fn main(){ let x = std::process::Command::new("false").status().unwrap(); dbg!(x.exit_ok()); eprintln!("x={:?}",x); } ``` produces this output ``` [src/main.rs:4] x.exit_ok() = Err( ExitStatusError( unix_wait_status( 256, ), ), ) x=ExitStatus(unix_wait_status(256)) ``` Closes #74832
2021-10-01Call `libc::sigaction()` only on AndroidFabian Wolff-3/+14
2021-09-28Clean up unneeded explicit pointer castDavid Tolnay-1/+1
The reference automatically coerces to a pointer. Writing an explicit cast here is slightly misleading because that's most commonly used when a pointer needs to be converted from one pointer type to another, e.g. `*const c_void` to `*const sigaction` or vice versa.
2021-09-10Use `libc::sigaction()` instead of `sys::signal()` to prevent a deadlockFabian Wolff-4/+3
2021-08-24Manual Debug for Unix ExitCode ExitStatus ExitStatusErrorIan Jackson-3/+21
These structs have misleading names. An ExitStatus[Error] is actually a Unix wait status; an ExitCode is actually an exit status. The Display impls are fixed, but the Debug impls are still misleading, as reported in #74832. Fix this by pretending that these internal structs are called `unix_exit_status` and `unix_wait_status` as applicable. (We can't actually rename the structs because of the way that the cross-platform machinery works: the names are cross-platform.) Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-08-24Remove unnecessary unsafe block in `process_unix`Léo Lanteri Thauvin-2/+1
2021-08-19Fix an unused import warning.Dan Gohman-1/+1
2021-08-19Update PidFd for the new I/O safety APIs.Dan Gohman-5/+11