about summary refs log tree commit diff
path: root/library/std/src/sys/unix
AgeCommit message (Collapse)AuthorLines
2021-02-23Update outdated comment in unix Command.Eric Huss-17/+7
2021-02-23ExitStatus: Improve documentation re wait status vs exit statusIan Jackson-2/+12
The use of `ExitStatus` as the Rust type name for a Unix *wait status*, not an *exit status*, is very confusing, but sadly probably too late to change. This area is confusing enough in Unix already (and many programmers are already confuxed). We can at least document it. I chose *not* to mention the way shells like to exit with signal numbers, thus turning signal numbers into exit statuses. This is only relevant for Rust programs using `std::process` if they run shells. Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-02-23process::unix: Test wait status formattingIan Jackson-0/+26
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-02-22fix io::copy specialization when writer was opened with O_APPENDThe8472-8/+10
2021-02-22add test for failing io::copy specializationThe8472-0/+18
2021-02-22process::unix: Handle other wait statuses in ExitStatus as DisplayIan Jackson-2/+11
Currently, on Nightly, this panics: ``` use std::process::ExitStatus; use std::os::unix::process::ExitStatusExt; fn main() { let st = ExitStatus::from_raw(0x007f); println!("st = {}", st); } ``` This is because the impl of Display assumes that if .code() is None, .signal() must be Some. That was a false assumption, although it was true with buggy code before 5b1316f78152a9c066b357ea9addf803d48e114a unix ExitStatus: Do not treat WIFSTOPPED as WIFSIGNALED This is not likely to have affected many people in practice, because `Command` will never produce such a wait status (`ExitStatus`). Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-02-15Rollup merge of #81975 - Amanieu:seal2, r=m-ou-seJonas Schievink-13/+6
Seal the CommandExt, OsStrExt and OsStringExt traits A crater run (https://github.com/rust-lang/rust/pull/81213#issuecomment-767651811) has shown that this does not break any existing code. This also unblocks #77728. Based on #81213. r? ````@m-ou-se```` cc ````@lygstate````
2021-02-10Seal the CommandExt, OsStrExt and OsStringExt traitsAmanieu d'Antras-13/+6
2021-02-09split guard into read and write typesThe8472-2/+2
2021-02-08introduce StaticRWLock wrapper to make methods safeThe8472-11/+12
2021-02-08avoid &mut on the read path since it now allows concurrent readersThe8472-1/+1
2021-02-07use rwlock for accessing ENVThe8472-11/+11
2021-01-21Add setgroups to std::os::unix::process::CommandExtslo1-7/+41
2021-01-20Deprecate-in-future the constants superceded by RFC 2700bstrie-1/+0
2021-01-17Don't use posix_spawn_file_actions_addchdir_np on macOS.Eric Huss-4/+14
2021-01-14Rollup merge of #79982 - ijackson:exit-status, r=dtolnayMara Bos-2/+116
Add missing methods to unix ExitStatusExt These are the methods corresponding to the remaining exit status examination macros from `wait.h`. `WCOREDUMP` isn't in SuS but is it is very standard. I have not done portability testing to see if this builds everywhere, so I may need to Do Something if it doesn't. There is also a bugfix and doc improvement to `.signal()`, and an `.into_raw()` accessor. This would fix #73128 and fix #73129. Please let me know if you like this direction, and if so I will open the tracking issue and so on. If this MR goes well, I may tackle #73125 next - I have an idea for how to do it.
2021-01-13Fix typos in Fuchsia unix_process_wait_moreDavid Tolnay-2/+2
2021-01-13ExitStatusExt: Fix build on FuchsiaIan Jackson-0/+44
This is not particularly pretty but the current situation is a mess and I don't think I'm making it significantly worse. Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-01-13Fix typo saeled -> sealedDavid Tolnay-1/+1
2021-01-13ExitStatusExt unix: Retrospectively seal this traitIan Jackson-1/+15
As discussed in #79982. I think the "new interfaces", ie the new trait and impl, must be insta-stable. This seems OK because we are, in fact, adding a new restriction to the stable API. Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-01-13unix ExitStatus: Add tracking issue to new methodsIan Jackson-4/+4
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-01-13Replace `Ie` with `In other words`Ian Jackson-1/+1
Co-authored-by: Joshua Nelson <joshua@yottadb.com>
2021-01-13Replace `Ie` with `In other words`Ian Jackson-1/+1
Co-authored-by: Joshua Nelson <joshua@yottadb.com>
2021-01-13unix ExitStatus: Provide .continued()Ian Jackson-0/+15
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-01-13unix ExitStatus: Provide .stopped_signal()Ian Jackson-0/+15
Necessary to handle WIFSTOPPED. Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-01-13unix ExitStatus: Provide .core_dumpedIan Jackson-0/+12
This is essential for proper reporting of child process status on Unix. Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-01-13unix ExitStatus: Provide .into_raw()Ian Jackson-0/+12
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-01-13unix ExitStatus: Clarify docs for .signal()Ian Jackson-0/+2
We need to be clear that this never returns WSTOPSIG. That is, if WIFSTOPPED, the return value is None. Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-01-13unix ExitStatus: Do not treat WIFSTOPPED as WIFSIGNALEDIan Jackson-1/+1
A unix wait status can contain, at least, exit statuses, termination signals, and stop signals. WTERMSIG is only valid if WIFSIGNALED. https://pubs.opengroup.org/onlinepubs/9699919799/functions/wait.html It will not be easy to experience this bug with `Command`, because that doesn't pass WUNTRACED. But you could make an ExitStatus containing, say, a WIFSTOPPED, from a call to one of the libc wait functions. (In the WIFSTOPPED case, there is WSTOPSIG. But a stop signal is encoded differently to a termination signal, so WTERMSIG and WSTOPSIG are by no means the same.) Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-01-13Update code to account for extern ABI requirementMark Rousskov-1/+1
2020-12-29Fix small typo in time commentBlackHoleFox-1/+1
2020-12-21Auto merge of #80088 - operutka:fix-cmsg-len-uclibc, r=dtolnaybors-1/+5
Fix failing build of std on armv5te-unknown-linux-uclibceabi due to missing cmsg_len_zero I'm getting the following error when trying to build `std` on `armv5te-unknown-linux-uclibceabi`: ``` error[E0425]: cannot find value `cmsg_len_zero` in this scope --> /home/operutka/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys/unix/ext/net/ancillary.rs:376:47 | 376 | let data_len = (*cmsg).cmsg_len - cmsg_len_zero; | ^^^^^^^^^^^^^ not found in this scope ``` Obviously, this branch: ```rust cfg_if::cfg_if! { if #[cfg(any(target_os = "android", all(target_os = "linux", target_env = "gnu")))] { let cmsg_len_zero = libc::CMSG_LEN(0) as libc::size_t; } else if #[cfg(any( target_os = "dragonfly", target_os = "emscripten", target_os = "freebsd", all(target_os = "linux", target_env = "musl",), target_os = "netbsd", target_os = "openbsd", ))] { let cmsg_len_zero = libc::CMSG_LEN(0) as libc::socklen_t; } } ``` does not cover the case `all(target_os = "linux", target_env = "uclibc")`.
2020-12-20Auto merge of #74699 - notriddle:fd-non-negative, r=m-ou-sebors-2/+9
Mark `-1` as an available niche for file descriptors Based on discussion from <https://internals.rust-lang.org/t/can-the-standard-library-shrink-option-file/12768>, the file descriptor `-1` is chosen based on the POSIX API designs that use it as a sentinel to report errors. A bigger niche could've been chosen, particularly on Linux, but would not necessarily be portable. This PR also adds a test case to ensure that the -1 niche (which is kind of hacky and has no obvious test case) works correctly. It requires the "upper" bound, which is actually -1, to be expressed in two's complement.
2020-12-20Check that c_int is i32 in FileDesc::new.Mara Bos-1/+1
2020-12-16Fix failing build of std on armv5te-unknown-linux-uclibceabi due to missing ↵Ondrej Perutka-1/+5
cmsg_len_zero
2020-12-10Rollup merge of #79375 - vext01:kernel-copy-temps, r=bjorn3Tyler Mandry-8/+11
Make the kernel_copy tests more robust/concurrent. These tests write to the same filenames in /tmp and in some cases these files don't get cleaned up properly. This caused issues for us when different users run the tests on the same system, e.g.: ``` ---- sys::unix::kernel_copy::tests::bench_file_to_file_copy stdout ---- thread 'sys::unix::kernel_copy::tests::bench_file_to_file_copy' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 13, kind: PermissionDenied, message: "Permission denied" }', library/std/src/sys/unix/kernel_copy/tests.rs:71:10 ---- sys::unix::kernel_copy::tests::bench_file_to_socket_copy stdout ---- thread 'sys::unix::kernel_copy::tests::bench_file_to_socket_copy' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 13, kind: PermissionDenied, message: "Permission denied" }', library/std/src/sys/unix/kernel_copy/tests.rs💯10 ``` Use `std::sys_common::io__test::tmpdir()` to solve this. CC ``@the8472.``
2020-12-10Fix fd test caseMichael Howell-1/+1
2020-12-10Add safety note to library/std/src/sys/unix/fd.rsMichael Howell-0/+1
Co-authored-by: Elichai Turkel <elichai.turkel@gmail.com>
2020-12-10Mark `-1` as an available niche for file descriptorsMichael Howell-1/+7
Based on discussion from https://internals.rust-lang.org/t/can-the-standard-library-shrink-option-file/12768, the file descriptor -1 is chosen based on the POSIX API designs that use it as a sentinel to report errors. A bigger niche could've been chosen, particularly on Linux, but would not necessarily be portable. This PR also adds a test case to ensure that the -1 niche (which is kind of hacky and has no obvious test case) works correctly. It requires the "upper" bound, which is actually -1, to be expressed in two's complement.
2020-12-09Improve comment grammarThe8472-2/+2
2020-12-09implement better availability probing for copy_file_rangeThe8472-34/+48
previously any attempt to copy to an immutable file (EPERM) would disable copy_file_range support for the whole process.
2020-12-09Auto merge of #79387 - woodruffw-forks:ww/peer-cred-pid-macos, r=Amanieubors-15/+57
ext/ucred: Support PID in peer creds on macOS This is a follow-up to https://github.com/rust-lang/rust/pull/75148 (RFC: https://github.com/rust-lang/rust/issues/42839). The original PR used `getpeereid` on macOS and the BSDs, since they don't (generally) support the `SO_PEERCRED` mechanism that Linux supplies. This PR splits the macOS/iOS implementation of `peer_cred()` from that of the BSDs, since macOS supplies the `LOCAL_PEERPID` sockopt as a source of the missing PID. It also adds a `cfg`-gated tests that ensures that platforms with support for PIDs in `UCred` have the expected data.
2020-12-03Make the kernel_copy tests more robust/concurrent.Edd Barrett-8/+11
These tests write to the same filenames in /tmp and in some cases these files don't get cleaned up properly. This caused issues for us when different users run the tests on the same system, e.g.: ``` ---- sys::unix::kernel_copy::tests::bench_file_to_file_copy stdout ---- thread 'sys::unix::kernel_copy::tests::bench_file_to_file_copy' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 13, kind: PermissionDenied, message: "Permission denied" }', library/std/src/sys/unix/kernel_copy/tests.rs:71:10 ---- sys::unix::kernel_copy::tests::bench_file_to_socket_copy stdout ---- thread 'sys::unix::kernel_copy::tests::bench_file_to_socket_copy' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 13, kind: PermissionDenied, message: "Permission denied" }', library/std/src/sys/unix/kernel_copy/tests.rs:100:10 ``` Use `std::sys_common::io__test::tmpdir()` to solve this.
2020-12-03fix copy specialization not updating Take wrappersThe8472-14/+45
2020-12-02update test to check Take limits after copyingThe8472-2/+9
2020-12-02Auto merge of #69864 - LinkTed:master, r=Amanieubors-1771/+3097
unix: Extend UnixStream and UnixDatagram to send and receive file descriptors Add the functions `recv_vectored_fds` and `send_vectored_fds` to `UnixDatagram` and `UnixStream`. With this functions `UnixDatagram` and `UnixStream` can send and receive file descriptors, by using `recvmsg` and `sendmsg` system call.
2020-12-01Leverage kernel copy for UnixStreamNicolas Koch-0/+29
UDS can be a sendfile destination, just like TCP sockets.
2020-12-01Add benchmark for File to UnixStream copyNicolas Koch-0/+29
2020-11-26Add comment for the previous android bug fixLinkTed-0/+4
2020-11-24Bug fix for android platform, because of the wrong behavior of CMSG_NXTHDRLinkTed-0/+19