Commit Graph

561 Commits

Author SHA1 Message Date
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
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]
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
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
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
Ryan Zoeller
598925c78f Fix nightly clippy in tests 2022-05-15 23:32:24 -05:00
Nikita Baksalyar
c1c1c6cfe4 Add ptrace::read_user and ptrace::write_user 2022-05-15 23:36:02 +01: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
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
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
Ryan Zoeller
e543733a4c Upgrade sysctl to 0.4
Upgrade sysctl dev-dependency to 0.4 and handle its breaking API changes.
2022-04-24 19:25:16 -05:00
bors[bot]
256707e8c7
Merge #1643
1643: Replace the IoVec struct with IoSlice and IoSliceMut from the standard library r=asomers a=notgull

As per discussion in #1637, the `IoVec<&[u8]>` and `IoVec<&mut [u8]>` types have been replaced with `std::io::IoSlice` and `IoSliceMut`, respectively. Notable changes made in this pull request include:

- The complete replacement of `IoVec` with `IoSlice*` types in both public API, private API, and tests.
- Replacing `IoVec` with `IoSlice` in docs.
- Replacing `&[IoVec<&mut [u8]>]` with `&mut [IoSliceMut]`, note that the slice requires a mutable reference now. This is how it's done in the standard library, and there might be a soundness issue in doing it the other way.

Resolves #1637 

Co-authored-by: not_a_seagull <notaseagull048@gmail.com>
2022-04-08 20:05:41 +00:00
not_a_seagull
0b58f29772 Replace the IoVec type with IoSlice and IoSliceMut 2022-04-08 12:39:16 -07:00
Junho Choi
a4b5dfc059 Add IP_DONTFRAG and IPV6_DONTFRAG SockOpts
IP_DONTFRAG: iOS, macOS
IPV6_DONTFRAG: android, iOS, linux and macOS

Test: `cargo test --test test dontfrag_opts`

Some CI tests running ENOPROTOOPT are disabled (qemu-based).
2022-04-07 17:39:46 -07:00
Jan Bujak
4ae4cfd058 Make uname always safe
This fixes several issues with the current `uname` bindings:

  - Do not ignore `uname` errors; at least on glibc `uname` can fail,
    so now it returns a `Result` instead of assuming that the call
    will always succeed.

  - Do not assume `uname` will initialize every member of `utsname`;
    not every implementation initializes every field, so internally
    the struct is now zero-initialized.

  - Do not blindly assume strings returned by `uname` will always be valid UTF-8;
    `UtsName`'s accessors will now return `&OsStr`s instead of `&str`s.
2022-03-23 14:28:37 +09:00
Alan Somers
fbeabf3730 Deprecate IpAddr, Ipv4Addr, and Ipv6Addr
Because they're redundant with types in the standard library.

Fixes #1681
2022-03-22 21:09:52 -06:00
Alan Somers
76d70b4b25 Replace the Sockaddr enum with a union
The SockAddr enum is quite large, and the user must allocate space for
the whole thing even though he usually knows what type he needs.
Furthermore, thanks to the sa_family field, the sockaddr types are
basically an enum even in C.

So replace the ungainly enum with a SockaddrLike trait implemented by
all sockaddr types and  a SockaddrStorage union that has safe accessors.

Also, deprecate InetAddr, which only existed to support SockAddr.

Supplants #1504
Fixes #1544
2022-03-21 20:50:24 -06:00
Arnavion
cf628ca609
Change getrlimit and setrlimit to use rlim_t directly.
Fixes #1666
2022-03-13 17:33:02 -07:00
Matthias Schiffer
df417e295b
wait: implement waitid()
waitid() has a number of additional features that waitpid() is missing:

- WNOWAIT is only accepted for waitid() on Linux (and possibly other
  platforms)
- Support for waiting on PID file descriptors on Linux

For now support is added for all platforms with waitid() that have proper
siginfo_t support in libc. NetBSD support is currently a work in progress
[1].

