43 Commits

Author SHA1 Message Date
Dan Gohman 4e2599b729 Run the tests on Rust 1.48, and check compilation of tests and examples on more targets (#465)
* Fix the tests to run on 1.48.

This puts the benchmarks behind a `criterion` cfg, so add
`--cfg=criterion` to RUSTFLAGS when running cargo bench.

An MSRV of 1.48 enables us to support users such as async-io, which also
has an MSRV of 1.48.

* Add a rust-version field.

This prints a warning under Rust 1.48, but only when rustix is the
top-level build; when rustix is a dependency, it doesn't warn, so this
seems ok.
2022-12-01 11:42:09 -08:00
Dan Gohman d85c50603b Enable rustix::termios::isatty on wasm32-wasi. 2022-11-28 08:58:36 -08:00
Dan Gohman a4434a6c12 Fix various compilation errors on haiku. (#411)
This builds on top of #407!
2022-09-25 18:20:34 -07:00
Dan Gohman e5d9aa159f More fixes for compilation on x86_64-unknown-dragonfly. (#410)
Add a tier-3 CI check for x86_64-unknown-dragonfly, and fix the
compilation errors needed to compile with --features=all-apis.

This builds on top of #409!
2022-09-25 13:15:28 -07:00
gco ccaebe7c3a Fix compilation errors on solaris. 2022-09-07 14:05:12 -07:00
Dan Gohman 26baf41126 Add a Result to getpgid, and add getpgrp. (#386)
* Add a `Result` to `getpgid`, and add `getpgrp`.

Add a `Result` return type to `getpgid`, as it can fail if there's no
process with the given pid.

And, add a a `getpgrp` function, which is similar to `getpgid`, but
doesn't take a pid argument and always operates on the current process,
which means it doesn't need a `Result` return type.

* Use `getpgid` on platforms which don't have a `getpgrp` syscall.
2022-07-26 05:49:50 -07:00
Dan Gohman ec92ea492e Fix miscellaneous clippy lints. 2022-07-07 07:38:07 -07:00
Dan Gohman 61f69d91db Be consistent about trailing commas in cfgs in more places. 2022-06-14 16:19:44 -07:00
Dan Gohman 801a48149f Code formatting cleanups.
Wrap long lines that were hidden from rustfmt by macros, be consistent
about trailing commas in `cfg`s, alphabetize operands to `any`/`all`,
and add some comments.
2022-06-14 16:19:44 -07:00
Dan Gohman 0a8e27e336 Fix compilation on arm-linux-androideabi. (#364)
* Fix compilation on arm-linux-androideabi.

arm-linux-androideabi's `st_dev` is 64-bit, even though its `dev_t` is
32-bit.

* Move qemu arguments into qemu_args for mipsel and mips64el.

The cache script needs the name of the qemu binary without the args, so
always split the args into a separate variable.

* `linux_execfn` is unavailable on 32-bit Android.

* Fix types for non-x86 32-bit Android.

* Add aarch64-apple-ios as a cross target to CI.
2022-06-13 15:50:01 -07:00
Dan Gohman 11630efc0d Add more cfg's to fix the build with various combinations of features. 2022-06-13 15:49:17 -07:00
Dan Gohman 6c6a86c6fa Avoid using .init_array and __environ on non-musl non-glibc platforms. (#339)
* Avoid using `.init_array` and `__environ` on non-musl non-glibc platforms.

Don't assume that non-musl non-glibc platforms have `.init_array` and
`__environ`; use an explicit `init` function on such platforms, and add a
`debug_assert` to check that it's called.

* Add a safety comment.

* Move the auxv functions into a new top-level "param" module.

"param" is short for "process parameter".

* Use `CStr` instead of `ZStr`.
2022-06-03 06:28:23 -07:00
Dan Gohman b99ed80b77 Fix dependencies for big-endian mips targets.
This makes main consistent with the changes mad in #343 in the 0.34.x
branch.
2022-06-02 10:34:53 -07:00
Dan Gohman fc82d704bc Change dup2's second operand from &OwnedFd to &mut OwnedFd.
And similar for `dup3`.

The idea behind using `&OwnedFd` is that `dup2`'s second operand isn't like a
normal borrow. It effectively closes the old file descriptor, and creates a
new one with the same index. This could break assumptions of classes that have
an `AsFd` to allow users to do special I/O operations, but which don't expect
users can close and reopen their file descriptor as some completely unrelated
resource.

However, the existence of things like [`FilelikeView`], as well as the
`ManuallyDrop` pattern, mean that `&OwnedFd` doesn't actually prevent
users from using `dup2` on a `BorrowedFd`.

With sunfishcode/io-lifetimes#32 though, `&mut OwnedFd` would be
sufficient, because it removes the `DerefMut` implementation.

So change `rustix` stance to be that `dup2` requires `&mut OwnedFd`.

This means that it's no longer possible to pass the same file descriptor
to both operands of `dup2` or `dup3` with safe Rust, which means it's not
possible to observe the difference in behavior in that case, so remove
the `dup3.rs` test.

[`FilelikeView`]: https://docs.rs/io-lifetimes/latest/io_lifetimes/views/struct.FilelikeView.html
2022-05-26 12:41:01 -07:00
Dan Gohman 243e8c5197 Rename rustix::io::Error to rustix::io::Errno.
Fixes #254.
2022-05-16 04:00:10 -07:00
Dan Gohman 99fd6e5ccc Fix y2038 bugs in the libc backend on glibc platforms.
Add support for glibc's y2038 APIs in the libc backend.

The musl and android targets are not y2038 compatible on 32-bit
platforms, however in musl's case, this will be fixed when Rust itself
is updated to musl 1.2, and in android's case, this is because android
itself does not intend to be y2038-compatible on 32-bit platforms.

This strengthen's rustix's y2038 stance to: support y2038 compatibility
on platforms which have support for this.
2022-05-08 06:40:10 -07:00
Dan Gohman a946a14762 Put net, time, and other parts of the API behind feature flags (#297)
* Introduce API features.

* Don't use doc_cfg on internal modules.

* Don't compile the net code when the "net" feature is not present.

* Don't compile the runtime code when the "runtime" feature is not present.

* Don't compile the thread code when the "thread" feature is not present.

* Don't compile the time code when the "time" feature is not present.

* Don't compile the fs code when the "fs" feature is not present.

* Don't compile the rand code when the "rand" feature is not present.

* Split an "mm" feature out of the "io" module.

* Make some parts of "process"' implementation conditional.

* "Inline" the use declarations in src/imp/linux_raw/fs/mod.rs.

* Export `Timespec` and `ClockId` in `crate::thread`.

* io_uring depends on types from fs and net.

* Re-export Timespec etc. in crate::fs and crate::thread.

This makes it easier to disable crate::time when the time module is not
enabled.

* Ensure that tests and examples compile when features are disabled.

* Fix compilation.
2022-05-02 10:54:40 -07:00
Dan Gohman 3e8957c62c Tidy up unsafe block safety comments.
Ensure that unsafe block safety comments are have a form that clippy can
identify, add add safety comments for several blocks that needed them.
2022-04-29 16:39:39 -07:00
Dan Gohman ce827448c9 Implement a new rustix::termios module. (#274)
* Implement a new `rustix::termios` module.

Implement a new termios module, containing tcdrain, tcflow, tcflush,
tcgetpgrp, tcgetsid, tcsendbreak, tcsetattr, tcsetpgrp, tcsetwinsize,
and all the cf* functions.

This also renames APIs like `ioctl_tcgets` to more POSIX-like names,
like `tcgetattr`.

* Put the termios API under a "termios" cargo feature.

In anticipation of #250, put the "termios" API under a "termios" feature.

* Move `isatty` into the termios API module.

* Make `RawMode` on x86 Android be `c_uint`.

Android's `mode_t` is `u16`, which is different than its `stat`'s
`st_mode`.

* Move `ttyname` into the `termios` module.
2022-04-18 15:38:53 -07:00
Dan Gohman 1ddac0f56d Simplify the "procfs" feature.
Make `ttyname` conditional on the "procfs" feature, regardless of which
backend is enabled. This makes it easier to switch backends without
having to worry about which APIs are in use.
2022-04-18 14:45:06 -07:00
Dan Gohman f3be1866f8 Add a clock_ticks_per_second function.
This exposes `sysconf(_SC_CLK_TCK)`.
2022-03-07 07:02:55 -08:00
Dan Gohman fb844ed676 Fixes for --cfg=io_lifetimes_use_std mode
This contains a few fixes for building rustix in io_lifetimes_use_std
mode, which tells io-lifetimes to be a passthrough for the I/O safety
types and traits in nightly std rather than using its own.
2022-03-07 05:26:43 -08:00
Dan Gohman 815a9aa411 Use the new impl AsFd for &T support in io-lifetimes.
With rust-lang/rust#93888 now in nightly, and sunfishcode/io-lifetimes#18 now
in io-lifetimes 0.5.2, we can now simplify the `AsFd` pattern from
`fn foo<Fd: AsFd>(fd: &Fd)` to `fn foo<Fd: AsFd>(fd: Fd)`, without the `&`.

This also follows the emerging convention in std, as seen in the new
[`fchown`] function.

This means that users can now pass `BorrowedFd` values directly to
functions that expect `AsFd` arguments, without having to write an
extra `&` when passing them.

[`fchown`]: https://doc.rust-lang.org/nightly/std/os/unix/fs/fn.fchown.html
2022-02-17 07:01:03 -08:00
Dan Gohman c476e97387 Fix a typo in the time example. 2022-02-16 13:24:43 -08:00
Dan Gohman ca21dfdb26 Reformat comments. 2022-02-16 13:24:43 -08:00
Dan Gohman 20ebc0f5ee Add comments to dup2_to_replace_stdio.
And while here, simplify the code to use `println!` to print "hello
world", which we can do now that it's no longer running within the
test harness process.
2022-02-01 08:17:17 -08:00
Dan Gohman ee8edc414a Move the dup2_to_replace_stdio test into a separate child process.
This should help it run better on macos and ios, as well as on older
Linux versions and qemu.
2022-01-31 18:38:34 -08:00
Dan Gohman f7e4c56df5 Write more comments.
Make a pass over the crate adding and cleanup up comments and doc aliases.
2022-01-19 12:44:26 -08:00
Dan Gohman 71a3f2d4d3 Make Pid a non-zero type. (#136)
Make `Pid` a non-zero type and use `Option<Pid>` in places where a pid
value can be zero.  This lets `fork`'s API use an `Option` instead of a
sentry value, which is cleaner.
2021-12-03 19:59:05 -08:00
Dan Gohman 39da9d142c Rename rustix::io_lifetimes to rustix::fd. (#128)
And have it export only the types and traits that rustix uses. This
makes it easier to provide a consistent interface whether the fd
types and traits are defined by the standard library or by Rustix
itself.
2021-12-01 11:32:02 -08:00
Dan Gohman 0c2b539e29 Add a "hello world" example.
Add an example which shows how to implement "hello world" using rustix
calls.
2021-11-18 06:40:02 -08:00
Dan Gohman 4ef8c6a1d6 Rename rsix to rustix.
Fixes #98.
2021-11-04 15:16:20 -07:00
Dan Gohman 57b7f4f628 Winsock support.
The Windows Winsock API provides an API similar enough to POSIX-style
sockets that it's supportable within rsix.
2021-11-02 04:19:27 -07:00
Your Name ba243f182c replace OsString with CString in getcwd 2021-10-20 06:01:12 -07:00
Your Name a67afe4667 replace OsString with CString in ttyname 2021-10-20 06:01:12 -07:00
Dan Gohman 63b6740c15 Put proc_self_fd and ttyname behind a "procfs" cargo feature.
This allows the `once_cell` depedendency to be optional.
2021-10-11 09:57:01 -07:00
Dan Gohman dc4e93d469 Implement linux_execfn, exposing AT_EXECFN. 2021-09-30 07:47:27 -07:00
Dan Gohman 5a7b4cb6d5 Implement getrlimit. 2021-09-30 07:47:27 -07:00
Dan Gohman 8486d96396 rustfmt 2021-09-15 12:27:40 -07:00
Dan Gohman b6035e886c Rename the ttyname example to stdio, and add more output.
This also fixes the API for `ioctl_tiocgwinsz`.
2021-09-15 12:10:18 -07:00
Dan Gohman b0c100b7c6 Add a simple time example. 2021-09-15 12:09:57 -07:00
Dan Gohman 50fc77c5ad Add an example demonstrating use of the process APIs.
Also, move `getcwd` into the `process` module, since it's reading an
attribute of the current process. This is admittadly subjective, since
`cwd()` is in `fs`, but I think it makes more sense this way because
`cwd()` is just a way to let `*at` functions behave like their non-`at`
counterparts, while `getcwd` is typically used to record the path for
later use or for use outside the process.
2021-09-14 17:13:10 -07:00
Dan Gohman e080560c71 Add a simple ttyname example. 2021-09-14 10:09:32 -07:00