diff options
Diffstat (limited to 'src/sys')
-rw-r--r-- | src/sys/aio.rs | 2 | ||||
-rw-r--r-- | src/sys/epoll.rs | 1 | ||||
-rw-r--r-- | src/sys/event.rs | 1 | ||||
-rw-r--r-- | src/sys/mman.rs | 1 | ||||
-rw-r--r-- | src/sys/mod.rs | 2 | ||||
-rw-r--r-- | src/sys/pthread.rs | 22 | ||||
-rw-r--r-- | src/sys/ptrace/bsd.rs | 1 | ||||
-rw-r--r-- | src/sys/ptrace/linux.rs | 2 | ||||
-rw-r--r-- | src/sys/quota.rs | 2 | ||||
-rw-r--r-- | src/sys/reboot.rs | 1 | ||||
-rw-r--r-- | src/sys/signal.rs | 2 | ||||
-rw-r--r-- | src/sys/socket/addr.rs | 2 | ||||
-rw-r--r-- | src/sys/socket/mod.rs | 4 | ||||
-rw-r--r-- | src/sys/stat.rs | 25 | ||||
-rw-r--r-- | src/sys/termios.rs | 5 | ||||
-rw-r--r-- | src/sys/timerfd.rs | 1 |
16 files changed, 69 insertions, 5 deletions
diff --git a/src/sys/aio.rs b/src/sys/aio.rs index b63affb8..71a2184d 100644 --- a/src/sys/aio.rs +++ b/src/sys/aio.rs @@ -39,6 +39,7 @@ libc_enum! { /// Mode for `AioCb::fsync`. Controls whether only data or both data and /// metadata are synced. #[repr(i32)] + #[non_exhaustive] pub enum AioFsyncMode { /// do it like `fsync` O_SYNC, @@ -57,6 +58,7 @@ libc_enum! { /// given `aiocb` should be used for a read operation, a write operation, or /// ignored. Has no effect for any other aio functions. #[repr(i32)] + #[non_exhaustive] pub enum LioOpcode { LIO_NOP, LIO_WRITE, diff --git a/src/sys/epoll.rs b/src/sys/epoll.rs index b73af13e..9f68d5ce 100644 --- a/src/sys/epoll.rs +++ b/src/sys/epoll.rs @@ -29,6 +29,7 @@ libc_bitflags!( #[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] #[repr(i32)] +#[non_exhaustive] pub enum EpollOp { EpollCtlAdd = libc::EPOLL_CTL_ADD, EpollCtlDel = libc::EPOLL_CTL_DEL, diff --git a/src/sys/event.rs b/src/sys/event.rs index 8050af31..1f4c1b41 100644 --- a/src/sys/event.rs +++ b/src/sys/event.rs @@ -36,6 +36,7 @@ type type_of_event_filter = i16; libc_enum! { #[cfg_attr(target_os = "netbsd", repr(u32))] #[cfg_attr(not(target_os = "netbsd"), repr(i16))] + #[non_exhaustive] pub enum EventFilter { EVFILT_AIO, /// Returns whenever there is no remaining data in the write buffer diff --git a/src/sys/mman.rs b/src/sys/mman.rs index 58edf086..a8d6d7c9 100644 --- a/src/sys/mman.rs +++ b/src/sys/mman.rs @@ -155,6 +155,7 @@ libc_enum!{ /// /// Used by [`madvise`](./fn.madvise.html). #[repr(i32)] + #[non_exhaustive] pub enum MmapAdvise { /// No further special treatment. This is the default. MADV_NORMAL, diff --git a/src/sys/mod.rs b/src/sys/mod.rs index 43877a12..b43587b8 100644 --- a/src/sys/mod.rs +++ b/src/sys/mod.rs @@ -17,7 +17,7 @@ pub mod epoll; target_os = "openbsd"))] pub mod event; -#[cfg(target_os = "linux")] +#[cfg(any(target_os = "android", target_os = "linux"))] pub mod eventfd; #[cfg(any(target_os = "android", diff --git a/src/sys/pthread.rs b/src/sys/pthread.rs index f7304087..9163c8d1 100644 --- a/src/sys/pthread.rs +++ b/src/sys/pthread.rs @@ -1,3 +1,9 @@ +#[cfg(not(target_os = "redox"))] +use crate::errno::Errno; +#[cfg(not(target_os = "redox"))] +use crate::Result; +#[cfg(not(target_os = "redox"))] +use crate::sys::signal::Signal; use libc::{self, pthread_t}; pub type Pthread = pthread_t; @@ -11,3 +17,19 @@ pub type Pthread = pthread_t; pub fn pthread_self() -> Pthread { unsafe { libc::pthread_self() } } + +/// Send a signal to a thread (see [`pthread_kill(3)`]). +/// +/// If `signal` is `None`, `pthread_kill` will only preform error checking and +/// won't send any signal. +/// +/// [`pthread_kill(3)`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_kill.html +#[cfg(not(target_os = "redox"))] +pub fn pthread_kill<T: Into<Option<Signal>>>(thread: Pthread, signal: T) -> Result<()> { + let sig = match signal.into() { + Some(s) => s as libc::c_int, + None => 0, + }; + let res = unsafe { libc::pthread_kill(thread, sig) }; + Errno::result(res).map(drop) +} diff --git a/src/sys/ptrace/bsd.rs b/src/sys/ptrace/bsd.rs index 141dfbc4..a62881ef 100644 --- a/src/sys/ptrace/bsd.rs +++ b/src/sys/ptrace/bsd.rs @@ -24,6 +24,7 @@ cfg_if! { libc_enum! { #[repr(i32)] /// Ptrace Request enum defining the action to be taken. + #[non_exhaustive] pub enum Request { PT_TRACE_ME, PT_READ_I, diff --git a/src/sys/ptrace/linux.rs b/src/sys/ptrace/linux.rs index 4ac43936..74a23e03 100644 --- a/src/sys/ptrace/linux.rs +++ b/src/sys/ptrace/linux.rs @@ -33,6 +33,7 @@ libc_enum!{ #[cfg_attr(not(any(target_env = "musl", target_os = "android")), repr(u32))] #[cfg_attr(any(target_env = "musl", target_os = "android"), repr(i32))] /// Ptrace Request enum defining the action to be taken. + #[non_exhaustive] pub enum Request { PTRACE_TRACEME, PTRACE_PEEKTEXT, @@ -123,6 +124,7 @@ libc_enum!{ /// Using the ptrace options the tracer can configure the tracee to stop /// at certain events. This enum is used to define those events as defined /// in `man ptrace`. + #[non_exhaustive] pub enum Event { /// Event that stops before a return from fork or clone. PTRACE_EVENT_FORK, diff --git a/src/sys/quota.rs b/src/sys/quota.rs index 19330132..6e34e38d 100644 --- a/src/sys/quota.rs +++ b/src/sys/quota.rs @@ -42,6 +42,7 @@ libc_enum!{ libc_enum!{ /// The scope of the quota. #[repr(i32)] + #[non_exhaustive] pub enum QuotaType { /// Specify a user quota USRQUOTA, @@ -53,6 +54,7 @@ libc_enum!{ libc_enum!{ /// The type of quota format to use. #[repr(i32)] + #[non_exhaustive] pub enum QuotaFmt { /// Use the original quota format. QFMT_VFS_OLD, diff --git a/src/sys/reboot.rs b/src/sys/reboot.rs index 5b376824..be5067a9 100644 --- a/src/sys/reboot.rs +++ b/src/sys/reboot.rs @@ -12,6 +12,7 @@ libc_enum! { /// See [`set_cad_enabled()`](fn.set_cad_enabled.html) for /// enabling/disabling Ctrl-Alt-Delete. #[repr(i32)] + #[non_exhaustive] pub enum RebootMode { RB_HALT_SYSTEM, RB_KEXEC, diff --git a/src/sys/signal.rs b/src/sys/signal.rs index e7b9e88a..0911cfaa 100644 --- a/src/sys/signal.rs +++ b/src/sys/signal.rs @@ -23,6 +23,7 @@ libc_enum!{ // We would prefer to use the libc::c_int alias in the repr attribute. Unfortunately // this is not (yet) possible. #[repr(i32)] + #[non_exhaustive] pub enum Signal { SIGHUP, SIGINT, @@ -396,6 +397,7 @@ libc_bitflags!{ libc_enum! { #[repr(i32)] + #[non_exhaustive] pub enum SigmaskHow { SIG_BLOCK, SIG_UNBLOCK, diff --git a/src/sys/socket/addr.rs b/src/sys/socket/addr.rs index d8bb064c..366c9afd 100644 --- a/src/sys/socket/addr.rs +++ b/src/sys/socket/addr.rs @@ -32,6 +32,7 @@ pub use self::vsock::VsockAddr; /// These constants specify the protocol family to be used /// in [`socket`](fn.socket.html) and [`socketpair`](fn.socketpair.html) #[repr(i32)] +#[non_exhaustive] #[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)] pub enum AddressFamily { /// Local communication (see [`unix(7)`](https://man7.org/linux/man-pages/man7/unix.7.html)) @@ -641,6 +642,7 @@ impl Hash for UnixAddr { /// Represents a socket address #[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] +#[non_exhaustive] pub enum SockAddr { Inet(InetAddr), Unix(UnixAddr), diff --git a/src/sys/socket/mod.rs b/src/sys/socket/mod.rs index 33bdbb62..0f54ef0c 100644 --- a/src/sys/socket/mod.rs +++ b/src/sys/socket/mod.rs @@ -70,6 +70,7 @@ pub use libc::{c_uint, CMSG_SPACE}; /// when creating a socket with [`socket()`](fn.socket.html) #[derive(Clone, Copy, PartialEq, Eq, Debug)] #[repr(i32)] +#[non_exhaustive] pub enum SockType { /// Provides sequenced, reliable, two-way, connection- /// based byte streams. An out-of-band data transmission @@ -94,6 +95,7 @@ pub enum SockType { /// to specify the protocol to use. #[repr(i32)] #[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] +#[non_exhaustive] pub enum SockProtocol { /// TCP protocol ([ip(7)](https://man7.org/linux/man-pages/man7/ip.7.html)) Tcp = libc::IPPROTO_TCP, @@ -490,6 +492,7 @@ impl<'a> Iterator for CmsgIterator<'a> { // // See https://github.com/nix-rust/nix/issues/999 #[derive(Clone, Debug, Eq, PartialEq)] +#[non_exhaustive] pub enum ControlMessageOwned { /// Received version of /// [`ControlMessage::ScmRights`][#enum.ControlMessage.html#variant.ScmRights] @@ -739,6 +742,7 @@ impl ControlMessageOwned { /// /// [Further reading](https://man7.org/linux/man-pages/man3/cmsg.3.html) #[derive(Clone, Copy, Debug, Eq, PartialEq)] +#[non_exhaustive] pub enum ControlMessage<'a> { /// A message of type `SCM_RIGHTS`, containing an array of file /// descriptors passed between processes. diff --git a/src/sys/stat.rs b/src/sys/stat.rs index ba212611..ed62b12d 100644 --- a/src/sys/stat.rs +++ b/src/sys/stat.rs @@ -9,6 +9,7 @@ use std::os::unix::io::RawFd; use crate::sys::time::{TimeSpec, TimeVal}; libc_bitflags!( + /// "File type" flags for `mknod` and related functions. pub struct SFlag: mode_t { S_IFIFO; S_IFCHR; @@ -22,6 +23,7 @@ libc_bitflags!( ); libc_bitflags! { + /// "File mode / permissions" flags. pub struct Mode: mode_t { S_IRWXU; S_IRUSR; @@ -41,11 +43,26 @@ libc_bitflags! { } } +/// Create a special or ordinary file, by pathname. pub fn mknod<P: ?Sized + NixPath>(path: &P, kind: SFlag, perm: Mode, dev: dev_t) -> Result<()> { - let res = path.with_nix_path(|cstr| { - unsafe { - libc::mknod(cstr.as_ptr(), kind.bits | perm.bits() as mode_t, dev) - } + let res = path.with_nix_path(|cstr| unsafe { + libc::mknod(cstr.as_ptr(), kind.bits | perm.bits() as mode_t, dev) + })?; + + Errno::result(res).map(drop) +} + +/// Create a special or ordinary file, relative to a given directory. +#[cfg(not(any(target_os = "ios", target_os = "macos", target_os = "redox")))] +pub fn mknodat<P: ?Sized + NixPath>( + dirfd: RawFd, + path: &P, + kind: SFlag, + perm: Mode, + dev: dev_t, +) -> Result<()> { + let res = path.with_nix_path(|cstr| unsafe { + libc::mknodat(dirfd, cstr.as_ptr(), kind.bits | perm.bits() as mode_t, dev) })?; Errno::result(res).map(drop) diff --git a/src/sys/termios.rs b/src/sys/termios.rs index 9abae9d0..b29d3b98 100644 --- a/src/sys/termios.rs +++ b/src/sys/termios.rs @@ -256,6 +256,7 @@ libc_enum!{ /// B0 is special and will disable the port. #[cfg_attr(all(any(target_os = "ios", target_os = "macos"), target_pointer_width = "64"), repr(u64))] #[cfg_attr(not(all(any(target_os = "ios", target_os = "macos"), target_pointer_width = "64")), repr(u32))] + #[non_exhaustive] pub enum BaudRate { B0, B50, @@ -472,6 +473,7 @@ libc_enum! { /// /// Used as an argument to `tcsetattr()` #[repr(i32)] + #[non_exhaustive] pub enum SetArg { /// The change will occur immediately TCSANOW, @@ -487,6 +489,7 @@ libc_enum! { /// /// Used as an argument to `tcflush()`. #[repr(i32)] + #[non_exhaustive] pub enum FlushArg { /// Flush data that was received but not read TCIFLUSH, @@ -502,6 +505,7 @@ libc_enum! { /// /// Used as an argument to `tcflow()`. #[repr(i32)] + #[non_exhaustive] pub enum FlowArg { /// Suspend transmission TCOOFF, @@ -518,6 +522,7 @@ libc_enum! { libc_enum! { /// Indices into the `termios.c_cc` array for special characters. #[repr(usize)] + #[non_exhaustive] pub enum SpecialCharacterIndices { VDISCARD, #[cfg(any(target_os = "dragonfly", diff --git a/src/sys/timerfd.rs b/src/sys/timerfd.rs index 3e1a1558..5d87b7c2 100644 --- a/src/sys/timerfd.rs +++ b/src/sys/timerfd.rs @@ -58,6 +58,7 @@ libc_enum! { /// The type of the clock used to mark the progress of the timer. For more /// details on each kind of clock, please refer to [timerfd_create(2)](https://man7.org/linux/man-pages/man2/timerfd_create.2.html). #[repr(i32)] + #[non_exhaustive] pub enum ClockId { CLOCK_REALTIME, CLOCK_MONOTONIC, |