Tests for the signal/exit code are currently skipped on MIPS platforms due
to bugs in qemu-user's translation of siginfo_t (fixed in [2] and [3]; the
second fix is not in a released qemu version yet).

[1] https://github.com/rust-lang/libc/pull/2476
[2] https://lists.nongnu.org/archive/html/qemu-devel/2021-01/msg04810.html
[3] https://lists.nongnu.org/archive/html/qemu-devel/2021-10/msg05433.html
2022-03-09 16:56:59 +01:00
Jesse Luehrs
22bb105612 also implement Read and Write for &PtyMaster 2022-02-22 13:08:54 -05:00
Jonah Petri
6c4b9133f1 uclibc support 2022-01-24 10:06:35 -05:00
Alan Somers
475da53d56 Better type safety for mqueue
On some platforms, mqd_t is a pointer.  That means code like the below
can trigger a segfault.  Fix it by defining a Newtype around mqd_t that
prevents use-after-free and dangling pointer scenarios.

```rust
fn invalid_mqd_t() {
    let mqd: libc::mqd_t = std::ptr::null_mut();
    mq_close(mqd).unwrap();
}
```

Also, get test coverage for mqueue in CI on FreeBSD.
2022-01-22 14:48:48 -07:00
bors[bot]
f8e27505f5
Merge #1630
1630: Change port used by test_txtime to avoid conflict r=asomers a=rtzoeller

The socket tests request specific ports, and `test_timestamping` and `test_txtime` are currently conflicting in the port they request.

This leads to the second of the tests failing with `EADDRINUSE` when run locally.

Co-authored-by: Ryan Zoeller <rtzoeller@rtzoeller.com>
2022-01-11 05:15:35 +00:00
Ryan Zoeller
ebd4acebc0 Change port used by test_txtime to avoid conflict 2022-01-10 21:57:55 -06:00
Ryan Zoeller
1b32230831 Add getresuid/gid and setresuid/gid on BSDs 2022-01-10 20:14:34 -06:00
Ryan Zoeller
4d5c090fcf Add sendfile(2) for DragonFly 2022-01-03 04:05:09 -06:00
Ryan Zoeller
b7dd35e9b3 Correct MAP_FIXED documentation for NetBSD
The previous documentation described the default behavior, rather than
the behavior when the flag was set.

Also fix a test which is failing due to passing this flag erroneously.
2022-01-02 16:53:42 -06:00
bors[bot]
c1abab9714
Merge #1624
1624: Fix mq tests on NetBSD and DragonFly r=asomers a=rtzoeller

NetBSD (and DragonFly, which borrows its implementation) include additional flags beyond O_NONBLOCK in MqAttr, such as the flags passed to mq_open(). Modify the mq tests to validate _at least_ the expected flags are set, but don't require strict equality on these platforms.

Verified these tests pass on DragonFly and NetBSD locally.

Co-authored-by: Ryan Zoeller <rtzoeller@rtzoeller.com>
2022-01-02 22:32:19 +00:00
Alan Somers
e5b9b972b2 Fix intermittency in test_timer::alarm_fires
The test was disabling the signal handler before disabling the timer.
Fix intermittent failures by:
* Reversing the cleanup order.
* Sleeping for a while before removing the signal handler, since POSIX
  does not guarantee that timer_delete will clear pending signals.

Also, speed up the timer to make the test suite complete faster.
2022-01-02 15:06:24 -07:00
Ryan Zoeller
58d7c04dfb Fix mq tests on NetBSD and DragonFly
NetBSD (and DragonFly, which borrows its implementation) include
additional flags beyond O_NONBLOCK in MqAttr, such as the flags
passed to mq_open().
2022-01-01 22:44:56 -06:00
Brian L. Troutwine
77febe0e6b
Introduce timer_* support
This commit adds support for the signal timer mechanism in POSIX, the
mirror to timerfd on Linux.

Resolves #1424

