Commit Graph

2569 Commits

Author SHA1 Message Date
Ryan Zoeller
d0d48f214b Pin cross to 0.2.1, as 0.2.2 requires Rust 1.58.1 2022-06-25 21:27:15 -05:00
bors[bot]
a45e9f8fe8
Merge #1748
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>
2022-06-24 01:37:55 +00:00
Costin-Robert Sin
3e6cb639f0 Fix all formating problems to pass CI formating test
Signed-off-by: Costin-Robert Sin <sin.costinrobert@gmail.com>
2022-06-24 00:35:52 +03:00
Costin-Robert Sin
8f08a69c28 Add format test to CI
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>
2022-06-24 00:35:31 +03:00
bors[bot]
2c7bb2ab85
Merge #1747
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>
2022-06-21 03:04:36 +00:00
Gustavo Noronha Silva
9313a189d8 Add getrusage wrapper
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.
2022-06-20 22:10:01 -03:00
bors[bot]
b6df05d63e
Merge #1746
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>
2022-06-19 01:28:28 +00:00
Costin-Robert Sin
a240d82880 Minimise the use of the unsafe block inside pipe function
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>
2022-06-19 02:52:08 +03:00
Costin-Robert Sin
6755205782 Fix typo by adding a semicolon
Signed-off-by: Costin-Robert Sin <sin.costinrobert@gmail.com>
2022-06-19 02:49:07 +03:00
bors[bot]
01a5927e2c
Merge #1739
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>
2022-06-09 11:31:52 +00:00
Stefano Garzarella
c3081e4896 ppoll: make sigmask parameter optional
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>
2022-06-09 09:09:23 +02:00
bors[bot]
b3ba2b5f63
Merge #1736
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>
2022-06-09 04:26:59 +00:00
bors[bot]
32d597bbd6
Merge #1735
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>
2022-06-09 03:52:06 +00:00
bors[bot]
649430f990
Merge #1737
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>
2022-06-09 03:29:21 +00:00
Alan Somers
c8a9cf3351 Fix the test_acct test
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.
2022-06-07 20:10:46 -06:00
Andrew Walbran
ccf1b80455 Mention fix in changelog. 2022-06-07 16:22:03 +01:00
Andrew Walbran
d3cc30c3da Fix socket address family check for SysControlAddr::from_raw. 2022-06-07 15:52:49 +01:00
Andrew Walbran
5a122f83a0 Fix socket address family check for VsockAddr::from_raw. 2022-06-07 15:52:03 +01:00
Ryan Zoeller
80f8320ffd Cleanup cfg blocks
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.
2022-06-06 18:50:19 -05:00
bors[bot]
5dedbc7850
Merge #1729
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>
2022-05-31 23:57:45 +00:00
bors[bot]
b53dfa87c3
Merge #1730
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>
2022-05-31 23:36:31 +00:00
Alex Rawson
0ac338b744 Ignore doctests for unexported macros
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.
2022-05-31 17:51:45 -05:00
Alan Somers
1520d7b316 Enable SockaddrStorage::{as_link_addr, as_link_addr_mut} on Linux.
This was an oversight from #1684.

Fixes #1728
2022-05-31 10:42:35 -06:00
bors[bot]
7e8757f4df
Merge #1727
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>
2022-05-30 22:36:43 +00:00
Keith Koskie
51f1ef33a4 Add infallible conversion from uid_t and gid_t
Implements the following traits:
* From<uid_t> for Uid
* From<gid_t> for Gid
2022-05-30 18:28:56 -04:00
bors[bot]
e3932c466f
Merge #1725
1725: Use released libc version 0.2.126 r=rtzoeller a=asomers



Co-authored-by: Alan Somers <asomers@gmail.com>
2022-05-30 21:20:55 +00:00
bors[bot]
20d2edb706
Merge #1726
1726: Clippy cleanup for latest nightly r=rtzoeller a=asomers



Co-authored-by: Alan Somers <asomers@gmail.com>
2022-05-30 21:04:55 +00:00
Alan Somers
6f1c748938 Clippy cleanup for latest nightly 2022-05-29 14:00:48 -06:00
Alan Somers
06f0446d90 Use released libc version 0.2.126 2022-05-29 13:10:50 -06:00
bors[bot]
b0ab5573ea
Merge #1722
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>
2022-05-16 04:49:20 +00:00
Ryan Zoeller
598925c78f Fix nightly clippy in tests 2022-05-15 23:32:24 -05:00
bors[bot]
6639c59618
Merge #1697
1697: Add ptrace::read_user and ptrace::write_user r=rtzoeller a=nbaksalyar



Co-authored-by: Nikita Baksalyar <nikita.baksalyar@gmail.com>
2022-05-15 23:04:06 +00:00
Nikita Baksalyar
c1c1c6cfe4 Add ptrace::read_user and ptrace::write_user 2022-05-15 23:36:02 +01:00
bors[bot]
1647189816
Merge #1703
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>
2022-05-15 00:20:01 +00:00
Al Hoang
d02e27476c add haiku support
* enabled as much functionality and defines that match
  updated libc definitions for haiku
2022-05-14 18:45:18 -05:00
bors[bot]
69738c0fd0
Merge #1713
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>
2022-05-14 20:17:18 +00:00
Alan Somers
0c07a9e469 Rewrite the aio module
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.
2022-05-14 13:34:11 -06:00
bors[bot]
1c36d49c0b
Merge #1720
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>
2022-05-14 07:04:06 +00:00
Alan Somers
7dff51fbfc Fix "unused_macro_rules" warnings with the latest nightly compiler.
It just so happens that Redox, OpenBSD, Dragonfly, and uclibc don't use
some of the rules for two internal macros.
2022-05-13 21:01:21 -06:00
bors[bot]
6f57f2e11d
Merge #1699
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>
2022-05-11 02:34:14 +00:00
bors[bot]
db41e0b356
Merge #1716
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>
2022-05-09 13:25:37 +00:00
bors[bot]
68f36314e1
Merge #1717
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>
2022-05-07 17:40:43 +00:00
Jakub Jirutka
23f1787d3b Define FsType constants for musl
These constants are provided by Linux (linux/magic.h), not libc.

See rust-lang/libc#2639.
2022-05-07 19:20:35 +02:00
Alan Somers
b4fb5eec7d Future-proof the kevent ABI
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.
2022-05-07 08:12:12 -06:00
bors[bot]
11912bb88e
Merge #1715
1715: Log compiler version in Cirrus CI r=asomers a=rtzoeller



Co-authored-by: Ryan Zoeller <rtzoeller@rtzoeller.com>
2022-05-07 03:25:32 +00:00
Ryan Zoeller
ad7d45a0bf Log compiler version in Cirrus CI 2022-05-06 22:07:05 -05:00
bors[bot]
3109a6dab4
Merge #1711
1711: Restore conversions from ip v4/6 Sockaddr types to std::net equivalents. r=asomers a=khuey

Fixes #1710

Co-authored-by: Kyle Huey <khuey@kylehuey.com>
2022-05-03 03:28:41 +00:00
Kyle Huey
024c0d7dde Restore conversions from ip v4/6 Sockaddr types to std::net equivalents.
Fixes #1710
2022-05-02 08:53:08 -07:00
bors[bot]
4d79e93904
Merge #1712
1712: Create new Unreleased changelog section r=asomers a=rtzoeller



Co-authored-by: Ryan Zoeller <rtzoeller@rtzoeller.com>
2022-04-30 23:48:30 +00:00
Ryan Zoeller
bf2fa038cd Create new Unreleased changelog section 2022-04-30 18:12:39 -05:00