summaryrefslogtreecommitdiff
path: root/src/unistd.rs
AgeCommit message (Collapse)Author
2021-07-24unistd: Add conversion from User to libc::passwdorvij
Add From<User> for libc::passwd trait implementation to convert a User into a libc::passwd Implementation consumes the User struct, giving ownership over the internal members to the libc::passwd struct Add the User::gecos field to 64-bit Android builds, since it is supported by libc::passwd for those builds
2021-07-24Mark most C-derived enums as non_exhaustiveAlan Somers
Since libc may add new variants at any time, Nix's consumers should not use exhaustive match patterns. Fixes #1182
2021-07-09Fix fork test and enable doc testJim Newsome
Replaces `println!` with raw `libc::write`. `println!` isn't guaranteed to be async-signal-safe, and almost certainly *isn't* due to internal buffering and locking. Adds a call to `libc::_exit` in the child arm, so that it doesn't fall through and start executing the parent code. Adds a call to `waitpid` in the parent arm, to clean up the child process. Removes the `no_run` directive, so that it's run in the doc tests.
2021-07-07Collapse Error into ErrnoAlan Somers
Now that Nix's weird error types are eliminated, there's no reason not to simply use Errno as the Error type.
2021-07-07Overhaul Nix's error typesAlan Somers
For many of Nix's consumers it be convenient to easily convert a Nix error into a std::io::Error. That's currently not possible because of the InvalidPath, InvalidUtf8, and UnsupportedOperation types that have no equivalent in std::io::Error. However, very few of Nix's public APIs actually return those unusual errors. So a more useful API would be for Nix's standard error type to implement Into<std::io::Error>. This commit makes Error a simple NewType around Errno. For most functions it's a drop-in replacement. There are only three exceptions: * clearenv now returns a bespoke error type. It was the only Nix function whose error couldn't be cleanly mapped onto an Errno. * sys::signal::signal now returns Error(Errno::ENOTSUP) instead of Error::UnsupportedOperation when the user passes an incompatible argument to `handler`. * When a NixPath exceeds PATH_MAX, it will now return Error(Errno::ENAMETOOLONG) instead of Error::InvalidPath. In the latter two cases there is now some abiguity about whether the error code was generated by Nix or by the OS. But I think the ambiguity is worth it for the sake of being able to implement Into<io::Error>. This commit also introduces Error::Sys() as a migration aid. Previously that as an enum variant. Now it's a function, but it will work in many of the same contexts as the original. Fixes #1155
2021-06-12Hopefully fix unreliability in unistd::alarm's doc testAlan Somers
2021-05-31Add getresuid() and getresgid() to unistdJeryl Vaz
2021-05-30misc Clippy cleanupAlan Somers
* Fix race conditions in the tests. Two tests were grabbing a mutex but immediately dropping it. Thank you, Clippy. * Remove vestigial Windows support. Remove some code added to support Windows in 2015. Nix is no longer intended to ever run on Windows. * Various other minor Clippy lints.
2021-05-13Use https instead of httpRyan Zoeller
2021-05-01Merge pull request #1431 from asomers/alarm_doc_test2Alan Somers
Hopefully improve unistd::alarm::set's doc test's reliability
2021-05-01Hopefully improve unistd::alarm::set's doc test's reliabilityAlan Somers
2021-04-26constify from_raw and as_raw for Uid, Gid and PidWolfgang Bumiller
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2021-03-25unistd: Increase maximum passwd/group buffer to 1MBGeoffrey Thomas
We have one UNIX group that contains most of our users whose size is about 20 kB, so `Group::from_name` is failing with ERANGE. The discussion on PR #864 suggests that 1 MB is a reasonable maximum - it follows what FreeBSD's libc does. (glibc appears to have no maximum on the _r function and will just double the buffer until malloc fails, but that's not particularly Rusty.)
2021-03-21illumos and Solaris supportJason King
Co-authored-by: Dominik Hassler <hadfl@omnios.org> Co-authored-by: Joshua M. Clulow <josh@sysmgr.org>
2021-02-07add passwords to GroupsBen Linsay
2020-12-19unistd: Add getpeereid(3)William Woodruff
Closes #1339.
2020-12-19Add fuchsia supportAmanda Tait
Allow nix to compile on Fuchsia by conditionally avoiding libc functionality that does not exist for Fuchsia.
2020-12-09Fix intermittency in the doc test for alarmAlan Somers
On Cirrus CI, this test would sometimes fail, probably due to pause being awoken by SIGRT_1. sigwait is a superior alternative to pause. Fixes #1354
2020-12-06Switch all builds from Travis to CirrusAlan Somers
Travis has been super-slow lately (> 6 hours per build). Cirrus is much faster: about 20 minutes. Cirrus also has slightly better test coverage, mainly because it doesn't use SECCOMP. Also, * Fix the Redox CI build. The old Travis configuration didn't actually build for Redox, so we never noticed that Redox can't be built with a stable compiler. Thanks to @coolreader18 for finding this. * Disable the udp_offload tests on cross-tested platforms. These tests are failing with ENOPROTOOPT in Cirrus-CI. I suspect it's due to a lack of support in QEMU. These tests were skipped on Travis because its kernel was too old. * Fix require_kernel_version on Cirrus-CI. Cirrus reports the Linux kernel version as 4.19.112+, which the semver crate can't handle. * Fix test_setfsuid on Cirrus. When run on Cirrus, it seems like the file in /tmp gets deleted as soon as it's closed. Probably an overzealous temporary file cleaner. Use /var/tmp, because no temporary file cleaner should run in there. * Skip mount tests on Cirrus. They fail for an unknown reason. Issue #1351 * Skip the AF_ALG tests on Cirrus-CI Issue #1352
2020-09-20Mark nix::unistd::fork as unsafe.Vitaly _Vi Shukela
Fix tests. No change in documentation. Resolves #1030.
2020-08-22Merge branch 'master' into musl_seekAlan Somers
2020-08-22Expose SeekData and SeekHole on all Linux targetsAmanieu d'Antras
These were previously missing on musl and mips targets because of missing definitions in the libc crate.
2020-07-28Allow both &[CString] and &[&CStr] for sequence argsJeong YunWon
2020-07-03implement ttynameJesse Luehrs
2020-06-27misc clippy cleanupAlan Somers
2020-06-12Merge #1255bors[bot]
1255: Remove several deprecated constants and functions r=asomers a=asomers * `unistd::daemon` on Apple * `unistd::pipe2` on Apple * `sys::event::FilterFlag::NOTE_EXIT_REPARENTED` on Apple * `sys::event::FilterFlag::NOTE_REAP` on Apple * `sys::ptrace::ptrace` on Android and Linux All have been deprecated for more than two releases and one year. Co-authored-by: Alan Somers <asomers@gmail.com>
2020-06-12Add fchown(2) wrapper.Nate Avers
2020-06-04Remove several deprecated constants and functionsAlan Somers
* `unistd::daemon` on Apple * `unistd::pipe2` on Apple * `sys::event::FilterFlag::NOTE_EXIT_REPARENTED` on Apple * `sys::event::FilterFlag::NOTE_REAP` on Apple * `sys::ptrace::ptrace` on Android and Linux All have been deprecated for more than two releases and one year.
2020-05-31fixup to "Convert the crate to edition 2018"Alan Somers
2020-05-31Convert the crate to edition 2018Alan Somers
2020-05-17Fix test and remove group & user for redoxXavier L'Heureux
- Make sure all tests pass the CI - Redox does not (yet) have passwd functions, so remove it
2020-05-17Add wait, fdatasync, poll and pause for RedoxXavier L'Heureux
2020-05-17Disable mkfifo for RedoxXavier L'Heureux
FIFOs are not supported (yet?) by RedoxFS, so disable it
2020-05-17Remove more unsupported functions and make it possible to run testsXavier L'Heureux
2020-05-17Add Redox support for most of the modulesXavier L'Heureux
Some things are not implemented yet in redox, so a lot of annotations were added to remove functions when compiling for redox. Those functions will hopefully be added in time, but for now it's better to have partial support than none. Blocked by https://github.com/rust-lang/libc/pull/1438
2020-05-17Replace void crate with Rust standard lib Infallible typeOssi Herrala
std::convert::Infallible has been available since Rust 1.34 and nix currently targets Rust 1.36 or later so this should not cause problems. Fixes #1238
2020-05-15Document additional OS-specific flags for pipe2Harm Berntsen
See https://netbsd.gw.com/cgi-bin/man-cgi?pipe2+2+NetBSD-current and http://man7.org/linux/man-pages/man2/pipe.2.html
2020-04-06unistd: avoid infinite loop caused by reserve_double_buffer_sizeSteven Danna
Functions such as Group::from_anything use reserve_double_buffer_size in a loop, expecting it to return ERANGE if the passed limit is reached. However, the returned vector is passed as pointer to a libc function that writes data into memory and doesn't update the length of the Vec. Because of this, the previous code would never return ERANGE and the calling loops would never exit if they hit a case where the required buffer was larger than the maximum buffer. This fixes the problem by checking the capacity rather than the length. Signed-off-by: Steven Danna <steve@chef.io>
2020-03-03Derive `Ord`, `PartialOrd` for `Pid`Joe Ranweiler
2020-02-29add setfsuid and setfsgid implementation for filesystem checksMarco Conte
2020-01-12Add CLK_TCK to SysconfVarCaleb Bassi
http://man7.org/linux/man-pages/man3/sysconf.3.html says that the corresponding variable is obsolete, but I think that just means the constant defined in limits.h is obsolete. Checking the value using sysconf is still valid.
2019-11-03Implment linkatJohnnie Birch
This adds the linkat function which is part of POSIX: http://pubs.opengroup.org/onlinepubs/9699919799/functions/linkat.html and widely implmented on Unix-Family platforms. Add back trailing whitespace removed on previous force push
2019-10-30Add `Users` and `Group` related functionsOtavio Salvador
This was a collaborative work between Johannes Schilling <dario@deaktualisierung.org>, Fredrick Brennan <copypaste@kittens.ph> and myself. Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
2019-10-21fix documentation typo for effective gidScott Schroeder
2019-09-30refactored test casesZhang Miaolei
ignore mkfifoat in OSX and andriod
2019-09-30add mkfifoatZhang Miaolei
2019-09-28Merge #1121 #1130bors[bot]
1121: Fix #1093 r=asomers a=tathanhdinh Hello, This PR fixes the problem discovered in #1093. Thanks for any comment. 1130: unistd: getgrouplist: Rework code to use `reserve_double_buffer_size` r=asomers a=otavio The buffer resize logic can be simplified reusing the `reserve_double_buffer_size` method. Signed-off-by: Otavio Salvador <otavio@ossystems.com.br> Co-authored-by: Ta Thanh Dinh <tathanhdinh@gmail.com> Co-authored-by: Otavio Salvador <otavio@ossystems.com.br>
2019-09-25unistd: getgrouplist: Rework code to use `reserve_double_buffer_size`Otavio Salvador
The buffer resize logic can be simplified reusing the `reserve_double_buffer_size` method. Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
2019-09-25unistd: getgroups: Resize buffer up to NGROUPS_MAXOtavio Salvador
Use `reserve_double_buffer_size` up to NGROUPS_MAX as limit. Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
2019-09-25unistd: getgroups: Rework variable namesOtavio Salvador
We are preparing the use of `reserve_double_buffer_size` but for this, some logic need to be reworked so we are doing some rename preparing for the next patch which adds its use. Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>