about summary refs log tree commit diff
path: root/library/std/src/process.rs
AgeCommit message (Collapse)AuthorLines
2022-05-16Add tracking issue for ExitCode::exit_processNoa-1/+1
2022-05-13Auto merge of #95356 - coolreader18:exitstatus-exit-method, r=<try>bors-28/+56
ExitCode::exit_process() method cc `@yaahc` / #93840 (eeek, hit ctrl-enter before I meant to and right after realizing the branch name was wrong. oh, well) I feel like it makes sense to have the `exit(ExitCode)` function as a method or at least associated function on ExitCode, but maybe that would hurt discoverability? Probably not as much if it's at the top of the `process::exit()` documentation or something, but idk. Also very unsure about the name, I'd like something that communicates that you are exiting with *this* ExitCode, but with a method name being postfix it doesn't seem to flow. `code.exit_process_with()` ? `.exit_process_with_self()` ? Blech. Maybe it doesn't matter, since ideally just `code.exit()` or something would be clear simply by the name and single parameter but :shrug: Also I'd like to touch up the `ExitCode` docs (which I did a bit here), but that would probably be good in a separate PR, right? Since I think the beta deadline is coming up.
2022-05-13Guarantee less in docsNoa-2/+2
2022-05-13Add ExitCode::exit_process exampleNoa-0/+23
2022-03-30Remove antipattern from process::exit docsNoa-28/+13
2022-03-30Add ExitCode::exit_process()Noa-0/+20
2022-03-29fix since field version for termination stabilizationJane Lusby-13/+13
2022-03-29Rollup merge of #93840 - ↵Dylan DPC-24/+68
yaahc:termination-stabilization-celebration-station, r=joshtriplett Stabilize Termination and ExitCode From https://github.com/rust-lang/rust/issues/43301 This PR stabilizes the Termination trait and associated ExitCode type. It also adjusts the ExitCode feature flag to replace the placeholder flag with a more permanent name, as well as splitting off the `to_i32` method behind its own permanently unstable feature flag. This PR stabilizes the termination trait with the following signature: ```rust pub trait Termination { fn report(self) -> ExitCode; } ``` The existing impls of `Termination` are effectively already stable due to the prior stabilization of `?` in main. This PR also stabilizes the following APIs on exit code ```rust #[derive(Clone, Copy, Debug)] pub struct ExitCode(_); impl ExitCode { pub const SUCCESS: ExitCode; pub const FAILURE: ExitCode; } impl From<u8> for ExitCode { /* ... */ } ``` --- All of the previous blockers have been resolved. The main ones that were resolved recently are: * The trait's name: We decided against changing this since none of the alternatives seemed particularly compelling. Instead we decided to end the bikeshedding and stick with the current name. ([link to the discussion](https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/Termination.2FExit.20Status.20Stabilization/near/269793887)) * Issues around platform specific representations: We resolved this issue by changing the return type of `report` from `i32` to the opaque type `ExitCode`. That way we can change the underlying representation without affecting the API, letting us offer full support for platform specific exit code APIs in the future. * Custom exit codes: We resolved this by adding `From<u8> for ExitCode`. We choose to only support u8 initially because it is the least common denominator between the sets of exit codes supported by our current platforms. In the future we anticipate adding platform specific extension traits to ExitCode for constructors from larger or negative numbers, as needed.
2022-03-28Touch up ExitCode docsNoa-7/+26
2022-03-25std::process docs: linkify references to output, spawn and statusest31-7/+20
2022-03-22add some fixZHANGWENTAI-3/+4
Signed-off-by: ZHANGWENTAI <2092913428@qq.com>
2022-03-22fix the lint problemZHANGWENTAI-1/+1
Signed-off-by: ZHANGWENTAI <2092913428@qq.com>
2022-03-22update Termination trait docsZHANGWENTAI-0/+4
2022-03-10Use implicit capture syntax in format_argsT-O-R-U-S-9/+9
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-02-22Stabilize Termination and ExitCodeJane Lusby-19/+44
2022-02-17Rollup merge of #89869 - kpreid:from-doc, r=yaahcMatthias Krüger-4/+4
Add documentation to more `From::from` implementations. For users looking at documentation through IDE popups, this gives them relevant information rather than the generic trait documentation wording “Performs the conversion”. For users reading the documentation for a specific type for any reason, this informs them when the conversion may allocate or copy significant memory versus when it is always a move or cheap copy. Notes on specific cases: * The new documentation for `From<T> for T` explains that it is not a conversion at all. * Also documented `impl<T, U> Into<U> for T where U: From<T>`, the other central blanket implementation of conversion. * The new documentation for construction of maps and sets from arrays of keys mentions the handling of duplicates. Future work could be to do this for *all* code paths that convert an iterable to a map or set. * I did not add documentation to conversions of a specific error type to a more general error type. * I did not add documentation to unstable code. This change was prepared by searching for the text "From<... for" and so may have missed some cases that for whatever reason did not match. I also looked for `Into` impls but did not find any worth documenting by the above criteria.
2022-02-06Add From<u8> for ExitCodeJane Lusby-0/+8
This should cover a mostly cross-platform subset of supported exit codes.
2022-01-31add inline attribute to new methodJane Lusby-1/+2
2022-01-28Change Termination::report return type to ExitCodeJane Lusby-8/+22
2021-12-18Update stdlib to the 2021 editionLucas Kent-1/+0
2021-12-09Auto merge of #81156 - DrMeepster:read_buf, r=joshtriplettbors-13/+1
Implement most of RFC 2930, providing the ReadBuf abstraction This replaces the `Initializer` abstraction for permitting reading into uninitialized buffers, closing #42788. This leaves several APIs described in the RFC out of scope for the initial implementation: * read_buf_vectored * `ReadBufs` Closes #42788, by removing the relevant APIs.
2021-12-04Add documentation to more `From::from` implementations.Kevin Reid-4/+4
For users looking at documentation through IDE popups, this gives them relevant information rather than the generic trait documentation wording “Performs the conversion”. For users reading the documentation for a specific type for any reason, this informs them when the conversion may allocate or copy significant memory versus when it is always a move or cheap copy. Notes on specific cases: * The new documentation for `From<T> for T` explains that it is not a conversion at all. * Also documented `impl<T, U> Into<U> for T where U: From<T>`, the other central blanket implementation of conversion. * I did not add documentation to conversions of a specific error type to a more general error type. * I did not add documentation to unstable code. This change was prepared by searching for the text "From<... for" and so may have missed some cases that for whatever reason did not match. I also looked for `Into` impls but did not find any worth documenting by the above criteria.
2021-11-16Rollup merge of #88601 - ibraheemdev:termination-result-infallible, r=yaahcYuki Okushi-0/+9
Implement `Termination` for `Result<Infallible, E>` As noted in #43301, `Result<!, E>` is not usable on stable.
2021-11-11process::ExitStatus: Discuss `exit` vs `_exit` in a comment.Ian Jackson-0/+5
As discussed here https://github.com/rust-lang/rust/pull/88300#issuecomment-936097710 I felt this was the best place to put this (rather than next to ExitStatusExt). After all, it's a property of the ExitStatus type on Unix. Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-11-02read_bufDrMeepster-13/+1
2021-10-30Add #[must_use] to remaining std functions (O-Z)John Kugelman-0/+13
2021-10-09Rollup merge of #88436 - lf-:stabilize-command-access, r=yaahcGuillaume Gomez-12/+8
std: Stabilize command_access Tracking issue: #44434 (not yet closed but the FCP is done so that should be soon).
2021-10-05Apply suggestions from code reviewJane Lusby-8/+8
2021-09-16Merge sys_common::rt into rtbjorn3-1/+1
2021-09-03simplify `impl Termination for Result<Infallible, E>`Ibraheem Ahmed-2/+1
Co-authored-by: Konrad Borowski <konrad@borowski.pw>
2021-09-02implement `Termination` for `Result<Infallible, E>`ibraheemdev-0/+10
2021-08-28std: Stabilize command_accessJade-12/+8
Tracking issue: #44434
2021-08-19Add comments about impls for File, TcpStream, ChildStdin, etc.Dan Gohman-0/+18
2021-08-06Auto merge of #87774 - camelid:process-typo, r=jyn514bors-1/+1
Fix typo Add missing "by".
2021-08-04Fix typoNoah Lev-1/+1
2021-08-04Re-use std::sealed::Sealed in os/linux/process.Mara Bos-0/+4
2021-07-21Add Linux-specific pidfd process extensionsAaron Hill-1/+1
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?
2021-07-05s/die/terminate/ in abort documentation.Mara Bos-1/+1
2021-07-05abort docs: Document buffer non-flushingIan Jackson-0/+3
There is discussion of this in #40230 which requests clarification. Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-07-05aborts: Clarify documentation and commentsIan Jackson-0/+4
In the docs for intrinsics::abort(): * Strengthen the recommendation by to use process::abort instead. * Document the fact that it (ab)uses an LLVM debug trap and what the likely consequences are. * State that the precise behaviour is unstable. In the docs for process::abort(): * Promise that we have the same behaviour as C `abort()`. * Document the likely consequences, including, specifically, the consequences on Unix. In the internal comment for unix::abort_internal: * Refer to the public docs for the public API functions. * Correct and expand the description of libc::abort. Specifically: * Do not claim that abort() unregisters signal handlers. It doesn't; it honours the SIGABRT handler. * Discuss, extensively, the issue with abort() flushing stdio buffers. * Describe the glibc behaviour in some detail. Co-authored-by: Mark Wooding <mdw@distorted.org.uk> Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-07-03Rollup merge of #86803 - ↵Yuki Okushi-2/+2
xfix:remove-unnecessary-ampersand-from-command-args-calls, r=joshtriplett Remove & from Command::args calls in documentation Now that arrays implement `IntoIterator`, using `&` is no longer necessary. This makes examples easier to understand.
2021-07-02Remove & from Command::args calls in documentationKonrad Borowski-2/+2
Now that arrays implement `IntoIterator`, using `&` is no longer necessary. This makes examples easier to understand.
2021-07-02Auto merge of #85746 - m-ou-se:io-error-other, r=joshtriplettbors-3/+1
Redefine `ErrorKind::Other` and stop using it in std. This implements the idea I shared yesterday in the libs meeting when we were discussing how to handle adding new `ErrorKind`s to the standard library: This redefines `Other` to be for *user defined errors only*, and changes all uses of `Other` in the standard library to a `#[doc(hidden)]` and permanently `#[unstable]` `ErrorKind` that users can not match on. This ensures that adding `ErrorKind`s at a later point in time is not a breaking change, since the user couldn't match on these errors anyway. This way, we use the `#[non_exhaustive]` property of the enum in a more effective way. Open questions: - How do we check this change doesn't cause too much breakage? Will a crate run help and be enough? - How do we ensure we don't accidentally start using `Other` again in the standard library? We don't have a `pub(not crate)` or `#[deprecated(in this crate only)]`. cc https://github.com/rust-lang/rust/pull/79965 cc `@rust-lang/libs` `@ijackson` r? `@dtolnay`
2021-06-25Fix a few misspellings.Eric Huss-1/+1
2021-06-15Redefine `ErrorKind::Other` and stop using it in std.Mara Bos-3/+1
2021-05-12impl crate::error::Error for ExitStatusErrorIan Jackson-0/+3
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-05-12ExitStatusError: Be more verbose in Display implIan Jackson-1/+1
Co-authored-by: Jane Lusby <jlusby@yaah.dev>
2021-05-12Fix typo in docIan Jackson-1/+1
Co-authored-by: Josh Triplett <josh@joshtriplett.org>
2021-05-12unix: impl ExitStatusExt for ExitStatusErrorIan Jackson-3/+6
It is unergnomic to have to say things like bad.into_status().signal() Implementing `ExitStatusExt` for `ExitStatusError` fixes this. Unfortunately it does mean making a previously-infallible method capable of panicing, although of course the existing impl remains infallible. The alternative would be a whole new `ExitStatusErrorExt` trait. `<ExitStatus as ExitStatusExt>::into_raw()` is not particularly ergonomic to call because of the often-required type annotation. See for example the code in the test case in library/std/src/sys/unix/process/process_unix/tests.rs Perhaps we should provide equivalent free functions for `ExitStatus` and `ExitStatusExt` in std::os::unix::process and maybe deprecate this trait method. But I think that is for the future. Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-05-12Provide ExitStatusErrorIan Jackson-3/+135
Closes #73125 This is in pursuance of Issue #73127 Consider adding #[must_use] to std::process::ExitStatus In MR #81452 Add #[must_use] to [...] process::ExitStatus we concluded that the existing arrangements in are too awkward so adding that #[must_use] is blocked on improving the ergonomics. I wrote a mini-RFC-style discusion of the approach in https://github.com/rust-lang/rust/issues/73125#issuecomment-771092741 Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>