change ~ remove (now unneeded) vendored nix-v0.23.1-patched

This commit is contained in:
Roy Ivy III
2022-01-09 18:57:25 -06:00
parent 774e72551b
commit d22f3e239c
112 changed files with 0 additions and 34875 deletions
-274
View File
@@ -1,274 +0,0 @@
cargo_cache:
folder: $CARGO_HOME/registry
fingerprint_script: cat Cargo.lock || echo ""
env:
# Build by default; don't just check
BUILD: build
CLIPPYFLAGS: -D warnings
RUSTFLAGS: -D warnings
RUSTDOCFLAGS: -D warnings
TOOL: cargo
# The MSRV
TOOLCHAIN: 1.46.0
ZFLAGS:
# Tests that don't require executing the build binaries
build: &BUILD
build_script:
- . $HOME/.cargo/env || true
- $TOOL +$TOOLCHAIN $BUILD $ZFLAGS --target $TARGET --all-targets
- $TOOL +$TOOLCHAIN doc $ZFLAGS --no-deps --target $TARGET
- $TOOL +$TOOLCHAIN clippy $ZFLAGS --target $TARGET -- $CLIPPYFLAGS
# Tests that do require executing the binaries
test: &TEST
<< : *BUILD
test_script:
- . $HOME/.cargo/env || true
- $TOOL +$TOOLCHAIN test --target $TARGET
# Test FreeBSD in a full VM. Test the i686 target too, in the
# same VM. The binary will be built in 32-bit mode, but will execute on a
# 64-bit kernel and in a 64-bit environment. Our tests don't execute any of
# the system's binaries, so the environment shouldn't matter.
task:
name: FreeBSD amd64 & i686
env:
TARGET: x86_64-unknown-freebsd
freebsd_instance:
image: freebsd-12-2-release-amd64
setup_script:
- fetch https://sh.rustup.rs -o rustup.sh
- sh rustup.sh -y --profile=minimal --default-toolchain $TOOLCHAIN
- . $HOME/.cargo/env
- rustup target add i686-unknown-freebsd
- rustup component add --toolchain $TOOLCHAIN clippy
<< : *TEST
i386_test_script:
- . $HOME/.cargo/env
- cargo build --target i686-unknown-freebsd
- cargo doc --no-deps --target i686-unknown-freebsd
- cargo test --target i686-unknown-freebsd
before_cache_script: rm -rf $CARGO_HOME/registry/index
# Test OSX in a full VM
task:
matrix:
- name: OSX x86_64
env:
TARGET: x86_64-apple-darwin
osx_instance:
image: catalina-xcode
setup_script:
- curl --proto '=https' --tlsv1.2 -sSf -o rustup.sh https://sh.rustup.rs
- sh rustup.sh -y --profile=minimal --default-toolchain $TOOLCHAIN
- . $HOME/.cargo/env
- rustup component add --toolchain $TOOLCHAIN clippy
<< : *TEST
before_cache_script: rm -rf $CARGO_HOME/registry/index
# Use cross for QEMU-based testing
# cross needs to execute Docker, so we must use Cirrus's Docker Builder task.
task:
env:
RUST_TEST_THREADS: 1 # QEMU works best with 1 thread
HOME: /tmp/home
PATH: $HOME/.cargo/bin:$PATH
RUSTFLAGS: --cfg qemu -D warnings
TOOL: cross
matrix:
- name: Linux arm gnueabi
env:
TARGET: arm-unknown-linux-gnueabi
- name: Linux armv7 gnueabihf
env:
TARGET: armv7-unknown-linux-gnueabihf
- name: Linux i686
env:
TARGET: i686-unknown-linux-gnu
- name: Linux i686 musl
env:
TARGET: i686-unknown-linux-musl
- name: Linux MIPS
env:
TARGET: mips-unknown-linux-gnu
- name: Linux MIPS64
env:
TARGET: mips64-unknown-linux-gnuabi64
- name: Linux MIPS64 el
env:
TARGET: mips64el-unknown-linux-gnuabi64
- name: Linux mipsel
env:
TARGET: mipsel-unknown-linux-gnu
- name: Linux powerpc64le
env:
TARGET: powerpc64le-unknown-linux-gnu
compute_engine_instance:
image_project: cirrus-images
image: family/docker-builder
platform: linux
cpu: 1 # Since QEMU will only use 1 thread
memory: 4G
setup_script:
- mkdir /tmp/home
- curl --proto '=https' --tlsv1.2 -sSf -o rustup.sh https://sh.rustup.rs
- sh rustup.sh -y --profile=minimal --default-toolchain $TOOLCHAIN
- . $HOME/.cargo/env
- cargo install cross
<< : *TEST
before_cache_script: rm -rf $CARGO_HOME/registry/index
# Tasks for Linux native builds
task:
matrix:
- name: Rust Stable
container:
image: rust:latest
env:
TARGET: x86_64-unknown-linux-gnu
TOOLCHAIN:
- name: Linux aarch64
arm_container:
image: rust:1.46
env:
RUSTFLAGS: --cfg graviton -D warnings
TARGET: aarch64-unknown-linux-gnu
- name: Linux x86_64
container:
image: rust:1.46
env:
TARGET: x86_64-unknown-linux-gnu
- name: Linux x86_64 musl
container:
image: rust:1.46
env:
TARGET: x86_64-unknown-linux-musl
setup_script:
- rustup target add $TARGET
- rustup component add clippy
<< : *TEST
before_cache_script: rm -rf $CARGO_HOME/registry/index
# Tasks for cross-compiling, but no testing
task:
container:
image: rust:1.46
env:
BUILD: check
matrix:
# Cross claims to support Android, but when it tries to run Nix's tests it
# reports undefined symbol references.
- name: Android aarch64
env:
TARGET: aarch64-linux-android
- name: Android arm
env:
TARGET: arm-linux-androideabi
- name: Android armv7
env:
TARGET: armv7-linux-androideabi
- name: Android i686
env:
TARGET: i686-linux-android
- name: Android x86_64
env:
TARGET: x86_64-linux-android
- name: Linux arm-musleabi
env:
TARGET: arm-unknown-linux-musleabi
- name: Fuchsia x86_64
env:
TARGET: x86_64-fuchsia
- name: Illumos
env:
TARGET: x86_64-unknown-illumos
# illumos toolchain isn't available via rustup until 1.50
TOOLCHAIN: 1.50.0
container:
image: rust:1.50
# Cross claims to support running tests on iOS, but it actually doesn't.
# https://github.com/rust-embedded/cross/issues/535
- name: iOS aarch64
env:
TARGET: aarch64-apple-ios
# Rustup only supports cross-building from arbitrary hosts for iOS at
# 1.49.0 and above. Below that it's possible to cross-build from an OSX
# host, but OSX VMs are more expensive than Linux VMs.
TOOLCHAIN: 1.49.0
- name: iOS x86_64
env:
TARGET: x86_64-apple-ios
TOOLCHAIN: 1.49.0
# Cross testing on powerpc fails with "undefined reference to renameat2".
# Perhaps cross is using too-old a version?
- name: Linux powerpc
env:
TARGET: powerpc-unknown-linux-gnu
# Cross claims to support Linux powerpc64, but it really doesn't.
# https://github.com/rust-embedded/cross/issues/441
- name: Linux powerpc64
env:
TARGET: powerpc64-unknown-linux-gnu
- name: Linux s390x
env:
TARGET: s390x-unknown-linux-gnu
- name: Linux x32
env:
TARGET: x86_64-unknown-linux-gnux32
- name: NetBSD x86_64
env:
TARGET: x86_64-unknown-netbsd
- name: Redox x86_64
env:
TARGET: x86_64-unknown-redox
# Redox requires a nightly compiler.
# If stuff breaks, change nightly to the date in the toolchain_*
# directory at https://static.redox-os.org
TOOLCHAIN: nightly-2020-08-04
setup_script:
- rustup target add $TARGET
- rustup toolchain install $TOOLCHAIN --profile minimal --target $TARGET
- rustup component add --toolchain $TOOLCHAIN clippy
<< : *BUILD
before_cache_script: rm -rf $CARGO_HOME/registry/index
# Rust Tier 3 targets can't use Rustup
task:
container:
image: rustlang/rust:nightly
env:
BUILD: check
# Must allow here rather than in lib.rs because this lint doesn't exist
# prior to Rust 1.57.0
# https://github.com/rust-lang/rust-clippy/issues/7718
CLIPPYFLAGS: -D warnings -A clippy::if_then_panic
TOOLCHAIN: nightly
ZFLAGS: -Zbuild-std
matrix:
- name: DragonFly BSD x86_64
env:
TARGET: x86_64-unknown-dragonfly
- name: OpenBSD x86_64
env:
TARGET: x86_64-unknown-openbsd
setup_script:
- rustup component add rust-src
<< : *BUILD
before_cache_script: rm -rf $CARGO_HOME/registry/index
# Test that we can build with the lowest version of all dependencies.
# "cargo test" doesn't work because some of our dev-dependencies, like
# rand, can't build with their own minimal dependencies.
task:
name: Minver
env:
TOOLCHAIN: nightly
container:
image: rustlang/rust:nightly
setup_script:
- cargo update -Zminimal-versions
script:
- cargo check
before_cache_script: rm -rf $CARGO_HOME/registry/index
@@ -1 +0,0 @@
/CHANGELOG.md merge=union
-10
View File
@@ -1,10 +0,0 @@
syntax: glob
Cargo.lock
target
*.diff
*.rej
*.orig
.*.swn
.*.swo
.*.swp
*.a
File diff suppressed because it is too large Load Diff
-114
View File
@@ -1,114 +0,0 @@
# Contributing to nix
We're really glad you're interested in contributing to nix! This
document has a few pointers and guidelines to help get you started.
To have a welcoming and inclusive project, nix uses the Rust project's
[Code of Conduct][conduct]. All contributors are expected to follow it.
[conduct]: https://www.rust-lang.org/conduct.html
# Issues
We use GitHub's [issue tracker][issues].
[issues]: https://github.com/nix-rust/nix/issues
## Bug reports
Before submitting a new bug report, please [search existing
issues][issue-search] to see if there's something related. If not, just
[open a new issue][new-issue]!
As a reminder, the more information you can give in your issue, the
easier it is to figure out how to fix it. For nix, this will likely
include the OS and version, and the architecture.
[issue-search]: https://github.com/nix-rust/nix/search?utf8=%E2%9C%93&q=is%3Aissue&type=Issues
[new-issue]: https://github.com/nix-rust/nix/issues/new
## Feature / API requests
If you'd like a new API or feature added, please [open a new
issue][new-issue] requesting it. As with reporting a bug, the more
information you can provide, the better.
## Labels
We use labels to help manage issues. The structure is modeled after
[Rust's issue labeling scheme][rust-labels]:
- **A-** prefixed labels state which area of the project the issue
relates to
- **E-** prefixed labels explain the level of experience necessary to fix the
issue
- **O-** prefixed labels specify the OS for issues that are OS-specific
- **R-** prefixed labels specify the architecture for issues that are
architecture-specific
[rust-labels]: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#issue-triage
# Pull requests
GitHub pull requests are the primary mechanism we use to change nix. GitHub itself has
some [great documentation][pr-docs] on using the Pull Request feature. We use the 'fork and
pull' model described there.
Please make pull requests against the `master` branch.
If you change the API by way of adding, removing or changing something or if
you fix a bug, please add an appropriate note to the [change log][cl]. We
follow the conventions of [Keep A CHANGELOG][kacl].
[cl]: https://github.com/nix-rust/nix/blob/master/CHANGELOG.md
[kacl]: https://github.com/olivierlacan/keep-a-changelog/tree/18adb5f5be7a898d046f6a4acb93e39dcf40c4ad
[pr-docs]: https://help.github.com/articles/using-pull-requests/
## Testing
nix has a test suite that you can run with `cargo test`. Ideally, we'd like pull
requests to include tests where they make sense. For example, when fixing a bug,
add a test that would have failed without the fix.
After you've made your change, make sure the tests pass in your development
environment. We also have [continuous integration set up on
Cirrus-CI][cirrus-ci], which might find some issues on other platforms. The CI
will run once you open a pull request.
There is also infrastructure for running tests for other targets
locally. More information is available in the [CI Readme][ci-readme].
[cirrus-ci]: https://cirrus-ci.com/github/nix-rust/nix
[ci-readme]: ci/README.md
### Disabling a test in the CI environment
Sometimes there are features that cannot be tested in the CI environment.
To stop a test from running under CI, add `skip_if_cirrus!()` to it. Please
describe the reason it shouldn't run under CI, and a link to an issue if
possible!
## bors, the bot who merges all the PRs
All pull requests are merged via [bors], an integration bot. After the
pull request has been reviewed, the reviewer will leave a comment like
> bors r+
to let bors know that it was approved. Then bors will check that it passes
tests when merged with the latest changes in the `master` branch, and
merge if the tests succeed.
[bors]: https://bors-ng.github.io/
## API conventions
If you're adding a new API, we have a [document with
conventions][conventions] to use throughout the nix project.
[conventions]: https://github.com/nix-rust/nix/blob/master/CONVENTIONS.md
-86
View File
@@ -1,86 +0,0 @@
# Conventions
In order to achieve our goal of wrapping [libc][libc] code in idiomatic rust
constructs with minimal performance overhead, we follow the following
conventions.
Note that, thus far, not all the code follows these conventions and not all
conventions we try to follow have been documented here. If you find an instance
of either, feel free to remedy the flaw by opening a pull request with
appropriate changes or additions.
## Change Log
We follow the conventions laid out in [Keep A CHANGELOG][kacl].
[kacl]: https://github.com/olivierlacan/keep-a-changelog/tree/18adb5f5be7a898d046f6a4acb93e39dcf40c4ad
## libc constants, functions and structs
We do not define integer constants ourselves, but use or reexport them from the
[libc crate][libc].
We use the functions exported from [libc][libc] instead of writing our own
`extern` declarations.
We use the `struct` definitions from [libc][libc] internally instead of writing
our own. If we want to add methods to a libc type, we use the newtype pattern.
For example,
```rust
pub struct SigSet(libc::sigset_t);
impl SigSet {
...
}
```
When creating newtypes, we use Rust's `CamelCase` type naming convention.
## Bitflags
Many C functions have flags parameters that are combined from constants using
bitwise operations. We represent the types of these parameters by types defined
using our `libc_bitflags!` macro, which is a convenience wrapper around the
`bitflags!` macro from the [bitflags crate][bitflags] that brings in the
constant value from `libc`.
We name the type for a set of constants whose element's names start with `FOO_`
`FooFlags`.
For example,
```rust
libc_bitflags!{
pub struct ProtFlags: libc::c_int {
PROT_NONE;
PROT_READ;
PROT_WRITE;
PROT_EXEC;
#[cfg(any(target_os = "linux", target_os = "android"))]
PROT_GROWSDOWN;
#[cfg(any(target_os = "linux", target_os = "android"))]
PROT_GROWSUP;
}
}
```
## Enumerations
We represent sets of constants that are intended as mutually exclusive arguments
to parameters of functions by [enumerations][enum].
## Structures Initialized by libc Functions
Whenever we need to use a [libc][libc] function to properly initialize a
variable and said function allows us to use uninitialized memory, we use
[`std::mem::MaybeUninit`][std_MaybeUninit] when defining the variable. This
allows us to avoid the overhead incurred by zeroing or otherwise initializing
the variable.
[bitflags]: https://crates.io/crates/bitflags/
[enum]: https://doc.rust-lang.org/reference.html#enumerations
[libc]: https://crates.io/crates/libc/
[std_MaybeUninit]: https://doc.rust-lang.org/stable/std/mem/union.MaybeUninit.html
-74
View File
@@ -1,74 +0,0 @@
[package]
name = "nix"
description = "Rust friendly bindings to *nix APIs"
edition = "2018"
version = "0.23.1"
authors = ["The nix-rust Project Developers"]
repository = "https://github.com/nix-rust/nix"
license = "MIT"
categories = ["os::unix-apis"]
include = ["src/**/*", "LICENSE", "README.md", "CHANGELOG.md"]
[package.metadata.docs.rs]
targets = [
"x86_64-unknown-linux-gnu",
"aarch64-linux-android",
"x86_64-apple-darwin",
"aarch64-apple-ios",
"x86_64-unknown-freebsd",
"x86_64-unknown-openbsd",
"x86_64-unknown-netbsd",
"x86_64-unknown-dragonfly",
"x86_64-fuchsia",
"x86_64-unknown-redox",
"x86_64-unknown-illumos"
]
[dependencies]
libc = { version = "0.2.102", features = [ "extra_traits" ] }
bitflags = "1.3.1"
cfg-if = "1.0"
[target.'cfg(not(target_os = "redox"))'.dependencies]
memoffset = "0.6.3"
[target.'cfg(target_os = "dragonfly")'.build-dependencies]
cc = "1"
[dev-dependencies]
assert-impl = "0.1"
lazy_static = "1.2"
rand = "0.8"
tempfile = "3.2.0"
semver = "1.0.0"
[target.'cfg(any(target_os = "android", target_os = "linux"))'.dev-dependencies]
caps = "0.5.1"
[target.'cfg(target_os = "freebsd")'.dev-dependencies]
sysctl = "0.1"
[[test]]
name = "test"
path = "test/test.rs"
[[test]]
name = "test-aio-drop"
path = "test/sys/test_aio_drop.rs"
[[test]]
name = "test-clearenv"
path = "test/test_clearenv.rs"
[[test]]
name = "test-lio-listio-resubmit"
path = "test/sys/test_lio_listio_resubmit.rs"
[[test]]
name = "test-mount"
path = "test/test_mount.rs"
harness = false
[[test]]
name = "test-ptymaster-drop"
path = "test/test_ptymaster_drop.rs"
-5
View File
@@ -1,5 +0,0 @@
[build.env]
passthrough = [
"RUSTFLAGS",
"RUST_TEST_THREADS"
]
-21
View File
@@ -1,21 +0,0 @@
The MIT License (MIT)
Copyright (c) 2015 Carl Lerche + nix-rust Authors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-102
View File
@@ -1,102 +0,0 @@
# Rust bindings to *nix APIs
[![Cirrus Build Status](https://api.cirrus-ci.com/github/nix-rust/nix.svg)](https://cirrus-ci.com/github/nix-rust/nix)
[![crates.io](https://img.shields.io/crates/v/nix.svg)](https://crates.io/crates/nix)
[Documentation (Releases)](https://docs.rs/nix/)
Nix seeks to provide friendly bindings to various *nix platform APIs (Linux, Darwin,
...). The goal is to not provide a 100% unified interface, but to unify
what can be while still providing platform specific APIs.
For many system APIs, Nix provides a safe alternative to the unsafe APIs
exposed by the [libc crate](https://github.com/rust-lang/libc). This is done by
wrapping the libc functionality with types/abstractions that enforce legal/safe
usage.
As an example of what Nix provides, examine the differences between what is
exposed by libc and nix for the
[gethostname](https://man7.org/linux/man-pages/man2/gethostname.2.html) system
call:
```rust,ignore
// libc api (unsafe, requires handling return code/errno)
pub unsafe extern fn gethostname(name: *mut c_char, len: size_t) -> c_int;
// nix api (returns a nix::Result<CStr>)
pub fn gethostname<'a>(buffer: &'a mut [u8]) -> Result<&'a CStr>;
```
## Supported Platforms
nix target support consists of two tiers. While nix attempts to support all
platforms supported by [libc](https://github.com/rust-lang/libc), only some
platforms are actively supported due to either technical or manpower
limitations. Support for platforms is split into three tiers:
* Tier 1 - Builds and tests for this target are run in CI. Failures of either
block the inclusion of new code.
* Tier 2 - Builds for this target are run in CI. Failures during the build
blocks the inclusion of new code. Tests may be run, but failures
in tests don't block the inclusion of new code.
* Tier 3 - Builds for this target are run in CI. Failures during the build
*do not* block the inclusion of new code. Testing may be run, but
failures in tests don't block the inclusion of new code.
The following targets are supported by `nix`:
Tier 1:
* aarch64-unknown-linux-gnu
* arm-unknown-linux-gnueabi
* armv7-unknown-linux-gnueabihf
* i686-unknown-freebsd
* i686-unknown-linux-gnu
* i686-unknown-linux-musl
* mips-unknown-linux-gnu
* mips64-unknown-linux-gnuabi64
* mips64el-unknown-linux-gnuabi64
* mipsel-unknown-linux-gnu
* powerpc64le-unknown-linux-gnu
* x86_64-apple-darwin
* x86_64-unknown-freebsd
* x86_64-unknown-linux-gnu
* x86_64-unknown-linux-musl
Tier 2:
* aarch64-apple-ios
* aarch64-linux-android
* arm-linux-androideabi
* arm-unknown-linux-musleabi
* armv7-linux-androideabi
* i686-linux-android
* powerpc-unknown-linux-gnu
* s390x-unknown-linux-gnu
* x86_64-apple-ios
* x86_64-linux-android
* x86_64-unknown-illumos
* x86_64-unknown-netbsd
Tier 3:
* x86_64-fuchsia
* x86_64-unknown-dragonfly
* x86_64-unknown-linux-gnux32
* x86_64-unknown-openbsd
* x86_64-unknown-redox
## Minimum Supported Rust Version (MSRV)
nix is supported on Rust 1.46.0 and higher. It's MSRV will not be
changed in the future without bumping the major or minor version.
## Contributing
Contributions are very welcome. Please See [CONTRIBUTING](CONTRIBUTING.md) for
additional details.
Feel free to join us in [the nix-rust/nix](https://gitter.im/nix-rust/nix) channel on Gitter to
discuss `nix` development.
## License
Nix is licensed under the MIT license. See [LICENSE](LICENSE) for more details.
-18
View File
@@ -1,18 +0,0 @@
This document lists the steps that lead to a successful release of the Nix
library.
# Before Release
Nix uses [cargo release](https://github.com/crate-ci/cargo-release) to automate
the release process. Based on changes since the last release, pick a new
version number following semver conventions. For nix, a change that drops
support for some Rust versions counts as a breaking change, and requires a
major bump.
The release is prepared as follows:
- Ask for a new libc version if, necessary. It usually is. Then update the
dependency in Cargo.toml accordingly.
- Confirm that everything's ready for a release by running
`cargo release --dry-run <patch|minor|major>`
- Create the release with `cargo release <patch|minor|major>`
-49
View File
@@ -1,49 +0,0 @@
status = [
"Android aarch64",
"Android arm",
"Android armv7",
"Android i686",
"Android x86_64",
"DragonFly BSD x86_64",
"FreeBSD amd64 & i686",
"Fuchsia x86_64",
"Linux MIPS",
"Linux MIPS64 el",
"Linux MIPS64",
"Linux aarch64",
"Linux arm gnueabi",
"Linux arm-musleabi",
"Linux armv7 gnueabihf",
"Linux i686 musl",
"Linux i686",
"Linux mipsel",
"Linux powerpc",
"Linux powerpc64",
"Linux powerpc64le",
"Linux s390x",
"Linux x32",
"Linux x86_64 musl",
"Linux x86_64",
"Minver",
"NetBSD x86_64",
"OpenBSD x86_64",
"OSX x86_64",
"Redox x86_64",
"Rust Stable",
"iOS aarch64",
"iOS x86_64",
"Illumos",
]
# Set bors's timeout to 1 hour
#
# bors's timeout should always be at least twice as long as the test suite
# takes. This is to allow the CI provider to fast-fail a test; if one of the
# builders immediately reports a failure, then bors will move on to the next
# batch, leaving the slower builders to work through the already-doomed run and
# the next one.
#
# At the time this was written, nix's test suite took about twenty minutes to
# run. The timeout was raised to one hour to give nix room to grow and time
# for delays on Cirrus's end.
timeout_sec = 3600
-5
View File
@@ -1,5 +0,0 @@
no-dev-version = true
pre-release-replacements = [
{ file="CHANGELOG.md", search="Unreleased", replace="{{version}}" },
{ file="CHANGELOG.md", search="ReleaseDate", replace="{{date}}" }
]
-246
View File
@@ -1,246 +0,0 @@
use crate::{Error, NixPath, Result};
use crate::errno::Errno;
use crate::fcntl::{self, OFlag};
use std::os::unix::io::{AsRawFd, IntoRawFd, RawFd};
use std::ptr;
use std::ffi;
use crate::sys;
#[cfg(target_os = "linux")]
use libc::{dirent64 as dirent, readdir64_r as readdir_r};
#[cfg(not(target_os = "linux"))]
use libc::{dirent, readdir_r};
/// An open directory.
///
/// This is a lower-level interface than `std::fs::ReadDir`. Notable differences:
/// * can be opened from a file descriptor (as returned by `openat`, perhaps before knowing
/// if the path represents a file or directory).
/// * implements `AsRawFd`, so it can be passed to `fstat`, `openat`, etc.
/// The file descriptor continues to be owned by the `Dir`, so callers must not keep a `RawFd`
/// after the `Dir` is dropped.
/// * can be iterated through multiple times without closing and reopening the file
/// descriptor. Each iteration rewinds when finished.
/// * returns entries for `.` (current directory) and `..` (parent directory).
/// * returns entries' names as a `CStr` (no allocation or conversion beyond whatever libc
/// does).
#[derive(Debug, Eq, Hash, PartialEq)]
pub struct Dir(
ptr::NonNull<libc::DIR>
);
impl Dir {
/// Opens the given path as with `fcntl::open`.
pub fn open<P: ?Sized + NixPath>(path: &P, oflag: OFlag,
mode: sys::stat::Mode) -> Result<Self> {
let fd = fcntl::open(path, oflag, mode)?;
Dir::from_fd(fd)
}
/// Opens the given path as with `fcntl::openat`.
pub fn openat<P: ?Sized + NixPath>(dirfd: RawFd, path: &P, oflag: OFlag,
mode: sys::stat::Mode) -> Result<Self> {
let fd = fcntl::openat(dirfd, path, oflag, mode)?;
Dir::from_fd(fd)
}
/// Converts from a descriptor-based object, closing the descriptor on success or failure.
#[inline]
pub fn from<F: IntoRawFd>(fd: F) -> Result<Self> {
Dir::from_fd(fd.into_raw_fd())
}
/// Converts from a file descriptor, closing it on success or failure.
pub fn from_fd(fd: RawFd) -> Result<Self> {
let d = ptr::NonNull::new(unsafe { libc::fdopendir(fd) }).ok_or_else(|| {
let e = Error::last();
unsafe { libc::close(fd) };
e
})?;
Ok(Dir(d))
}
/// Returns an iterator of `Result<Entry>` which rewinds when finished.
pub fn iter(&mut self) -> Iter {
Iter(self)
}
}
// `Dir` is not `Sync`. With the current implementation, it could be, but according to
// https://www.gnu.org/software/libc/manual/html_node/Reading_002fClosing-Directory.html,
// future versions of POSIX are likely to obsolete `readdir_r` and specify that it's unsafe to
// call `readdir` simultaneously from multiple threads.
//
// `Dir` is safe to pass from one thread to another, as it's not reference-counted.
unsafe impl Send for Dir {}
impl AsRawFd for Dir {
fn as_raw_fd(&self) -> RawFd {
unsafe { libc::dirfd(self.0.as_ptr()) }
}
}
impl Drop for Dir {
fn drop(&mut self) {
let e = Errno::result(unsafe { libc::closedir(self.0.as_ptr()) });
if !std::thread::panicking() && e == Err(Errno::EBADF) {
panic!("Closing an invalid file descriptor!");
};
}
}
fn next(dir: &mut Dir) -> Option<Result<Entry>> {
unsafe {
// Note: POSIX specifies that portable applications should dynamically allocate a
// buffer with room for a `d_name` field of size `pathconf(..., _PC_NAME_MAX)` plus 1
// for the NUL byte. It doesn't look like the std library does this; it just uses
// fixed-sized buffers (and libc's dirent seems to be sized so this is appropriate).
// Probably fine here too then.
let mut ent = std::mem::MaybeUninit::<dirent>::uninit();
let mut result = ptr::null_mut();
if let Err(e) = Errno::result(
readdir_r(dir.0.as_ptr(), ent.as_mut_ptr(), &mut result))
{
return Some(Err(e));
}
if result.is_null() {
return None;
}
assert_eq!(result, ent.as_mut_ptr());
Some(Ok(Entry(ent.assume_init())))
}
}
#[derive(Debug, Eq, Hash, PartialEq)]
pub struct Iter<'d>(&'d mut Dir);
impl<'d> Iterator for Iter<'d> {
type Item = Result<Entry>;
fn next(&mut self) -> Option<Self::Item> {
next(self.0)
}
}
impl<'d> Drop for Iter<'d> {
fn drop(&mut self) {
unsafe { libc::rewinddir((self.0).0.as_ptr()) }
}
}
/// The return type of [Dir::into_iter]
#[derive(Debug, Eq, Hash, PartialEq)]
pub struct OwningIter(Dir);
impl Iterator for OwningIter {
type Item = Result<Entry>;
fn next(&mut self) -> Option<Self::Item> {
next(&mut self.0)
}
}
impl IntoIterator for Dir {
type Item = Result<Entry>;
type IntoIter = OwningIter;
/// Creates a owning iterator, that is, one that takes ownership of the
/// `Dir`. The `Dir` cannot be used after calling this. This can be useful
/// when you have a function that both creates a `Dir` instance and returns
/// an `Iterator`.
///
/// Example:
///
/// ```
/// use nix::{dir::Dir, fcntl::OFlag, sys::stat::Mode};
/// use std::{iter::Iterator, string::String};
///
/// fn ls_upper(dirname: &str) -> impl Iterator<Item=String> {
/// let d = Dir::open(dirname, OFlag::O_DIRECTORY, Mode::S_IXUSR).unwrap();
/// d.into_iter().map(|x| x.unwrap().file_name().as_ref().to_string_lossy().to_ascii_uppercase())
/// }
/// ```
fn into_iter(self) -> Self::IntoIter {
OwningIter(self)
}
}
/// A directory entry, similar to `std::fs::DirEntry`.
///
/// Note that unlike the std version, this may represent the `.` or `..` entries.
#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq)]
#[repr(transparent)]
pub struct Entry(dirent);
#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq)]
pub enum Type {
Fifo,
CharacterDevice,
Directory,
BlockDevice,
File,
Symlink,
Socket,
}
impl Entry {
/// Returns the inode number (`d_ino`) of the underlying `dirent`.
#[cfg(any(target_os = "android",
target_os = "emscripten",
target_os = "fuchsia",
target_os = "haiku",
target_os = "illumos",
target_os = "ios",
target_os = "l4re",
target_os = "linux",
target_os = "macos",
target_os = "solaris"))]
pub fn ino(&self) -> u64 {
self.0.d_ino as u64
}
/// Returns the inode number (`d_fileno`) of the underlying `dirent`.
#[cfg(not(any(target_os = "android",
target_os = "emscripten",
target_os = "fuchsia",
target_os = "haiku",
target_os = "illumos",
target_os = "ios",
target_os = "l4re",
target_os = "linux",
target_os = "macos",
target_os = "solaris")))]
#[allow(clippy::useless_conversion)] // Not useless on all OSes
pub fn ino(&self) -> u64 {
u64::from(self.0.d_fileno)
}
/// Returns the bare file name of this directory entry without any other leading path component.
pub fn file_name(&self) -> &ffi::CStr {
unsafe { ::std::ffi::CStr::from_ptr(self.0.d_name.as_ptr()) }
}
/// Returns the type of this directory entry, if known.
///
/// See platform `readdir(3)` or `dirent(5)` manpage for when the file type is known;
/// notably, some Linux filesystems don't implement this. The caller should use `stat` or
/// `fstat` if this returns `None`.
pub fn file_type(&self) -> Option<Type> {
#[cfg(not(any(target_os = "illumos", target_os = "solaris")))]
match self.0.d_type {
libc::DT_FIFO => Some(Type::Fifo),
libc::DT_CHR => Some(Type::CharacterDevice),
libc::DT_DIR => Some(Type::Directory),
libc::DT_BLK => Some(Type::BlockDevice),
libc::DT_REG => Some(Type::File),
libc::DT_LNK => Some(Type::Symlink),
libc::DT_SOCK => Some(Type::Socket),
/* libc::DT_UNKNOWN | */ _ => None,
}
// illumos and Solaris systems do not have the d_type member at all:
#[cfg(any(target_os = "illumos", target_os = "solaris"))]
None
}
}
-66
View File
@@ -1,66 +0,0 @@
//! Environment variables
use cfg_if::cfg_if;
use std::fmt;
/// Indicates that [`clearenv`] failed for some unknown reason
#[derive(Clone, Copy, Debug)]
pub struct ClearEnvError;
impl fmt::Display for ClearEnvError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "clearenv failed")
}
}
impl std::error::Error for ClearEnvError {}
/// Clear the environment of all name-value pairs.
///
/// On platforms where libc provides `clearenv()`, it will be used. libc's
/// `clearenv()` is documented to return an error code but not set errno; if the
/// return value indicates a failure, this function will return
/// [`ClearEnvError`].
///
/// On platforms where libc does not provide `clearenv()`, a fallback
/// implementation will be used that iterates over all environment variables and
/// removes them one-by-one.
///
/// # Safety
///
/// This function is not threadsafe and can cause undefined behavior in
/// combination with `std::env` or other program components that access the
/// environment. See, for example, the discussion on `std::env::remove_var`; this
/// function is a case of an "inherently unsafe non-threadsafe API" dealing with
/// the environment.
///
/// The caller must ensure no other threads access the process environment while
/// this function executes and that no raw pointers to an element of libc's
/// `environ` is currently held. The latter is not an issue if the only other
/// environment access in the program is via `std::env`, but the requirement on
/// thread safety must still be upheld.
pub unsafe fn clearenv() -> std::result::Result<(), ClearEnvError> {
let ret;
cfg_if! {
if #[cfg(any(target_os = "fuchsia",
target_os = "wasi",
target_env = "wasi",
target_env = "uclibc",
target_os = "linux",
target_os = "android",
target_os = "emscripten"))] {
ret = libc::clearenv();
} else {
use std::env;
for (name, _) in env::vars_os() {
env::remove_var(name);
}
ret = 0;
}
}
if ret == 0 {
Ok(())
} else {
Err(ClearEnvError)
}
}
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
-121
View File
@@ -1,121 +0,0 @@
//! Feature tests for OS functionality
pub use self::os::*;
#[cfg(any(target_os = "linux", target_os = "android"))]
mod os {
use crate::sys::utsname::uname;
// Features:
// * atomic cloexec on socket: 2.6.27
// * pipe2: 2.6.27
// * accept4: 2.6.28
static VERS_UNKNOWN: usize = 1;
static VERS_2_6_18: usize = 2;
static VERS_2_6_27: usize = 3;
static VERS_2_6_28: usize = 4;
static VERS_3: usize = 5;
#[inline]
fn digit(dst: &mut usize, b: u8) {
*dst *= 10;
*dst += (b - b'0') as usize;
}
fn parse_kernel_version() -> usize {
let u = uname();
let mut curr: usize = 0;
let mut major: usize = 0;
let mut minor: usize = 0;
let mut patch: usize = 0;
for b in u.release().bytes() {
if curr >= 3 {
break;
}
match b {
b'.' | b'-' => {
curr += 1;
}
b'0'..=b'9' => {
match curr {
0 => digit(&mut major, b),
1 => digit(&mut minor, b),
_ => digit(&mut patch, b),
}
}
_ => break,
}
}
if major >= 3 {
VERS_3
} else if major >= 2 {
if minor >= 7 {
VERS_UNKNOWN
} else if minor >= 6 {
if patch >= 28 {
VERS_2_6_28
} else if patch >= 27 {
VERS_2_6_27
} else {
VERS_2_6_18
}
} else {
VERS_UNKNOWN
}
} else {
VERS_UNKNOWN
}
}
fn kernel_version() -> usize {
static mut KERNEL_VERS: usize = 0;
unsafe {
if KERNEL_VERS == 0 {
KERNEL_VERS = parse_kernel_version();
}
KERNEL_VERS
}
}
/// Check if the OS supports atomic close-on-exec for sockets
pub fn socket_atomic_cloexec() -> bool {
kernel_version() >= VERS_2_6_27
}
#[test]
pub fn test_parsing_kernel_version() {
assert!(kernel_version() > 0);
}
}
#[cfg(any(
target_os = "dragonfly", // Since ???
target_os = "freebsd", // Since 10.0
target_os = "illumos", // Since ???
target_os = "netbsd", // Since 6.0
target_os = "openbsd", // Since 5.7
target_os = "redox", // Since 1-july-2020
))]
mod os {
/// Check if the OS supports atomic close-on-exec for sockets
pub const fn socket_atomic_cloexec() -> bool {
true
}
}
#[cfg(any(target_os = "macos",
target_os = "ios",
target_os = "fuchsia",
target_os = "solaris"))]
mod os {
/// Check if the OS supports atomic close-on-exec for sockets
pub const fn socket_atomic_cloexec() -> bool {
false
}
}
-147
View File
@@ -1,147 +0,0 @@
//! Query network interface addresses
//!
//! Uses the Linux and/or BSD specific function `getifaddrs` to query the list
//! of interfaces and their associated addresses.
use cfg_if::cfg_if;
use std::ffi;
use std::iter::Iterator;
use std::mem;
use std::option::Option;
use crate::{Result, Errno};
use crate::sys::socket::SockAddr;
use crate::net::if_::*;
/// Describes a single address for an interface as returned by `getifaddrs`.
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub struct InterfaceAddress {
/// Name of the network interface
pub interface_name: String,
/// Flags as from `SIOCGIFFLAGS` ioctl
pub flags: InterfaceFlags,
/// Network address of this interface
pub address: Option<SockAddr>,
/// Netmask of this interface
pub netmask: Option<SockAddr>,
/// Broadcast address of this interface, if applicable
pub broadcast: Option<SockAddr>,
/// Point-to-point destination address
pub destination: Option<SockAddr>,
}
cfg_if! {
if #[cfg(any(target_os = "android", target_os = "emscripten", target_os = "fuchsia", target_os = "linux"))] {
fn get_ifu_from_sockaddr(info: &libc::ifaddrs) -> *const libc::sockaddr {
info.ifa_ifu
}
} else {
fn get_ifu_from_sockaddr(info: &libc::ifaddrs) -> *const libc::sockaddr {
info.ifa_dstaddr
}
}
}
impl InterfaceAddress {
/// Create an `InterfaceAddress` from the libc struct.
fn from_libc_ifaddrs(info: &libc::ifaddrs) -> InterfaceAddress {
let ifname = unsafe { ffi::CStr::from_ptr(info.ifa_name) };
let address = unsafe { SockAddr::from_libc_sockaddr(info.ifa_addr) };
let netmask = unsafe { SockAddr::from_libc_sockaddr(info.ifa_netmask) };
let mut addr = InterfaceAddress {
interface_name: ifname.to_string_lossy().to_string(),
flags: InterfaceFlags::from_bits_truncate(info.ifa_flags as i32),
address,
netmask,
broadcast: None,
destination: None,
};
let ifu = get_ifu_from_sockaddr(info);
if addr.flags.contains(InterfaceFlags::IFF_POINTOPOINT) {
addr.destination = unsafe { SockAddr::from_libc_sockaddr(ifu) };
} else if addr.flags.contains(InterfaceFlags::IFF_BROADCAST) {
addr.broadcast = unsafe { SockAddr::from_libc_sockaddr(ifu) };
}
addr
}
}
/// Holds the results of `getifaddrs`.
///
/// Use the function `getifaddrs` to create this Iterator. Note that the
/// actual list of interfaces can be iterated once and will be freed as
/// soon as the Iterator goes out of scope.
#[derive(Debug, Eq, Hash, PartialEq)]
pub struct InterfaceAddressIterator {
base: *mut libc::ifaddrs,
next: *mut libc::ifaddrs,
}
impl Drop for InterfaceAddressIterator {
fn drop(&mut self) {
unsafe { libc::freeifaddrs(self.base) };
}
}
impl Iterator for InterfaceAddressIterator {
type Item = InterfaceAddress;
fn next(&mut self) -> Option<<Self as Iterator>::Item> {
match unsafe { self.next.as_ref() } {
Some(ifaddr) => {
self.next = ifaddr.ifa_next;
Some(InterfaceAddress::from_libc_ifaddrs(ifaddr))
}
None => None,
}
}
}
/// Get interface addresses using libc's `getifaddrs`
///
/// Note that the underlying implementation differs between OSes. Only the
/// most common address families are supported by the nix crate (due to
/// lack of time and complexity of testing). The address family is encoded
/// in the specific variant of `SockAddr` returned for the fields `address`,
/// `netmask`, `broadcast`, and `destination`. For any entry not supported,
/// the returned list will contain a `None` entry.
///
/// # Example
/// ```
/// let addrs = nix::ifaddrs::getifaddrs().unwrap();
/// for ifaddr in addrs {
/// match ifaddr.address {
/// Some(address) => {
/// println!("interface {} address {}",
/// ifaddr.interface_name, address);
/// },
/// None => {
/// println!("interface {} with unsupported address family",
/// ifaddr.interface_name);
/// }
/// }
/// }
/// ```
pub fn getifaddrs() -> Result<InterfaceAddressIterator> {
let mut addrs = mem::MaybeUninit::<*mut libc::ifaddrs>::uninit();
unsafe {
Errno::result(libc::getifaddrs(addrs.as_mut_ptr())).map(|_| {
InterfaceAddressIterator {
base: addrs.assume_init(),
next: addrs.assume_init(),
}
})
}
}
#[cfg(test)]
mod tests {
use super::*;
// Only checks if `getifaddrs` can be invoked without panicking.
#[test]
fn test_getifaddrs() {
let _ = getifaddrs();
}
}
-122
View File
@@ -1,122 +0,0 @@
//! Load and unload kernel modules.
//!
//! For more details see
use std::ffi::CStr;
use std::os::unix::io::AsRawFd;
use crate::errno::Errno;
use crate::Result;
/// Loads a kernel module from a buffer.
///
/// It loads an ELF image into kernel space,
/// performs any necessary symbol relocations,
/// initializes module parameters to values provided by the caller,
/// and then runs the module's init function.
///
/// This function requires `CAP_SYS_MODULE` privilege.
///
/// The `module_image` argument points to a buffer containing the binary image
/// to be loaded. The buffer should contain a valid ELF image
/// built for the running kernel.
///
/// The `param_values` argument is a string containing space-delimited specifications
/// of the values for module parameters.
/// Each of the parameter specifications has the form:
///
/// `name[=value[,value...]]`
///
/// # Example
///
/// ```no_run
/// use std::fs::File;
/// use std::io::Read;
/// use std::ffi::CString;
/// use nix::kmod::init_module;
///
/// let mut f = File::open("mykernel.ko").unwrap();
/// let mut contents: Vec<u8> = Vec::new();
/// f.read_to_end(&mut contents).unwrap();
/// init_module(&mut contents, &CString::new("who=Rust when=Now,12").unwrap()).unwrap();
/// ```
///
/// See [`man init_module(2)`](https://man7.org/linux/man-pages/man2/init_module.2.html) for more information.
pub fn init_module(module_image: &[u8], param_values: &CStr) -> Result<()> {
let res = unsafe {
libc::syscall(
libc::SYS_init_module,
module_image.as_ptr(),
module_image.len(),
param_values.as_ptr(),
)
};
Errno::result(res).map(drop)
}
libc_bitflags!(
/// Flags used by the `finit_module` function.
pub struct ModuleInitFlags: libc::c_uint {
/// Ignore symbol version hashes.
MODULE_INIT_IGNORE_MODVERSIONS;
/// Ignore kernel version magic.
MODULE_INIT_IGNORE_VERMAGIC;
}
);
/// Loads a kernel module from a given file descriptor.
///
/// # Example
///
/// ```no_run
/// use std::fs::File;
/// use std::ffi::CString;
/// use nix::kmod::{finit_module, ModuleInitFlags};
///
/// let f = File::open("mymod.ko").unwrap();
/// finit_module(&f, &CString::new("").unwrap(), ModuleInitFlags::empty()).unwrap();
/// ```
///
/// See [`man init_module(2)`](https://man7.org/linux/man-pages/man2/init_module.2.html) for more information.
pub fn finit_module<T: AsRawFd>(fd: &T, param_values: &CStr, flags: ModuleInitFlags) -> Result<()> {
let res = unsafe {
libc::syscall(
libc::SYS_finit_module,
fd.as_raw_fd(),
param_values.as_ptr(),
flags.bits(),
)
};
Errno::result(res).map(drop)
}
libc_bitflags!(
/// Flags used by `delete_module`.
///
/// See [`man delete_module(2)`](https://man7.org/linux/man-pages/man2/delete_module.2.html)
/// for a detailed description how these flags work.
pub struct DeleteModuleFlags: libc::c_int {
O_NONBLOCK;
O_TRUNC;
}
);
/// Unloads the kernel module with the given name.
///
/// # Example
///
/// ```no_run
/// use std::ffi::CString;
/// use nix::kmod::{delete_module, DeleteModuleFlags};
///
/// delete_module(&CString::new("mymod").unwrap(), DeleteModuleFlags::O_NONBLOCK).unwrap();
/// ```
///
/// See [`man delete_module(2)`](https://man7.org/linux/man-pages/man2/delete_module.2.html) for more information.
pub fn delete_module(name: &CStr, flags: DeleteModuleFlags) -> Result<()> {
let res = unsafe { libc::syscall(libc::SYS_delete_module, name.as_ptr(), flags.bits()) };
Errno::result(res).map(drop)
}

Some files were not shown because too many files have changed in this diff Show More