Signed-off-by: Brian L. Troutwine <brian@troutwine.us>
2021-12-30 20:40:48 -08:00
Alessandro Ghedini
a9829853df Add support for the SO_TXTIME sockopt and SCM_TXTIME control message 2021-12-29 14:15:54 +00:00
bors[bot]
2043bceb5b
Merge #1596 #1621
1596: Add NetBSD configuration for supported process resources r=asomers a=schctl

In addition to existing resources, NetBSD supports `RLIMIT_MEMLOCK`, `RLIMIT_NPROC` and `RLIMIT_RSS`.

https://man.netbsd.org/setrlimit.2

`RLIMIT_AS` is also supported, but it looks like it was added [after version 5.0](https://mail-index.netbsd.org/tech-kern/2009/03/28/msg004702.html), so I'm not sure if that should be enabled.

1621: Add posix_fallocate on DragonFly r=asomers a=rtzoeller

Enable the existing `posix_fallocate()` tests as they are passing locally.

Co-authored-by: Sachin Cherian <sachinctl@protonmail.com>
Co-authored-by: Ryan Zoeller <rtzoeller@rtzoeller.com>
2021-12-27 18:48:12 +00:00
Ryan Zoeller
1eeccb942e Add posix_fallocate on DragonFly 2021-12-27 02:56:19 -06:00
Ryan Zoeller
57f41a8898 Fix typos 2021-12-26 20:14:50 -06:00
bors[bot]
a392647f45
Merge #1547
1547: feat: Add glibc::SOF_TIMESTAMPING_* support r=asomers a=pacak

Support for kernel and hardware receive timestamps

Co-authored-by: Michael Baikov <manpacket@gmail.com>
2021-12-24 22:20:36 +00:00
Ryan Zoeller
9fe9432181 Disable mknod and mknodat tests on DragonFly 2021-12-24 21:47:39 -06:00
Michael Baikov
9aa61ef975 feat: Add glibc::SOF_TIMESTAMPING_* support 2021-12-23 06:41:30 +08:00
Ryan Zoeller
1fbdd29d45 Enable sched_get/setaffinity on DragonFly BSD 2021-12-22 13:56:16 -06:00
Ryan Zoeller
e5af884251 Recent versions of Android support EPOLLEXCLUSIVE
Enable epoll tests on Android, because they are passing.
2021-12-22 12:59:35 -06:00
Ryan Zoeller
2eb6e88406 DragonFly 6.0 added fexecve(2) 2021-12-21 16:20:48 -06:00
Alan Somers
3c52c56e12 Test preadv and pwritev on more operating systems
This was an oversight from PR #1511
2021-12-14 20:47:29 -07:00
Alan Somers
e7e8abc506 clippy cleanup with the latest nightly 2021-12-11 16:55:15 -07:00
Ryan Zoeller
09bddc3676 Avoid lock poisoning by using parking_lot
parking_lot provides synchronization primitives which aren't
poisoned on panic. This makes it easier to determine which tests
are failing, as a test failure no longer causes all subsequent tests
using that mutex to fail.
2021-11-27 13:50:29 -06:00
taylor.fish
dc80b4cd52 Fix unsoundness in FdSet methods
Ensure file descriptors are nonnegative and less than `FD_SETSIZE`.
(Fixes #1572.)
2021-10-21 21:06:04 -07:00
Haruki Okada
a60703430e Fix return value of posix_fadvise
libc::posix_fadvise returns errnos directly rather than in the errno
variable.
2021-09-28 19:17:48 -06:00
Conrad Meyer
b16e70eebf Fix #411 - Provide accessors for 'events' in PollFd
Test: `cargo test --test test test_pollfd_events`
2021-09-19 17:14:30 -07:00
Alan Somers
f2be3c3fe3 Actually connect the mman tests to the build
This was an oversight from #1306.

Reported-by:	@ocadaruma
2021-09-19 10:11:37 -06:00
Alan Somers
a09b1c8ac6 Clippy cleanup
And this time, start running Clippy in CI
2021-09-19 07:58:15 -06:00