Commit Graph

2509 Commits

Author SHA1 Message Date
Ryan Zoeller
7f5907c78d (cargo-release) version 0.24.0 2022-04-20 21:47:48 -05:00
bors[bot]
bfb290bf2b
Merge #1698
1698: Update FreeBSD CI image to 12.3.  12.2 is EoL. r=rtzoeller a=asomers



Co-authored-by: Alan Somers <asomers@gmail.com>
2022-04-15 01:44:05 +00:00
bors[bot]
f05789cd22
Merge #1694
1694: Use singular number for all feature names r=rtzoeller a=asomers

features => feature
users => user

Neither of these features have yet been included in a release, so it's
ok to rename them.

Co-authored-by: Alan Somers <asomers@gmail.com>
2022-04-15 01:24:59 +00:00
Alan Somers
7497b8a9e5 Update FreeBSD CI image to 12.3. 12.2 is EoL. 2022-04-14 09:31:19 -06:00
Alan Somers
23f18dfc18 Pin nightly compiler used in CI for uclibc
Workaround for https://github.com/rust-lang/rust/issues/95866
2022-04-10 12:40:31 -06:00
Alan Somers
145c240cfa Use singular number for all feature names
features => feature
users => user

Neither of these features have yet been included in a release, so it's
ok to rename them.
2022-04-09 16:32:39 -06: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
bors[bot]
3b786fd718
Merge #1692
1692: Add IP_DONTFRAG and IPV6_DONTFRAG SockOpts r=rtzoeller a=junhochoi

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.

Co-authored-by: Junho Choi <junho.choi@gmail.com>
2022-04-08 03:17:48 +00: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
bors[bot]
131fdf1d3c
Merge #1690
1690: Enable statfs magic constants for target_os = "android" r=rtzoeller a=flxo

The statfs magic constants of file systems types are available on
target_os android and the cfg guard is updated accordingly.

Sync the list of constant with the constants declared in libc.

Fixes #1689

Co-authored-by: Felix Obenhuber <felix@obenhuber.de>
2022-04-07 22:01:14 +00:00
Felix Obenhuber
42f671b1e6 Enable statfs magic constants for target_os = "android"
The statfs magic constants of file systems types are available on
target_os android and the cfg guard is updated accordingly.

Sync the list of constant with the constants declared in libc.

Fixes #1689
2022-03-28 15:19:48 +02:00
bors[bot]
c59a8c8cc6
Merge #1691
1691: [skip ci] edit CHANGELOG formatting prior to 0.24.0 release r=rtzoeller a=asomers



Co-authored-by: Alan Somers <asomers@gmail.com>
2022-03-26 00:55:30 +00:00
Alan Somers
333d03be5d Use the nightly toolchain for Redox
The latest redox-syscall crate requires at least Rust 1.59.0, but they
don't define an MSRV policy.  And the version given in the
rust-toolchain file in the Redox repository doesn't work.  So until they
clarify their MSRV, use nightly.

30f29c3295
2022-03-25 18:09:37 -06:00
Alan Somers
6a1f5452ae [skip ci] edit CHANGELOG formatting prior to 0.24.0 release 2022-03-25 17:02:30 -06:00
bors[bot]
4ccc6c6e69
Merge #1672
1672: Make `uname` always safe r=asomers a=koute

Currently `uname` doesn't check for errors and just blindly assumes that it always succeeds. According to the manpage this function can fail, even though no actual errors are defined:

```
RETURN VALUE
       Upon successful completion, a non-negative value shall be returned.  Otherwise, -1 shall be returned and errno set to indicate the error.

ERRORS
       No errors are defined.

       The following sections are informative.
```

