1748: Add format test to CI r=rtzoeller a=costinsin
To enforce uniformity for all PRs, the CI checks if the code
is formatted right using `cargo fmt` tool.
Results after implementing the format test in CicleCI, but before fixing the format errors: https://cirrus-ci.com/build/4684991404703744
Results after fixing the format errors: https://cirrus-ci.com/build/5423803479097344
Solves #770
Co-authored-by: Costin-Robert Sin <sin.costinrobert@gmail.com>
To enforce uniformity for all PRs, the CI checks if the code
is formatted rigth using `cargo fmt` tool.
Signed-off-by: Costin-Robert Sin <sin.costinrobert@gmail.com>
1747: Add getrusage wrapper r=rtzoeller a=kov
Includes an enum to specify what to get resource usage for, and a new
struct that provides a more readable view into libc::rusage, including
using TimeVal for user and system CPU time.
Signed-off-by: Gustavo Noronha Silva <gustavo@noronha.dev.br>
Co-authored-by: Gustavo Noronha Silva <gustavo@noronha.dev.br>
Includes an enum to specify what to get resource usage for, and a new
struct that provides a more readable view into libc::rusage, including
using TimeVal for user and system CPU time.
1746: Fix typo and minimise the use of `unsafe` blocks inside the `pipe` function r=rtzoeller a=costinsin
Some of the operations inside the pipe function are safe and should not be included inside an unsafe block.
Co-authored-by: Costin-Robert Sin <sin.costinrobert@gmail.com>
Some of the operations inside the pipe function are safe and should
not be included inside an unsafe block.
Signed-off-by: Costin-Robert Sin <sin.costinrobert@gmail.com>
1739: ppoll: make sigmask parameter optional r=rtzoeller a=stefano-garzarella
ppoll(2) supports 'sigmask' as NULL. In that case no signal mask
manipulation is performed.
Let's make `sigmask` parameter of `nix::poll::ppoll` optional
to allow that behaviour.
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
Co-authored-by: Stefano Garzarella <sgarzare@redhat.com>
ppoll(2) supports 'sigmask' as NULL. In that case no signal mask
manipulation is performed.
Let's make `sigmask` parameter of `nix::poll::ppoll` optional
to allow that behaviour.
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
1736: Fix socket address family checks r=rtzoeller a=qwandor
The `SockaddrLike::from_raw` implementations for `VsockAddr` and `SysControlAddr` were checking against the wrong address family constant. This PR makes them consistent with the values matched against in `SockaddrStorage::from_raw`.
Co-authored-by: Andrew Walbran <qwandor@google.com>
1735: Cleanup cfg blocks r=asomers a=rtzoeller
Remove obsolete references to target_env = wasi, target_os = nacl, target_os = osx, and a typo'd target_os = fushsia that didn't compile when fixed.
- target_env = wasi is dead: https://github.com/rust-lang/rust/pull/60117
- target_os = nacl is dead: https://github.com/rust-lang/rust/pull/45041
- target_os = osx is dead, but I can't find a link.
Found while exploring `--check-cfg`, as mentioned in #1734.
Co-authored-by: Ryan Zoeller <rtzoeller@rtzoeller.com>
1737: Fix the test_acct test r=rtzoeller a=asomers
It has never actually executed its command, so the only reason that it
ever worked is that on most systems there are usually processes starting
and exiting all the time.
Co-authored-by: Alan Somers <asomers@gmail.com>
It has never actually executed its command, so the only reason that it
ever worked is that on most systems there are usually processes starting
and exiting all the time.
1729: Enable SockaddrStorage::{as_link_addr, as_link_addr_mut} on Linux. r=rtzoeller a=asomers
This was an oversight from #1684.
Fixes#1728
Co-authored-by: Alan Somers <asomers@gmail.com>
1730: Ignore doctests for unexported macros r=asomers a=zombiepigdragon
Due to rust-lang/rust#97030, cargo test will fail to doctest macros unless they are exported, breaking the examples for `libc_bitflags!` and `libc_enum!`.
Adds `ignore` to the examples for these macros to stop tests from failing.
`cargo test` already fails on cargo 1.62.0-beta.2, and the above issue makes it seem unlikely that this will be changed on the Rust side. If rust-lang/rust#96630 *does* get reverted, this PR can be closed/unmerged, although the test wasn't running beforehand, and it might be worth making this explicit regardless.
Co-authored-by: Alex Rawson <ajzecrom@gmail.com>
Due to rust-lang/rust#97030, cargo test will fail to doctest macros
unless they are exported, breaking the examples for libc_bitflags! and
libc_enum!.
Adds `ignore` to the examples for these macros to stop tests from
failing.
1727: Add From<uid_t> and From<gid_t> r=rtzoeller a=vkkoskie
Conversions to/from primitive uid_t and gid_t to newtype Uid and Gid types are valid and infallible, but are only implemented in one direction. This provides the counterparts in the other direction.
These conversions are identical in behavior to the from_raw methods. However, using the more idiomatic From trait enables easier interoperability with other crates (e.g., deserialization with serde)
Co-authored-by: Keith Koskie <vkkoskie@gmail.com>
1722: Fix nightly clippy in tests r=asomers a=rtzoeller
`cargo +nightly clippy --tests` currently produces
```
warning: this let-binding has unit value
--> test/sys/test_uio.rs:256:20
|
256 | loop { let _ = pause(); }
| ^^^^^^^^^^^^^^^^ help: omit the `let` binding: `pause();`
|
= note: `#[warn(clippy::let_unit_value)]` on by default
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#let_unit_value
```
Co-authored-by: Ryan Zoeller <rtzoeller@rtzoeller.com>
1703: add haiku support r=rtzoeller a=hoanga
hello,
the following changeset(s) adds support for compiling on haiku.
below is an sample run showing compilation
```sh
> uname -a
Haiku shredder 1 hrev56040 Apr 22 2022 06:24:48 x86_64 x86_64 Haiku
> cargo build
Compiling autocfg v1.1.0
Compiling libc v0.2.123
Compiling bitflags v1.3.2
Compiling cfg-if v1.0.0
Compiling memoffset v0.6.5
Compiling nix v0.24.1 (/boot/home/src/git/rust-libs/nix)
Finished dev [unoptimized + debuginfo] target(s) in 11.09s
```
and some results from running ```cargo test```:
```sh
running 32 tests
test sys::select::tests::fdset_clear ... ok
test sys::select::tests::fdset_insert ... ok
test sys::select::tests::fdset_highest ... ok
test sys::select::tests::fdset_fds ... ok
test sys::select::tests::fdset_remove ... ok
test sys::signal::tests::test_clear ... ok
test sys::select::tests::test_select ... ok
test sys::select::tests::test_select_nfds2 ... ok
test sys::signal::tests::test_contains ... ok
test sys::select::tests::test_select_nfds ... ok
test sys::signal::tests::test_extend ... ok
test sys::signal::tests::test_from_and_into_iterator ... ok
test sys::signal::tests::test_from_str_invalid_value ... ok
test sys::signal::tests::test_from_str_round_trips ... ok
test sys::signal::tests::test_sigaction ... ok
test sys::signal::tests::test_sigwait ... ok
test sys::signal::tests::test_thread_signal_set_mask ... ok
test sys::statvfs::test::fstatvfs_call ... ok
test sys::statvfs::test::statvfs_call ... ok
test sys::termios::test::try_from ... ok
test sys::signal::tests::test_thread_signal_swap ... ok
test sys::signal::tests::test_thread_signal_block ... ok
test sys::signal::tests::test_thread_signal_unblock ... ok
test sys::time::test::test_timespec ... ok
test sys::time::test::test_timespec_from ... ok
test sys::time::test::test_timespec_neg ... ok
test sys::time::test::test_timespec_fmt ... ok
test sys::time::test::test_timespec_ord ... ok
test sys::time::test::test_timeval ... ok
test sys::time::test::test_timeval_neg ... ok
test sys::time::test::test_timeval_fmt ... ok
test sys::time::test::test_timeval_ord ... ok
test result: ok. 32 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
Running test/test.rs (target/debug/deps/test-6e8a70ba3d8f7447)
running 73 tests
test sys::test_pthread::test_pthread_kill_none ... ok
test sys::test_pthread::test_pthread_self ... ok
test sys::test_select::test_pselect_nfds2 ... ok
test sys::test_select::test_pselect ... ok
test sys::test_signal::test_kill_none ... ok
test sys::test_signal::test_killpg_none ... ok
test sys::test_signal::test_old_sigaction_flags ... ok
test sys::test_signal::test_signal ... ok
test sys::test_signal::test_sigprocmask ... ok
test sys::test_signal::test_signal_sigaction ... ok
test sys::test_signal::test_sigprocmask_noop ... ok
test sys::test_select::test_fdset_negative_fd::contains - should panic ... ok
test sys::test_select::test_fdset_negative_fd::remove - should panic ... ok
test sys::test_select::test_fdset_negative_fd::insert - should panic ... ok
test sys::test_select::test_fdset_too_large_fd::contains - should panic ... ok
test sys::test_select::test_fdset_too_large_fd::insert - should panic ... ok
test sys::test_select::test_fdset_too_large_fd::remove - should panic ... ok
test sys::test_wait::test_wait_exit ... ok
test sys::test_wait::test_waitid_pid ... ok
test sys::test_uio::test_readv ... ok
test sys::test_wait::test_waitstatus_from_raw ... FAILED
test sys::test_wait::test_waitstatus_pid ... ok
test sys::test_uio::test_writev ... ok
test test_net::test_if_nametoindex ... ok
test test_dir::rewind ... ok
test test_poll::test_pollfd_events ... ok
test test_poll::test_pollfd_fd ... ok
test sys::test_uio::test_pwrite ... ok
test sys::test_uio::test_pread ... ok
test test_fcntl::test_readlink ... ok
test test_fcntl::test_openat ... ok
test test_dir::read ... ok
test test_stat::test_fstatat ... ok
test test_stat::test_mkdirat_fail ... ok
test test_time::test_clock_gettime ... ok
test test_stat::test_fchmod ... ok
test test_stat::test_fchmodat ... ok
test test_time::test_clock_id_now ... ok
test test_fcntl::test_renameat ... ok
test test_stat::test_mkdirat_success_path ... ok
test test_stat::test_stat_and_fstat ... ok
test test_unistd::test_execvpe::test_cstr_ref ... ok
test test_unistd::test_access_not_existing ... ok
test test_unistd::test_execvpe::test_cstring ... ok
test test_unistd::test_access_file_exists ... ok
test test_stat::test_stat_fstat_lstat ... ok
test test_unistd::test_fchdir ... ok
test test_unistd::test_fork_and_waitpid ... ok
test test_unistd::test_fchown ... ok
test test_unistd::test_chown ... ok
test test_unistd::test_getpid ... ok
test test_unistd::test_getsid ... ok
test test_unistd::test_fpathconf_limited ... ok
test test_unistd::test_lseek ... ok
test test_unistd::test_mkfifo_directory ... ok
test test_unistd::test_fchownat ... ok
test test_unistd::test_mkstemp_directory ... ok
test test_unistd::test_pathconf_limited ... ok
test test_unistd::test_pipe ... ok
test test_unistd::test_sysconf_limited ... ok
test test_unistd::test_mkfifo ... ok
test test_unistd::test_ttyname_not_pty ... ok
test test_unistd::test_ftruncate ... ok
test test_unistd::test_mkstemp ... ok
test test_poll::test_poll ... ok
test test_unistd::test_wait ... ok
test test_unistd::test_unlinkat_dir_removedir ... ok
test test_unistd::test_unlinkat_file ... ok
test test_unistd::test_unlinkat_dir_noremovedir ... ok
test test_unistd::test_truncate ... ok
test test_unistd::test_getcwd ... ok
test test_unistd::test_alarm ... ok
test test_unistd::test_canceling_alarm ... ok
failures:
---- sys::test_wait::test_waitstatus_from_raw stdout ----
thread 'sys::test_wait::test_waitstatus_from_raw' panicked at 'assertion failed: `(left == right)`
left: `Ok(Exited(Pid(1), 2))`,
right: `Ok(Signaled(Pid(1), SIGINT, false))`', test/sys/test_wait.rs:93:5
failures:
sys::test_wait::test_waitstatus_from_raw
test result: FAILED. 72 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 1.06s
error: test failed, to rerun pass '--test test'
```
Co-authored-by: Al Hoang <3811822-hoanga@users.noreply.gitlab.com>
1713: Rewrite the aio module r=rtzoeller a=asomers
The existing AIO implementation has some problems:
1) The in_progress field is checked at runtime, not compile time.
2) The mutable field is checked at runtime, not compile time.
4) A downstream lio_listio user must store extra state to track whether
the whole operation is partially, completely, or not at all
submitted.
4) Nix does heap allocation itself, rather than allowing the caller to
choose it. This can result in double (or triple, or quadruple)
boxing.
5) There's no easy way to use lio_listio to submit multiple operations with
a single syscall, but poll each individually.
6) The lio_listio usage is far from transparent and zero-cost.
7) No aio_readv or aio_writev support.
8) priority has type c_int; should be i32
9) aio_return should return a usize instead of an isize, since it only
uses negative values to indicate errors, which Rust represents via
the Result type.
This rewrite solves several problems:
1) Unsolved. I don't think it can be solved without something like
C++'s guaranteed type elision. It might require changing the
signature of Future::poll too.
2) Solved.
3) Solved, by the new in_progress method and by removing the complicated
lio_listio resubmit code.
4) Solved.
5) Solved.
6) Solved, by removing the lio_listo resubmit code. It can be
reimplemented downstream if necessary. Or even in Nix, but it
doesn't fit Nix's theme of zero-cost abstractions.
7) Solved.
8) Solved.
9) Solved.
Co-authored-by: Alan Somers <asomers@gmail.com>
The existing AIO implementation has some problems:
1) The in_progress field is checked at runtime, not compile time.
2) The mutable field is checked at runtime, not compile time.
3) A downstream lio_listio user must store extra state to track whether
the whole operation is partially, completely, or not at all
submitted.
4) Nix does heap allocation itself, rather than allowing the caller to
choose it. This can result in double (or triple, or quadruple)
boxing.
5) There's no easy way to use lio_listio to submit multiple operations with
a single syscall, but poll each individually.
6) The lio_listio usage is far from transparent and zero-cost.
7) No aio_readv or aio_writev support.
8) priority has type c_int; should be i32
9) aio_return should return a usize instead of an isize, since it only
uses negative values to indicate errors, which Rust represents via
the Result type.
This rewrite solves several problems:
1) Unsolved. I don't think it can be solved without something like
C++'s guaranteed type elision. It might require changing the
signature of Future::poll too.
2) Solved.
3) Solved, by the new in_progress method and by removing the complicated
lio_listio resubmit code.
4) Solved.
5) Solved.
6) Solved, by removing the lio_listo resubmit code. It can be
reimplemented downstream if necessary. Or even in Nix, but it
doesn't fit Nix's theme of zero-cost abstractions.
7) Solved.
8) Solved.
9) Solved.
The rewrite includes functions that don't work on FreeBSD, so add CI
testing for FreeBSD 14 too.
By default only enable tests that will pass on FreeBSD 12.3. But run a
CI job on FreeBSD 14 and set a flag that will enable such tests.
1720: Fix a warning on Redox with the latest nightly compiler. r=rtzoeller a=asomers
It just so happens that Redox doesn't use any of the libc_enum entries
that aren't followed by a comma.
Co-authored-by: Alan Somers <asomers@gmail.com>
1699: Revert "Pin nightly compiler used in CI for uclibc" r=rtzoeller a=asomers
This reverts commit 23f18dfc18.
libc v0.2.124 fixes the problem.
Co-authored-by: Alan Somers <asomers@gmail.com>
1716: Future-proof the kevent ABI r=rtzoeller a=asomers
FreeBSD 12 changes struct kevent. For now, libc always binds to the
11-compat ABI. But that will change some day. Adjust Nix's code to
build with either struct definition.
Co-authored-by: Alan Somers <asomers@gmail.com>
1717: Define FsType constants for musl r=asomers a=jirutka
These constants are provided by Linux (linux/magic.h), not libc.
See rust-lang/libc#2639.
Co-authored-by: Jakub Jirutka <jakub@jirutka.cz>
FreeBSD 12 changes struct kevent. For now, libc always binds to the
11-compat ABI. But that will change some day. Adjust Nix's code to
build with either struct definition.