diff --git a/src/backend/libc/c.rs b/src/backend/libc/c.rs index 802d638de..98e7c9d20 100644 --- a/src/backend/libc/c.rs +++ b/src/backend/libc/c.rs @@ -329,7 +329,7 @@ mod readwrite_pv64 { #[cfg(target_os = "android")] pub(super) use readwrite_pv64::{preadv64 as preadv, pwritev64 as pwritev}; -// macOS added preadv and pwritev in version 11.0 +// macOS added `preadv` and `pwritev` in version 11.0. #[cfg(apple)] mod readwrite_pv { weakcall! { diff --git a/src/backend/libc/event/epoll.rs b/src/backend/libc/event/epoll.rs index a6087a167..9fba85cc6 100644 --- a/src/backend/libc/event/epoll.rs +++ b/src/backend/libc/event/epoll.rs @@ -312,8 +312,8 @@ pub struct Event { pub data: EventData, } -/// Data assocated with an [`Event`]. This can either be a 64-bit integer value -/// or a pointer which preserves pointer provenance. +/// Data associated with an [`Event`]. This can either be a 64-bit integer +/// value or a pointer which preserves pointer provenance. #[repr(C)] #[derive(Copy, Clone)] pub union EventData { diff --git a/src/backend/libc/fs/inotify.rs b/src/backend/libc/fs/inotify.rs index fea2fad06..20767e228 100644 --- a/src/backend/libc/fs/inotify.rs +++ b/src/backend/libc/fs/inotify.rs @@ -38,7 +38,7 @@ bitflags! { const CLOSE_NOWRITE = c::IN_CLOSE_NOWRITE; /// `IN_CLOSE_WRITE` const CLOSE_WRITE = c::IN_CLOSE_WRITE; - /// `IN_CREATE ` + /// `IN_CREATE` const CREATE = c::IN_CREATE; /// `IN_DELETE` const DELETE = c::IN_DELETE; @@ -105,8 +105,8 @@ pub fn inotify_add_watch( flags: WatchFlags, ) -> io::Result { path.into_with_c_str(|path| { - // SAFETY: The fd and path we are passing is guaranteed valid by the type - // system. + // SAFETY: The fd and path we are passing is guaranteed valid by the + // type system. unsafe { ret_c_int(c::inotify_add_watch( borrowed_fd(inot), diff --git a/src/backend/libc/fs/syscalls.rs b/src/backend/libc/fs/syscalls.rs index a97845e0c..8a3a55d2e 100644 --- a/src/backend/libc/fs/syscalls.rs +++ b/src/backend/libc/fs/syscalls.rs @@ -839,8 +839,8 @@ pub(crate) fn utimensat( )); } - // `setattrlistat` was introduced in 10.13 along with `utimensat`, so if - // we don't have `utimensat`, we don't have `setattrlistat` either. + // `setattrlistat` was introduced in 10.13 along with `utimensat`, so + // if we don't have `utimensat`, we don't have `setattrlistat` either. // Emulate it using `fork`, and `fchdir` and [`setattrlist`]. // // [`setattrlist`]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/setattrlist.2.html @@ -1565,7 +1565,8 @@ pub(crate) fn fallocate( assert!(mode.is_empty()); let err = unsafe { c::posix_fallocate(borrowed_fd(fd), offset, len) }; - // `posix_fallocate` returns its error status rather than using `errno`. + // `posix_fallocate` returns its error status rather than using + // `errno`. if err == 0 { Ok(()) } else { diff --git a/src/backend/libc/fs/types.rs b/src/backend/libc/fs/types.rs index 29180042d..cdb96efae 100644 --- a/src/backend/libc/fs/types.rs +++ b/src/backend/libc/fs/types.rs @@ -213,9 +213,9 @@ bitflags! { /// Similar to `ACCMODE`, but just includes the read/write flags, and /// no other flags. /// - /// Some implementations include `O_PATH` in `O_ACCMODE`, when + /// On some platforms, `PATH` may be included in `ACCMODE`, when /// sometimes we really just want the read/write bits. Caution is - /// indicated, as the presence of `O_PATH` may mean that the read/write + /// indicated, as the presence of `PATH` may mean that the read/write /// bits don't have their usual meaning. const RWMODE = bitcast!(c::O_RDONLY | c::O_WRONLY | c::O_RDWR); @@ -638,13 +638,13 @@ bitflags! { #[repr(transparent)] #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub struct SealFlags: u32 { - /// `F_SEAL_SEAL`. + /// `F_SEAL_SEAL` const SEAL = bitcast!(c::F_SEAL_SEAL); - /// `F_SEAL_SHRINK`. + /// `F_SEAL_SHRINK` const SHRINK = bitcast!(c::F_SEAL_SHRINK); - /// `F_SEAL_GROW`. + /// `F_SEAL_GROW` const GROW = bitcast!(c::F_SEAL_GROW); - /// `F_SEAL_WRITE`. + /// `F_SEAL_WRITE` const WRITE = bitcast!(c::F_SEAL_WRITE); /// `F_SEAL_FUTURE_WRITE` (since Linux 5.1) #[cfg(linux_kernel)] diff --git a/src/backend/libc/net/read_sockaddr.rs b/src/backend/libc/net/read_sockaddr.rs index 604f24928..273e9424e 100644 --- a/src/backend/libc/net/read_sockaddr.rs +++ b/src/backend/libc/net/read_sockaddr.rs @@ -139,9 +139,9 @@ pub(crate) unsafe fn read_sockaddr( // Trim off unused bytes from the end of `path_bytes`. let path_bytes = if cfg!(target_os = "freebsd") { - // FreeBSD sometimes sets the length to longer than the length - // of the NUL-terminated string. Find the NUL and truncate the - // string accordingly. + // FreeBSD sometimes sets the length to longer than the + // length of the NUL-terminated string. Find the NUL and + // truncate the string accordingly. &decode.sun_path[..decode .sun_path .iter() diff --git a/src/backend/libc/net/sockopt.rs b/src/backend/libc/net/sockopt.rs index 2319c7cda..39e4ee93b 100644 --- a/src/backend/libc/net/sockopt.rs +++ b/src/backend/libc/net/sockopt.rs @@ -70,8 +70,7 @@ use alloc::string::String; use c::TCP_KEEPALIVE as TCP_KEEPIDLE; #[cfg(not(any(apple, target_os = "openbsd", target_os = "haiku", target_os = "nto")))] use c::TCP_KEEPIDLE; -use core::mem::size_of; -use core::mem::MaybeUninit; +use core::mem::{size_of, MaybeUninit}; use core::time::Duration; #[cfg(windows)] use windows_sys::Win32::Foundation::BOOL; diff --git a/src/backend/libc/pty/syscalls.rs b/src/backend/libc/pty/syscalls.rs index cf566045d..86f3a6c46 100644 --- a/src/backend/libc/pty/syscalls.rs +++ b/src/backend/libc/pty/syscalls.rs @@ -67,7 +67,8 @@ pub(crate) fn ptsname(fd: BorrowedFd<'_>, mut buffer: Vec) -> io::Result { @@ -87,7 +88,8 @@ pub(crate) fn ptsname(fd: BorrowedFd<'_>, mut buffer: Vec) -> io::Result u32 { /// Create a `Vdso` value by parsing the vDSO at the `sysinfo_ehdr` address. fn init_from_sysinfo_ehdr() -> Option { - // SAFETY: the auxv initialization code does extensive checks to ensure + // SAFETY: The auxv initialization code does extensive checks to ensure // that the value we get really is an `AT_SYSINFO_EHDR` value from the // kernel. unsafe { @@ -106,9 +106,9 @@ fn init_from_sysinfo_ehdr() -> Option { vdso.load_end = vdso.base_plus(phdr.p_offset.checked_add(phdr.p_memsz)?)?; vdso.pv_offset = phdr.p_offset.wrapping_sub(phdr.p_vaddr); } else if phdr.p_type == PT_DYNAMIC { - // If `p_offset` is zero, it's more likely that we're looking at memory - // that has been zeroed than that the kernel has somehow aliased the - // `Ehdr` and the `Elf_Dyn` array. + // If `p_offset` is zero, it's more likely that we're looking + // at memory that has been zeroed than that the kernel has + // somehow aliased the `Ehdr` and the `Elf_Dyn` array. if phdr.p_offset < size_of::() { return None; } @@ -117,9 +117,9 @@ fn init_from_sysinfo_ehdr() -> Option { .as_ptr(); num_dyn = phdr.p_memsz / size_of::(); } else if phdr.p_type == PT_INTERP || phdr.p_type == PT_GNU_RELRO { - // Don't trust any ELF image that has an “interpreter” or that uses - // RELRO, which is likely to be a user ELF image rather and not the - // kernel vDSO. + // Don't trust any ELF image that has an “interpreter” or + // that uses RELRO, which is likely to be a user ELF image + // rather and not the kernel vDSO. return None; } } @@ -176,8 +176,8 @@ fn init_from_sysinfo_ehdr() -> Option { } i = i.checked_add(1)?; } - // The upstream code checks `symstrings`, `symtab`, and `hash` for null; - // here, `check_raw_pointer` has already done that. + // The upstream code checks `symstrings`, `symtab`, and `hash` for + // null; here, `check_raw_pointer` has already done that. if vdso.verdef.is_null() { vdso.versym = null(); diff --git a/src/backend/linux_raw/vdso_wrappers.rs b/src/backend/linux_raw/vdso_wrappers.rs index 1ff50415b..1bbffaca8 100644 --- a/src/backend/linux_raw/vdso_wrappers.rs +++ b/src/backend/linux_raw/vdso_wrappers.rs @@ -36,8 +36,8 @@ use { #[inline] pub(crate) fn clock_gettime(which_clock: ClockId) -> __kernel_timespec { // SAFETY: `CLOCK_GETTIME` contains either null or the address of a - // function with an ABI like libc `clock_gettime`, and calling it has - // the side effect of writing to the result buffer, and no others. + // function with an ABI like libc `clock_gettime`, and calling it has the + // side effect of writing to the result buffer, and no others. unsafe { let mut result = MaybeUninit::<__kernel_timespec>::uninit(); let callee = match transmute(CLOCK_GETTIME.load(Relaxed)) { @@ -78,8 +78,8 @@ pub(crate) fn clock_gettime_dynamic(which_clock: DynamicClockId<'_>) -> io::Resu }; // SAFETY: `CLOCK_GETTIME` contains either null or the address of a - // function with an ABI like libc `clock_gettime`, and calling it has - // the side effect of writing to the result buffer, and no others. + // function with an ABI like libc `clock_gettime`, and calling it has the + // side effect of writing to the result buffer, and no others. unsafe { const EINVAL: c::c_int = -(c::EINVAL as c::c_int); let mut timespec = MaybeUninit::::uninit(); @@ -234,8 +234,8 @@ pub(super) type SyscallType = unsafe extern "C" fn(); #[cold] fn init_clock_gettime() -> ClockGettimeType { init(); - // SAFETY: Load the function address from static storage that we - // just initialized. + // SAFETY: Load the function address from static storage that we just + // initialized. unsafe { transmute(CLOCK_GETTIME.load(Relaxed)) } } @@ -244,8 +244,8 @@ fn init_clock_gettime() -> ClockGettimeType { #[cold] fn init_syscall() -> SyscallType { init(); - // SAFETY: Load the function address from static storage that we - // just initialized. + // SAFETY: Load the function address from static storage that we just + // initialized. unsafe { transmute(SYSCALL.load(Relaxed)) } } @@ -345,9 +345,9 @@ rustix_int_0x80: fn minimal_init() { // SAFETY: Store default function addresses in static storage so that if we - // end up making any system calls while we read the vDSO, they'll work. - // If the memory happens to already be initialized, this is redundant, but - // not harmful. + // end up making any system calls while we read the vDSO, they'll work. If + // the memory happens to already be initialized, this is redundant, but not + // harmful. unsafe { #[cfg(feature = "time")] { @@ -381,9 +381,9 @@ fn init() { if let Some(vdso) = vdso::Vdso::new() { #[cfg(feature = "time")] { - // Look up the platform-specific `clock_gettime` symbol as documented - // [here], except on 32-bit platforms where we look up the - // `64`-suffixed variant and fail if we don't find it. + // Look up the platform-specific `clock_gettime` symbol as + // documented [here], except on 32-bit platforms where we look up + // the `64`-suffixed variant and fail if we don't find it. // // [here]: https://man7.org/linux/man-pages/man7/vdso.7.html #[cfg(target_arch = "x86_64")] @@ -408,8 +408,8 @@ fn init() { #[cfg(target_pointer_width = "64")] let ok = true; - // On some 32-bit platforms, the 64-bit `clock_gettime` symbols are not - // available on older kernel versions. + // On some 32-bit platforms, the 64-bit `clock_gettime` symbols are + // not available on older kernel versions. #[cfg(any( target_arch = "arm", target_arch = "mips", @@ -421,9 +421,9 @@ fn init() { if ok { assert!(!ptr.is_null()); - // SAFETY: Store the computed function addresses in static storage - // so that we don't need to compute it again (but if we do, it - // doesn't hurt anything). + // SAFETY: Store the computed function addresses in static + // storage so that we don't need to compute it again (but if + // we do, it doesn't hurt anything). unsafe { CLOCK_GETTIME.store(ptr.cast(), Relaxed); } diff --git a/src/cstr.rs b/src/cstr.rs index d32436e18..17a8c8b77 100644 --- a/src/cstr.rs +++ b/src/cstr.rs @@ -44,8 +44,9 @@ macro_rules! cstr { // call `from_bytes_with_nul_unchecked`, which as of this writing // is defined as `#[inline]` and completely optimizes away. // - // SAFETY: We have manually checked that the string does not contain - // embedded NULs above, and we append or own NUL terminator here. + // SAFETY: We have manually checked that the string does not + // contain embedded NULs above, and we append or own NUL terminator + // here. unsafe { $crate::ffi::CStr::from_bytes_with_nul_unchecked(concat!($str, "\0").as_bytes()) } diff --git a/src/fs/abs.rs b/src/fs/abs.rs index f57bd00fe..ff93fe74e 100644 --- a/src/fs/abs.rs +++ b/src/fs/abs.rs @@ -129,7 +129,8 @@ fn _readlink(path: &CStr, mut buffer: Vec) -> io::Result { buffer.resize(nread, 0_u8); return Ok(CString::new(buffer).unwrap()); } - buffer.reserve(1); // use `Vec` reallocation strategy to grow capacity exponentially + // Use `Vec` reallocation strategy to grow capacity exponentially. + buffer.reserve(1); buffer.resize(buffer.capacity(), 0_u8); } } diff --git a/src/fs/at.rs b/src/fs/at.rs index 0434b56ef..d8d746bda 100644 --- a/src/fs/at.rs +++ b/src/fs/at.rs @@ -104,8 +104,8 @@ fn _readlinkat(dirfd: BorrowedFd<'_>, path: &CStr, mut buffer: Vec) -> io::R debug_assert!(nread <= buffer.capacity()); if nread < buffer.capacity() { - // SAFETY: From the [documentation]: - // "On success, these calls return the number of bytes placed in buf." + // SAFETY: From the [documentation]: "On success, these calls + // return the number of bytes placed in buf." // // [documentation]: https://man7.org/linux/man-pages/man2/readlinkat.2.html unsafe { diff --git a/src/fs/fd.rs b/src/fs/fd.rs index 94de43daa..6b8992ac2 100644 --- a/src/fs/fd.rs +++ b/src/fs/fd.rs @@ -107,8 +107,8 @@ pub fn tell(fd: Fd) -> io::Result { /// `fchmod(fd, mode)`—Sets open file or directory permissions. /// -/// This implementation does not support `O_PATH` file descriptors, even on -/// platforms where the host libc emulates it. +/// This implementation does not support [`OFlags::PATH`] file descriptors, +/// even on platforms where the host libc emulates it. /// /// # References /// - [POSIX] diff --git a/src/ioctl/mod.rs b/src/ioctl/mod.rs index fbcbb4df8..2d9fe6d61 100644 --- a/src/ioctl/mod.rs +++ b/src/ioctl/mod.rs @@ -86,16 +86,16 @@ pub unsafe fn ioctl(fd: F, mut ioctl: I) -> Result let request = I::OPCODE.raw(); let arg = ioctl.as_ptr(); - // SAFETY: The variant of `Ioctl` asserts that this is a valid IOCTL call to - // make. + // SAFETY: The variant of `Ioctl` asserts that this is a valid IOCTL call + // to make. let output = if I::IS_MUTATING { _ioctl(fd, request, arg)? } else { _ioctl_readonly(fd, request, arg)? }; - // SAFETY: The variant of `Ioctl` asserts that this is a valid pointer to the - // output data. + // SAFETY: The variant of `Ioctl` asserts that this is a valid pointer to + // the output data. I::output_from_ptr(output, arg) } @@ -230,7 +230,8 @@ impl Opcode { /// Create a new non-mutating opcode from a group, a number and the type of /// data. /// - /// This corresponds to the C macro `_IO(group, number)` when `T` is zero sized. + /// This corresponds to the C macro `_IO(group, number)` when `T` is zero + /// sized. #[cfg(any(linux_kernel, bsd))] #[inline] pub const fn none(group: u8, number: u8) -> Self { diff --git a/src/ioctl/patterns.rs b/src/ioctl/patterns.rs index ff6f478ff..b11cf1b27 100644 --- a/src/ioctl/patterns.rs +++ b/src/ioctl/patterns.rs @@ -200,7 +200,8 @@ impl CompileTimeOpcode for ReadWriteOpcode /// Provides a `None` code at compile time. /// -/// This corresponds to the C macro `_IO(GROUP, NUM)` when `Data` is zero sized. +/// This corresponds to the C macro `_IO(GROUP, NUM)` when `Data` is zero +/// sized. #[cfg(any(linux_kernel, bsd))] pub struct NoneOpcode(Data); diff --git a/src/net/sockopt.rs b/src/net/sockopt.rs index aa8562d9b..30e37862e 100644 --- a/src/net/sockopt.rs +++ b/src/net/sockopt.rs @@ -758,7 +758,8 @@ pub fn set_ip_add_membership( backend::net::sockopt::set_ip_add_membership(fd.as_fd(), multiaddr, interface) } -/// `setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, multiaddr, address, ifindex)` +/// `setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, multiaddr, address, +/// ifindex)` /// /// This is similar to [`set_ip_add_membership_with_ifindex`] but additionally /// allows a `ifindex` value to be given. diff --git a/src/path/arg.rs b/src/path/arg.rs index 3b0ad91ae..dc0893e4b 100644 --- a/src/path/arg.rs +++ b/src/path/arg.rs @@ -1039,7 +1039,7 @@ where buf_ptr.add(bytes.len()).write(0); } - // SAFETY: we just wrote the bytes above and they will remain valid for the + // SAFETY: We just wrote the bytes above and they will remain valid for the // duration of `f` b/c buf doesn't get dropped until the end of the // function. match CStr::from_bytes_with_nul(unsafe { slice::from_raw_parts(buf_ptr, bytes.len() + 1) }) { @@ -1078,15 +1078,15 @@ where return Err(io::Errno::NAMETOOLONG); } - // SAFETY: `bytes.len() < LARGE_PATH_BUFFER_SIZE` which means we have space - // for `bytes.len() + 1` u8s: + // SAFETY: `bytes.len() < LARGE_PATH_BUFFER_SIZE` which means we have + // space for `bytes.len() + 1` u8s: unsafe { ptr::copy_nonoverlapping(bytes.as_ptr(), buf_ptr, bytes.len()); buf_ptr.add(bytes.len()).write(0); } - // SAFETY: we just wrote the bytes above and they will remain valid for the - // duration of `f` b/c buf doesn't get dropped until the end of the + // SAFETY: We just wrote the bytes above and they will remain valid for + // the duration of `f` b/c buf doesn't get dropped until the end of the // function. match CStr::from_bytes_with_nul(unsafe { slice::from_raw_parts(buf_ptr, bytes.len() + 1) }) { diff --git a/src/pid.rs b/src/pid.rs index 3911e4c7a..5f2b9ad2a 100644 --- a/src/pid.rs +++ b/src/pid.rs @@ -26,8 +26,7 @@ impl Pid { /// Converts a `RawPid` into a `Pid`. /// - /// Returns `Some` for strictly positive `RawPid`s. Otherwise, returns - /// `None`. + /// Returns `Some` for positive `RawPid`s. Otherwise, returns `None`. /// /// This is safe because a `Pid` is a number without any guarantees for the /// kernel. Non-child `Pid`s are always racy for any syscalls, but can only @@ -39,18 +38,18 @@ impl Pid { #[inline] pub const fn from_raw(raw: RawPid) -> Option { if raw > 0 { - // SAFETY: raw > 0. + // SAFETY: We just checked that `raw > 0`. unsafe { Some(Self::from_raw_unchecked(raw)) } } else { None } } - /// Converts a known strictly positive `RawPid` into a `Pid`. + /// Converts a known positive `RawPid` into a `Pid`. /// /// # Safety /// - /// The caller must guarantee `raw` is strictly positive. + /// The caller must guarantee `raw` is positive. #[inline] pub const unsafe fn from_raw_unchecked(raw: RawPid) -> Self { debug_assert!(raw > 0); diff --git a/src/process/chdir.rs b/src/process/chdir.rs index b110afef8..03601a5ad 100644 --- a/src/process/chdir.rs +++ b/src/process/chdir.rs @@ -75,7 +75,8 @@ fn _getcwd(mut buffer: Vec) -> io::Result { // - [POSIX definition 3.375: String]: "A contiguous sequence of bytes // terminated by and including the first null byte." // - // Thus, there will be a single NUL byte at the end of the string. + // Thus, there will be a single NUL byte at the end of the + // string. // // [POSIX definition 3.375: String]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_375 unsafe { diff --git a/src/process/id.rs b/src/process/id.rs index 4ed33a6c8..1a49dc539 100644 --- a/src/process/id.rs +++ b/src/process/id.rs @@ -225,7 +225,8 @@ pub fn getgroups() -> io::Result> { buffer.resize(ngroups, Gid::ROOT); return Ok(buffer); } - buffer.reserve(1); // use `Vec` reallocation strategy to grow capacity exponentially + // Use `Vec` reallocation strategy to grow capacity exponentially. + buffer.reserve(1); buffer.resize(buffer.capacity(), Gid::ROOT); } } diff --git a/src/process/ioctl.rs b/src/process/ioctl.rs index 3c9d90255..5afc76609 100644 --- a/src/process/ioctl.rs +++ b/src/process/ioctl.rs @@ -10,7 +10,7 @@ use crate::{backend, io, ioctl}; use backend::c; use backend::fd::AsFd; -/// `ioctl(fd, TIOCSCTTY, 0)`—Sets the controlling terminal for the processs. +/// `ioctl(fd, TIOCSCTTY, 0)`—Sets the controlling terminal for the process. /// /// # References /// - [Linux] diff --git a/src/process/procctl.rs b/src/process/procctl.rs index 5225f16f7..b5b796ea7 100644 --- a/src/process/procctl.rs +++ b/src/process/procctl.rs @@ -300,7 +300,8 @@ bitflags! { const REAPER = 4; /// The reported process is in the zombie state. const ZOMBIE = 8; - /// The reported process is stopped by SIGSTOP/SIGTSTP. + /// The reported process is stopped by + /// [`Signal::Stop`]/[`Signal::Tstp`]. const STOPPED = 16; /// The reported process is in the process of exiting. const EXITING = 32; diff --git a/src/pty.rs b/src/pty.rs index a63fbfeef..23162936b 100644 --- a/src/pty.rs +++ b/src/pty.rs @@ -142,8 +142,8 @@ pub fn unlockpt(fd: Fd) -> io::Result<()> { /// /// On Linux, calling this function has no effect, as the kernel is expected to /// grant the appropriate access. On all other platorms, this function has -/// unspecified behavior if the calling process has a `SIGCHLD` signal handler -/// installed. +/// unspecified behavior if the calling process has a [`Signal::Child`] signal +/// handler installed. /// /// # References /// - [POSIX] @@ -153,6 +153,7 @@ pub fn unlockpt(fd: Fd) -> io::Result<()> { /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/grantpt.html /// [Linux]: https://man7.org/linux/man-pages/man3/grantpt.3.html /// [glibc]: https://www.gnu.org/software/libc/manual/html_node/Allocation.html#index-grantpt +/// [`Signal::Child`]: crate::process::Signal::Child #[inline] pub fn grantpt(fd: Fd) -> io::Result<()> { #[cfg(not(linux_kernel))] diff --git a/src/runtime.rs b/src/runtime.rs index 2cb0eba54..687b4f8cd 100644 --- a/src/runtime.rs +++ b/src/runtime.rs @@ -188,7 +188,7 @@ pub const EXIT_FAILURE: i32 = backend::c::EXIT_FAILURE; /// Return fields from the main executable segment headers ("phdrs") relevant /// to initializing TLS provided to the program at startup. /// -/// `addr` will always be non-null, even when the TLS data is absent, ao that +/// `addr` will always be non-null, even when the TLS data is absent, so that /// the `addr` and `file_size` parameters are suitable for creating a slice /// with `slice::from_raw_parts`. #[inline] diff --git a/src/system.rs b/src/system.rs index ab34818ee..1ceb5afaa 100644 --- a/src/system.rs +++ b/src/system.rs @@ -157,26 +157,23 @@ pub fn sethostname(name: &[u8]) -> io::Result<()> { backend::system::syscalls::sethostname(name) } -/// Reboot command to be used with [`reboot`]. -/// -/// See [`reboot`] documentation for more info -/// -/// [`reboot`]: crate::system::reboot +/// Reboot command for use use with [`reboot`]. #[cfg(target_os = "linux")] #[derive(Copy, Clone, Debug, Eq, PartialEq)] #[repr(i32)] #[non_exhaustive] pub enum RebootCommand { - /// CAD is disabled. - /// This means that the CAD keystroke will cause a SIGINT signal to be sent to init (process 1), - /// whereupon this process may decide upon a proper action (maybe: kill all processes, sync, reboot). /// Disables the Ctrl-Alt-Del keystroke. /// - /// When disabled, the keystroke will send a SIGINT signal to pid 1 + /// When disabled, the keystroke will send a [`Signal::Int`] to pid 1. + /// + /// [`Signal::Int`]: crate::process::Signal::Int CadOff = c::LINUX_REBOOT_CMD_CAD_OFF, /// Enables the Ctrl-Alt-Del keystroke. /// - /// When enabled, the keystroke will trigger LINUX_REBOOT_CMD_RESTART + /// When enabled, the keystroke will trigger a [`Restart`]. + /// + /// [`Restart`]: Self::Restart CadOn = c::LINUX_REBOOT_CMD_CAD_ON, /// Prints the message "System halted" and halts the system Halt = c::LINUX_REBOOT_CMD_HALT, @@ -184,7 +181,8 @@ pub enum RebootCommand { /// /// [`kexec_load`]: https://man7.org/linux/man-pages/man2/kexec_load.2.html Kexec = c::LINUX_REBOOT_CMD_KEXEC, - /// Prints the message "Power down.", stops the system and tries to remove all power + /// Prints the message "Power down.", stops the system and tries to remove + /// all power PowerOff = c::LINUX_REBOOT_CMD_POWER_OFF, /// Prints the message "Restarting system." and triggers a restart Restart = c::LINUX_REBOOT_CMD_RESTART, @@ -192,9 +190,10 @@ pub enum RebootCommand { SwSuspend = c::LINUX_REBOOT_CMD_SW_SUSPEND, } -/// `reboot`—Reboot or enable/disable Ctrl-Alt-Del +/// `reboot`—Reboot the system or enable/disable Ctrl-Alt-Del /// -/// The reboot syscall, despite the name, can actually do much more than reboot. +/// The reboot syscall, despite the name, can actually do much more than +/// reboot. /// /// Among other things it can /// - Restart, Halt, Power Off and Suspend the system @@ -202,7 +201,8 @@ pub enum RebootCommand { /// - Execute other kernels /// - Terminate init inside PID namespaces /// -/// It is highly reccomended to carefully read the kernel documentation before calling this function. +/// It is highly recommended to carefully read the kernel documentation before +/// calling this function. /// /// # References /// - [Linux] diff --git a/src/termios/tty.rs b/src/termios/tty.rs index 56aab9fcf..6a6aaf61a 100644 --- a/src/termios/tty.rs +++ b/src/termios/tty.rs @@ -51,11 +51,13 @@ fn _ttyname(dirfd: BorrowedFd<'_>, mut buffer: Vec) -> io::Result { loop { match backend::termios::syscalls::ttyname(dirfd, buffer.spare_capacity_mut()) { Err(io::Errno::RANGE) => { - buffer.reserve(buffer.capacity() + 1); // use `Vec` reallocation strategy to grow capacity exponentially + // Use `Vec` reallocation strategy to grow capacity + // exponentially. + buffer.reserve(buffer.capacity() + 1); } Ok(len) => { - // SAFETY: assume the backend returns the length of the string excluding the - // NUL. + // SAFETY: Assume the backend returns the length of the string + // excluding the NUL. unsafe { buffer.set_len(len + 1); } @@ -67,7 +69,8 @@ fn _ttyname(dirfd: BorrowedFd<'_>, mut buffer: Vec) -> io::Result { // - [POSIX definition 3.375: String]: "A contiguous sequence of bytes // terminated by and including the first null byte." // - // Thus, there will be a single NUL byte at the end of the string. + // Thus, there will be a single NUL byte at the end of the + // string. // // [POSIX definition 3.271: Pathname]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_271 // [POSIX definition 3.375: String]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_375 diff --git a/src/termios/types.rs b/src/termios/types.rs index 33a73767a..02f06268f 100644 --- a/src/termios/types.rs +++ b/src/termios/types.rs @@ -1277,8 +1277,8 @@ fn termios_layouts() { check_renamed_struct_renamed_field!(Termios, termios, local_modes, c_lflag); check_renamed_struct_renamed_field!(Termios, termios, special_codes, c_cc); - // On everything except PowerPC, `termios` matches `termios2` except for - // the addition of `c_ispeed` and `c_ospeed`. + // On everything except PowerPC, `termios` matches `termios2` except + // for the addition of `c_ispeed` and `c_ospeed`. #[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))] const_assert_eq!( memoffset::offset_of!(Termios, input_speed), diff --git a/tests/fs/file.rs b/tests/fs/file.rs index d8ca3e11f..83b35cc44 100644 --- a/tests/fs/file.rs +++ b/tests/fs/file.rs @@ -183,7 +183,7 @@ fn test_setfl_append() { rustix::fs::fcntl_setfl(&file, OFlags::APPEND).unwrap(); assert_eq!(rustix::io::write(&file, b"xyz"), Ok(3)); - // Check the final contents. + // Check the resulting contents. let file = rustix::fs::open(tmp.path().join("test.file"), OFlags::RDONLY, Mode::empty()).unwrap(); let mut buf = [0_u8; 32]; diff --git a/tests/io/read_write.rs b/tests/io/read_write.rs index 0023cf4c2..82b8c9d3a 100644 --- a/tests/io/read_write.rs +++ b/tests/io/read_write.rs @@ -25,7 +25,8 @@ fn test_readwrite_pv() { { pwritev(&foo, &[IoSlice::new(b"hello")], 200).unwrap(); } - // macOS only has pwritev in newer versions; allow it to fail with `ENOSYS`. + // macOS only has `pwritev` in newer versions; allow it to fail with + // `Errno::NOSYS`. #[cfg(apple)] { match pwritev(&foo, &[IoSlice::new(b"hello")], 200) { diff --git a/tests/system/reboot.rs b/tests/system/reboot.rs index fe5c4e80f..2bc146c57 100644 --- a/tests/system/reboot.rs +++ b/tests/system/reboot.rs @@ -1,11 +1,9 @@ #[test] #[cfg(feature = "thread")] fn test_reboot() { - use rustix::{ - io::Errno, - system::{self, RebootCommand}, - thread::{self, CapabilityFlags}, - }; + use rustix::io::Errno; + use rustix::system::{self, RebootCommand}; + use rustix::thread::{self, CapabilityFlags}; let mut capabilities = thread::capabilities(None).expect("Failed to get capabilities"); @@ -13,6 +11,7 @@ fn test_reboot() { thread::set_capabilities(None, capabilities).expect("Failed to set capabilities"); - // The reboot syscall requires the CAP_SYS_BOOT permission to be called, otherwise EPERM is returned + // The reboot syscall requires the `CapabilityFlags::SYS_BOOT` permission + // to be called, otherwise [`Errno::PERM`] is returned assert_eq!(system::reboot(RebootCommand::Restart), Err(Errno::PERM)); }