Looking at [the glibc's sources](b92a49359f/posix/uname.c (L29)) we can see that it indeed could fail if the internal `gethostname` call fails for some reason.

This code also assumes that every field of `utsname` is going to be initialized by the call to `uname`, which apparently is also not true. Even though the interface doesn't expose this field so it's not a problem in practice (although it might be UB since we do call `assume_init` on the whole struct) [the `utsname` does have a `domainname` field](https://docs.rs/libc/0.2.119/libc/struct.utsname.html) which glibc doesn't initialize.

The code also assumes that every field is a valid UTF-8 string, which is also technically not guaranteed.

The code also assumes that every field will be null terminated, which might not be true if any of the strings are too long (since glibc uses `strncpy` which will *not* null-terminate the string if it ends up running out of space).

This PR should fix all of these problems.

This is a breaking change.

Co-authored-by: Jan Bujak <jan@parity.io>
2022-03-24 03:12:46 +00:00
bors[bot]
d2bc189f5d
Merge #1686
1686: [skip ci] better docs for SockaddrLike::from_raw r=asomers a=asomers

Fixes #1680

Co-authored-by: Alan Somers <asomers@gmail.com>
2022-03-24 02:56:27 +00: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
350423ca02 [skip ci] better docs for SockaddrLike::from_raw
Fixes #1680
2022-03-22 21:29:51 -06:00
bors[bot]
3ca28f681c
Merge #1685
1685: Deprecate IpAddr, Ipv4Addr, and Ipv6Addr r=rtzoeller a=asomers

Because they're redundant with types in the standard library.

Fixes #1681

Co-authored-by: Alan Somers <asomers@gmail.com>
2022-03-23 03:28:45 +00: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
bors[bot]
0fe668265f
Merge #1684
1684: Replace the Sockaddr enum with a union r=rtzoeller a=asomers

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

Co-authored-by: Alan Somers <asomers@gmail.com>
2022-03-22 03:09:55 +00: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
bors[bot]
b2ff9d227f
Merge #1682
1682: [skip ci] spellcheck a comment for sethostname r=rtzoeller a=asomers



Co-authored-by: Alan Somers <asomers@gmail.com>
2022-03-20 15:44:32 +00:00
bors[bot]
1acf27ce27
Merge #1683
1683: Fix build for Redox and uclibc r=asomers a=rtzoeller

- Redox renamed `sigaction.sa_handler` to `.sa_sigaction`, which lets us drop some specialized code for the platform.
- uclibc now uses a `u32` for the `RLIMIT` definitions, like Linux GNU.

Co-authored-by: Ryan Zoeller <rtzoeller@rtzoeller.com>
2022-03-20 14:50:14 +00:00
Ryan Zoeller
e3983d1620 uclibc uses a u32 for RLIMIT definitions 2022-03-20 09:26:11 -05:00
Ryan Zoeller
ff6f8b8a26 Redox renamed sigaction.sa_handler to .sa_sigaction 2022-03-20 09:24:21 -05:00
Alan Somers
70f614fbd6 [skip ci] spellcheck a comment for sethostname 2022-03-19 22:13:46 -06:00
bors[bot]
445a4387ad
Merge #1677
1677: Use the same signature for LinkAddr::addr on all platforms r=rtzoeller a=asomers

This should've been done as part of #1675

Co-authored-by: Alan Somers <asomers@gmail.com>
2022-03-14 13:05:45 +00:00
Alan Somers
d97e292a5d Use the same signature for LinkAddr::addr on all platforms
This should've been done as part of #1675
2022-03-13 22:57:00 -06:00
bors[bot]
9e63cb7323
Merge #1668
1668: Change getrlimit and setrlimit to use rlim_t directly. r=asomers a=Arnavion

Fixes #1666

Co-authored-by: Arnavion <me@arnavion.dev>
2022-03-14 02:28:00 +00:00
Arnavion
cf628ca609
Change getrlimit and setrlimit to use rlim_t directly.
Fixes #1666
2022-03-13 17:33:02 -07:00
bors[bot]
342585cf8e
Merge #1675 #1676
1675: Fix a panic in Linkaddr::addr r=rtzoeller a=asomers

The function assumed something about the values of the sockaddr_dl's
fields.  But because the inner type is public, we musn't do that.  The
only solution is to change the function's signature to return an Option.

1676: Fix the build on DragonflyBSD with -Zminimal-versions r=asomers a=asomers



Co-authored-by: Alan Somers <asomers@gmail.com>
2022-03-13 23:07:29 +00:00
Alan Somers
e08c47cf1e Fix the build on DragonflyBSD with -Zminimal-versions 2022-03-13 16:36:34 -06:00
Alan Somers
f0f67954fe Fix a panic in Linkaddr::addr
The function assumed something about the values of the sockaddr_dl's
fields.  But because the inner type is public, we musn't do that.  The
only solution is to change the function's signature to return an Option.
2022-03-13 16:34:23 -06:00
bors[bot]
bf59a6ca10
Merge #1671
1671: docs: fix link in doc for cmsg_space in sys/socket r=rtzoeller a=liubin

Link to cmsg_space macro for recvmmsg and recvmsg should
be the doc's root of crate as macro is an exported macro.

Signed-off-by: bin liu <liubin0329@gmail.com>

Co-authored-by: bin liu <liubin0329@gmail.com>
2022-03-13 16:53:22 +00:00
bors[bot]
0435be2ed2
Merge #1584
1584: wait: implement waitid() r=rtzoeller a=NeoRaider

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 multiple bugs in qemu-user in the translation of siginfo_t (one fixed in January [2], one currently under review [3]).

[1] rust-lang/libc#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

Co-authored-by: Matthias Schiffer <mschiffer@universe-factory.net>
2022-03-10 01:40:22 +00: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
bin liu
84d89e4fc2 docs: fix link in doc for cmsg_space in sys/socket
Link to cmsg_space macro for recvmmsg and recvmsg should
be the doc's root of crate as macro is an exported macro.

Signed-off-by: bin liu <liubin0329@gmail.com>
2022-03-09 15:59:15 +08:00
bors[bot]
ff08ff7732
Merge #1670
1670: Add `MsgFlag::MSG_NOSIGNAL` r=rtzoeller a=i509VCB

(I guess I will see if I did the cfg block correctly)

Co-authored-by: i509VCB <git@i509.me>
2022-03-08 23:46:46 +00:00
i509VCB
a092c5ccc7
Add MsgFlag::MSG_NOSIGNAL 2022-03-06 16:27:48 -06:00
bors[bot]
41ec401271
Merge #1669
1669: Fix complation on riscv32 r=asomers a=kraj

Signed-off-by: Khem Raj <raj.khem@gmail.com>

Co-authored-by: Khem Raj <raj.khem@gmail.com>
2022-03-06 15:05:57 +00:00
Khem Raj
01cd9d2cfc linux.rs: Define consts for rv32 architecture
Upstream-Status: Pending
Signed-off-by: Khem Raj <raj.khem@gmail.com>
2022-03-05 22:46:30 -08:00
Khem Raj
490a0c52b7 Fix complation on riscv32
Signed-off-by: Khem Raj <raj.khem@gmail.com>
2022-03-05 22:41:42 -08:00
bors[bot]
9312f1c410
Merge #1656
1656: Remove PATH_MAX restriction from with_nix_path and further improve performance r=rtzoeller a=SUPERCILEX

This PR removes the `PATH_MAX` limitation since that's wrong anyway: https://insanecoding.blogspot.com/2007/11/pathmax-simply-isnt.html

A nice side effect is that this lets us further optimize `with_nix_path` by having the compiler not insert probe frames, saving us another fat pile of instructions:

```
2,289,930 ( 1.67%) 305,324 ( 0.99%) 152,662 ( 0.74%) 18 ( 0.15%)  .            .          .          .           .           => ???:__rust_probestack (152,662x)
```

New numbers:

```
19,257,593 (16.43%) 4,415,242 (15.75%) 2,593,635 (12.82%) 41 ( 0.27%) 47 ( 0.12%) 53 ( 0.26%) 7 ( 0.12%) 0          3 ( 0.02%) 2,404,730 (14.52%) 2,721 ( 0.53%) 762,780 (30.96%)    66 ( 0.90%)  => /home/asaveau/Desktop/nix/src/lib.rs:<[u8] as nix::NixPath>::with_nix_path (152,556x)
```

```
Ir                 Dr               Dw               I1mr        D1mr        D1mw       ILmr       DLmr       DLmw       Bc               Bcm        Bi               Bim            

1,067,892 ( 0.91%)       0          457,668 ( 2.26%)  2 ( 0.01%)  0          0          1 ( 0.02%) .          .                .          .                .              .               fn with_nix_path<T, F>(&self, f: F) -> Result<T>
        .                .                .           .           .          .          .          .          .                .          .                .              .               where
        .                .                .           .           .          .          .          .          .                .          .                .              .                   F: FnOnce(&CStr) -> T,
        .                .                .           .           .          .          .          .          .                .          .                .              .               {
        .                .                .           .           .          .          .          .          .                .          .                .              .                   // The real PATH_MAX is 4096, but it's statistically unlikely to have a path longer than
        .                .                .           .           .          .          .          .          .                .          .                .              .                   // ~300 bytes. See the appendix to get stats for your own machine.
        .                .                .           .           .          .          .          .          .                .          .                .              .                   //
        .                .                .           .           .          .          .          .          .                .          .                .              .                   // By being smaller than a memory page, we also avoid the compiler inserting a probe frame:
        .                .                .           .           .          .          .          .          .                .          .                .              .                   // https://docs.rs/compiler_builtins/latest/compiler_builtins/probestack/index.html
        .                .                .           .           .          .          .          .          .                .          .                .              .                   const MAX_STACK_ALLOCATION: usize = 512;
        .                .                .           .           .          .          .          .          .                .          .                .              .           
  305,112 ( 0.26%)       0                0           0           0          0          0          0          0          152,556 ( 0.92%) .                .              .                   if self.len() >= MAX_STACK_ALLOCATION {
        .                .                .           .           .          .          .          .          .                .          .                .              .                       return with_nix_path_allocating(self, f);
        .                .                .           .           .          .          .          .          .                .          .                .              .                   }
        .                .                .           .           .          .          .          .          .                .          .                .              .           
        .                .                .           .           .          .          .          .          .                .          .                .              .                   let mut buf = MaybeUninit::<[u8; MAX_STACK_ALLOCATION]>::uninit();
        .                .                .           .           .          .          .          .          .                .          .                .              .                   let buf_ptr = buf.as_mut_ptr() as *mut u8;
        .                .                .           .           .          .          .          .          .                .          .                .              .           
        .                .                .           .           .          .          .          .          .                .          .                .              .                   unsafe {
        .                .                .           .           .          .          .          .          .                .          .                .              .                       ptr::copy_nonoverlapping(self.as_ptr(), buf_ptr, self.len());
        .                .                .           .           .          .          .          .          .                .          .                .              .                       buf_ptr.add(self.len()).write(0);
        .                .                .           .           .          .          .          .          .                .          .                .              .                   }
        .                .                .           .           .          .          .          .          .                .          .                .              .           
1,067,892 ( 0.91%) 305,112 ( 1.09%) 152,556 ( 0.75%)  2 ( 0.01%)  7 ( 0.02%) 0          1 ( 0.02%) 0          0          305,112 ( 1.84%) 6 ( 0.00%) 152,556 ( 6.19%)     1 ( 0.01%)          match CStr::from_bytes_with_nul(unsafe { slice::from_raw_parts(buf_ptr, self.len() + 1) }) {
8,730,403 ( 7.45%) 1,211,383 ( 4.32%) 1,067,892 ( 5.28%) 18 ( 0.12%)  2 ( 0.00%) 0          2 ( 0.04%) 0          0          1,336,744 ( 8.07%) 609 ( 0.12%) 152,556 ( 6.19%)    62 ( 0.85%)  => /rustc/21b4a9cfdcbb1e76f4b36b5c3cfd64d627285093//library/std/src/ffi/c_str.rs:std::ffi::c_str::CStr::from_bytes_with_nul (152,556x)
  610,224 ( 0.52%) 610,224 ( 2.18%)       .           .           .          .          .          .          .                .          .                .              .                       Ok(s) => Ok(f(s)),
        .                .                .           .           .          .          .          .          .                .          .                .              .                       Err(_) => Err(Errno::EINVAL),
        .                .                .           .           .          .          .          .          .                .          .                .              .                   }
  762,780 ( 0.65%) 610,224 ( 2.18%)       .           .           .          .          .          .          .                .          .                .              .               }
        .                .                .           .           .          .          .          .          .                .          .                .              .           }
```

## Appendix

```rust
use histogram::Histogram;
use std::env;
use std::fs::{canonicalize, read_dir};
use std::path::Path;

fn main() {
    let args = env::args().collect::<Vec<String>>();

    let mut histogram = Histogram::new();
    if args.len() == 2 {
        log(&mut histogram, canonicalize(&args[1]).unwrap());
    } else {
        log(&mut histogram, canonicalize(".").unwrap());
    }

    println!(
        "min={}\nmax={}\nmean={}\np50={}\np90={}\np99={}\np999={}\nstddev={}\nstdvar={}",
        histogram.minimum().unwrap(),
        histogram.maximum().unwrap(),
        histogram.mean().unwrap(),
        histogram.percentile(50.0).unwrap(),
        histogram.percentile(90.0).unwrap(),
        histogram.percentile(99.0).unwrap(),
        histogram.percentile(99.9).unwrap(),
        histogram.stddev().unwrap(),
        histogram.stdvar().unwrap(),
    )
}

fn log(histogram: &mut Histogram, path: impl AsRef<Path>) {
    for dir in read_dir(path.as_ref()).unwrap() {
        let entry = dir.unwrap();
        histogram
            .increment(entry.path().as_os_str().len() as u64)
            .unwrap();
        if entry.file_type().unwrap().is_dir() {
            log(histogram, entry.path());
        }
    }
}
```

Co-authored-by: Alex Saveau <saveau.alexandre@gmail.com>
2022-02-27 21:31:39 +00:00
Alex Saveau
378a66dd18
Remove PATH_MAX restriction from with_nix_path
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
2022-02-27 13:22:07 -08:00
bors[bot]
15af9b6d81
Merge #1667
1667: Define _POSIX_VDISABLE on Android to fix doc test r=asomers a=rtzoeller

This fixes the compilation [this](1a2ee3da30/src/sys/termios.rs (L27)) example documentation on Android. Tested on Termux.

Co-authored-by: Ryan Zoeller <rtzoeller@rtzoeller.com>
2022-02-27 16:24:31 +00:00
Ryan Zoeller
1a2ee3da30 Define _POSIX_VDISABLE on Android to fix doc test 2022-02-27 09:54:46 -06:00
bors[bot]
6123083a47
Merge #1664
1664: also implement Read and Write for &PtyMaster r=rtzoeller a=doy

align with std::fs::File which also does this because the underlying calls are just syscalls which are safe to run concurrently

Co-authored-by: Jesse Luehrs <doy@tozt.net>
2022-02-24 01:40:57 +00:00
Jesse Luehrs
22bb105612 also implement Read and Write for &PtyMaster 2022-02-22 13:08:54 -05:00