Commit Graph

495 Commits

Author SHA1 Message Date
eaon
76fe409f4b
Support for TCP_MAXSEG TCP MSS socket option 2021-09-04 22:39:55 -04:00
Alan Somers
f3cb6b321f Fix building the tests for Redox and Illumos
Also, split the overbroad test_mknod_family into two tests
2021-08-22 10:31:39 -06:00
Noah
c96141d423
Deprecate SockAddr/InetAddr::to_str 2021-08-21 16:59:35 -05:00
Kyle Huey
d133d3db76 Relax assertions in sockaddr_storage_to_addr to match the documentation.
Fixes #1479
2021-08-17 19:26:12 -07:00
bors[bot]
06b5d3344a
Merge #1482
1482: Add support for LOCAL_PEER_CRED r=asomers a=asomers

On FreeBSD and its derivatives, this socket option gets the credentials
of the connected peer.

Co-authored-by: Alan Somers <asomers@gmail.com>
2021-08-11 00:39:47 +00:00
Alan Somers
0d3bc089d5 Add support for LOCAL_PEER_CRED
On FreeBSD and its derivatives, this socket option gets the credentials
of the connected peer.
2021-08-10 17:57:32 -06:00
Mika Vatanen
1cbde2bb47 Add PTRACE_INTERRUPT 2021-08-09 20:29:44 +03:00
LMJW
cd004aa861 Add getrlimit and setrlimit
This work is a continutation on previou contribution by @kpcyrd and @j1ah0ng.
2021-08-01 10:23:00 +10:00
Luca BRUNO
6e2158bc71
sys/stat: add a safe wrapper for mknodat(2)
This introduces a new `mknodat` helper.

Ref: https://pubs.opengroup.org/onlinepubs/9699919799/functions/mknod.html
2021-07-28 12:36:59 +00:00
orvij
3f6151ebbe
unistd: Add conversion from User to libc::passwd
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-24 23:52:56 +00:00
Martin Kröning
3d5d369665 Add pthread_kill 2021-07-24 22:45:46 +02:00
Junho Choi
0b596a11e0 Support SO_RXQ_OVFL socket option (android/fuchsia/linux)
This PR implements support of RXQ_OVFL flag and parsing ControlMessage
to get the packet drop counter of UDP socket.
2021-07-08 16:00:39 -07:00
Tom Boland
1a23312c77 Adding linux specific renameat2() 2021-07-08 22:08:48 +01:00
Alan Somers
2d796eba38 Collapse Error into Errno
Now that Nix's weird error types are eliminated, there's no reason not
to simply use Errno as the Error type.
2021-07-07 20:49:29 -06:00
Alan Somers
6511d02414 Overhaul Nix's error types
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-07-07 20:49:28 -06:00
Alan Somers
48c7a07c42 Add nmount for FreeBSD. 2021-06-13 20:13:32 -06:00
Alan Somers
221eac1e8f Reenable tests that only failed on Travis, since we no longer use it. 2021-06-12 17:22:51 -06:00
Alan Somers
3405a7c374 Fix some unused import warnings in the tests 2021-06-12 16:58:02 -06:00
Jeryl Vaz
b481a0eb2f Add getresuid() and getresgid() to unistd 2021-05-31 16:17:50 +02:00
Alan Somers
7b7d954005 misc Clippy cleanup
* 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-30 20:12:41 -06:00
Alan Somers
5ac876e17d Adapt aio to the world of async/await, and fix some potential unsoundness.
* libc::aiocb must not be moved while the kernel has a pointer to it.
  This change enforces that requirement by using std::pin.

* Split LioCbBuilder out of LioCb.  struct LioCb relied on the
  (incorrect) assumption that a Vec's elements have a stable location in
  memory.  That's not true; they can be moved during Vec::push.  The
  solution is to use a Vec in the new Builder struct, but finalize it to
  a boxed slice (which doesn't support push) before allowing it to be
  submitted to the kernel.

* Eliminate owned buffer types.  mio-aio no longer uses owned buffers
  with nix::aio.  There's little need for it in the world of
  async/await.  I'm not aware of any other consumers.  This
  substantially simplifies the code.
2021-05-30 17:41:47 -06:00
bors[bot]
df9ed9314d
Merge #1439
1439: Add sendfile64 r=asomers a=tdryer

`sendfile64` is a Linux-specific call with a wider type for the `offset` argument than `sendfile`.

This is largely a copy of the existing `sendfile` function and associated test.

Co-authored-by: Tom Dryer <tomdryer.com@gmail.com>
2021-05-30 16:26:41 +00:00
Tom Dryer
65ab8d7fca Disable sendfile64 on android
It's not available from libc on that platform.
2021-05-28 16:04:44 -07:00
Tom Dryer
81c9e2d9a8 Add sendfile64
`sendfile64` is a Linux-specific call with a wider type for the `offset`
argument than `sendfile`.

This is largely a copy of the existing `sendfile` function and
associated test.
2021-05-28 15:01:42 -07:00
David Tolnay
acde3fe5c8
Update to semver 1.0.0 2021-05-27 11:17:17 -07:00
Alan Somers
468dc73cb7 Hopefully improve unistd::alarm::set's doc test's reliability 2021-05-01 14:54:46 -06:00
bors[bot]
68d01f0426
Merge #1402
1402: Support TIMESTAMPNS r=asomers a=WiSaGaN

This adds support of linux TIMESTAMPNS.
The code is mostly copied paste from https://github.com/nix-rust/nix/pull/663

Co-authored-by: Lu, Wangshan <wisagan@gmail.com>
2021-04-08 03:53:56 +00:00
Lu, Wangshan
830bab64a8
Support TIMESTAMPNS for linux 2021-04-08 10:41:38 +08:00
Alan Somers
2ba6999e2e Check all tests in CI
Travis didn't compile check tests on platforms that couldn't run tests
in CI, so they bitrotted.  Let's see how bad they are.

Most annoyingly, 32-bit Android defines mode_t as 16 bits, but
stat.st_mode as 32-bits.
2021-04-04 19:32:54 -06:00
Stefano Garzarella
5d17a60aa0 Revert "Temporarily disable test_vsock on QEMU arches"
This reverts commit c0783e7f8d.

Now the test should work correctly, so we can re-enable it.

Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
2021-03-22 09:53:14 +01:00
Stefano Garzarella
532e238d5e Fix test_vsock failure on VMADDR_CID_LOCAL testing
Starting from Linux 5.6, VMADDR_CID_LOCAL is supported to do local
communication (loopback device).

Before Linux 5.6 it was called VMADDR_CID_RESERVED and was not
supported, so we could expect an EADDRNOTAVAIL, but now this address
is supported and handled by the 'vsock_loopback' kernel module loaded
automatically if no other vsock transports are loaded.

Issue #1310
Issue #1403

Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
2021-03-22 09:51:50 +01:00
Jason King
d444f1bcf2 illumos and Solaris support
Co-authored-by: Dominik Hassler <hadfl@omnios.org>
Co-authored-by: Joshua M. Clulow <josh@sysmgr.org>
2021-03-21 23:04:03 +00:00
Alan Somers
c0783e7f8d Temporarily disable test_vsock on QEMU arches
Issue #1403
2021-03-21 16:17:49 -06:00
bors[bot]
7704f5d5d7
Merge #1390
1390: pty: Make forkpty() unsafe r=asomers a=tavianator

After the child returns from a fork() of a multi-threaded process, it is
undefined behaviour to call non-async-signal-safe functions according to
POSIX.  Since forkpty() is implemented in terms of fork(), those
restrictions should apply to it too.

Fixes #1388

Co-authored-by: Tavian Barnes <tavianator@tavianator.com>
2021-02-21 00:08:45 +00:00
Tavian Barnes
c6c851403b pty: Make forkpty() unsafe
After the child returns from a fork() of a multi-threaded process, it is
undefined behaviour to call non-async-signal-safe functions according to
POSIX.  Since forkpty() is implemented in terms of fork(), those
restrictions should apply to it too.
2021-02-20 19:06:08 -05:00
Alan Somers
04504295a6 Update rand to 0.8
This eliminates some duplicate dependencies
2021-02-20 14:56:36 -07:00
Alan Somers
7c755e6025 Fix a non_fmt_panic warning with Rustc 1.52.0 2021-02-20 14:49:12 -07:00
наб
59c18e2c2f
Fix test_ptrace_syscall() on x32
Based on
https://github.com/nix-rust/nix/issues/1384#issuecomment-774708486
2021-02-15 18:59:48 +01:00
наб
2abfdb4123
Port mqueue to x32
Test fix obtained from
https://github.com/nix-rust/nix/issues/1384#issuecomment-774708486
2021-02-15 18:59:46 +01:00
William Manley
91c2a080ea Dir: Implement IntoIterator for Dir
This is useful to allow returning an iterator based on a directory iterator
without needing a self-referential struct.
2021-02-15 13:48:17 +00:00
Alexander Thaller
d965259685 Fix fcntl for FreeBSD
Need to use the right cfg option for the conditional compilation.
target_os is the right option to use when targeting FreeBSD. target_env
was used before which seems to be a typo.
2021-01-03 00:41:45 +01:00
William Woodruff
7c3a3535fc
unistd: Add getpeereid(3)
Closes #1339.
2020-12-19 22:52:16 -05:00
Amanda Tait
5846ae2afd
Add fuchsia support
Allow nix to compile on Fuchsia by conditionally avoiding libc
functionality that does not exist for Fuchsia.
2020-12-19 14:17:42 -05:00
Alan Somers
d87e6b2820 Ignore failures of test_aio_suspend on macos
On Cirrus-CI, this test frequently fails with EINVAL.  The error goes
away if I add a line of debugging, so it's probably a timing issue.  But
I can't debug it myself.

Issue #1361
2020-12-14 19:37:53 -07:00
Alan Somers
668384e94f Remove a workaround for an old Musl bug
In older versions of Musl, ttyname_r would wrongly return ENOTTY instead
of EBADF.  We expected that bug in our test suite.  But Rust
1.37.0 updated Musl to 1.1.22, which fixes the problem.  This change
reverts our workaround.

https://www.openwall.com/lists/musl/2018/09/15/2
aaf6698793
2020-12-10 19:52:39 -07:00
Alan Somers
da204cf4a7 Ignore the execve tests on musl
On Cirrus-CI, these tests frequently segfault.  It's probably indicative
of a real bug, not just a problem in the tests.  But for now we need to
skip them to get CI working.

Issue #555
2020-12-09 19:35:02 -07:00
Alan Somers
b50a92b0c9 Fix unreliability in sys::test_aio::test_aio_suspend
On OSX, this test has begun to fail in CI on OSX.  Presumably it's because
aio_suspend was getting interrupted by a signal.
2020-12-08 20:36:19 -07:00
Alan Somers
1c757c78ba Fix a race in the test_unistd::test_fchown test
The test was assuming that once dropped, a temporary file's file
descriptor would be invalid.  But it might not be, because another file
might be opened with the same file descriptor.  Instead, use an
obviously invalid file descriptor.
2020-12-08 19:37:50 -07:00
Alan Somers
4a84e0c4d4 Fix a use-after-free in execve_test_factory
Ensure that the exec functions' arguments are valid for 'static.
Previously they were short-lived temporaries.
2020-12-07 21:01:40 -07:00
Alan Somers
bf7a5fd606 Switch all builds from Travis to Cirrus
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-12-06 22:35:30 -07:00