Skip to content

Commit a0307df

Browse files
authored
Merge branch 'nix-rust:master' into master
2 parents 39c45bc + 299feba commit a0307df

File tree

9 files changed

+212
-71
lines changed

9 files changed

+212
-71
lines changed

.github/workflows/ci.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,15 @@ jobs:
8989
armv7-unknown-linux-gnueabihf,
9090
i686-unknown-linux-gnu,
9191
i686-unknown-linux-musl,
92-
mips-unknown-linux-gnu,
93-
mips64-unknown-linux-gnuabi64,
94-
mips64el-unknown-linux-gnuabi64,
95-
mipsel-unknown-linux-gnu,
92+
93+
# Disable MIPS CIs, see https://github.com/nix-rust/nix/issues/2593
94+
# for detailed info.
95+
#
96+
# mips-unknown-linux-gnu,
97+
# mips64-unknown-linux-gnuabi64,
98+
# mips64el-unknown-linux-gnuabi64,
99+
# mipsel-unknown-linux-gnu,
100+
96101
powerpc64le-unknown-linux-gnu,
97102
loongarch64-unknown-linux-gnu,
98103
]

src/pty.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -334,9 +334,9 @@ feature! {
334334
/// # Safety
335335
///
336336
/// In a multithreaded program, only [async-signal-safe] functions like `pause`
337-
/// and `_exit` may be called by the child (the parent isn't restricted). Note
338-
/// that memory allocation may **not** be async-signal-safe and thus must be
339-
/// prevented.
337+
/// and `_exit` may be called by the child (the parent isn't restricted) until
338+
/// a call of `execve(2)`. Note that memory allocation may **not** be
339+
/// async-signal-safe and thus must be prevented.
340340
///
341341
/// Those functions are only a small subset of your operating system's API, so
342342
/// special care must be taken to only invoke code you can control and audit.

src/spawn.rs

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -361,30 +361,40 @@ unsafe fn to_exec_array<S: AsRef<CStr>>(args: &[S]) -> Vec<*mut libc::c_char> {
361361

362362
/// Create a new child process from the specified process image. See
363363
/// [posix_spawn](https://pubs.opengroup.org/onlinepubs/9699919799/functions/posix_spawn.html).
364-
pub fn posix_spawn<SA: AsRef<CStr>, SE: AsRef<CStr>>(
365-
path: &CStr,
364+
pub fn posix_spawn<P, SA, SE>(
365+
path: &P,
366366
file_actions: &PosixSpawnFileActions,
367367
attr: &PosixSpawnAttr,
368368
args: &[SA],
369369
envp: &[SE],
370-
) -> Result<Pid> {
370+
) -> Result<Pid>
371+
where
372+
P: NixPath + ?Sized,
373+
SA: AsRef<CStr>,
374+
SE: AsRef<CStr>,
375+
{
371376
let mut pid = 0;
372377

373-
let res = unsafe {
378+
let ret = unsafe {
374379
let args_p = to_exec_array(args);
375380
let env_p = to_exec_array(envp);
376381

377-
libc::posix_spawn(
378-
&mut pid as *mut libc::pid_t,
379-
path.as_ptr(),
380-
&file_actions.fa as *const libc::posix_spawn_file_actions_t,
381-
&attr.attr as *const libc::posix_spawnattr_t,
382-
args_p.as_ptr(),
383-
env_p.as_ptr(),
384-
)
382+
path.with_nix_path(|c_str| {
383+
libc::posix_spawn(
384+
&mut pid as *mut libc::pid_t,
385+
c_str.as_ptr(),
386+
&file_actions.fa as *const libc::posix_spawn_file_actions_t,
387+
&attr.attr as *const libc::posix_spawnattr_t,
388+
args_p.as_ptr(),
389+
env_p.as_ptr(),
390+
)
391+
})?
385392
};
386393

387-
Errno::result(res)?;
394+
if ret != 0 {
395+
return Err(Errno::from_raw(ret));
396+
}
397+
388398
Ok(Pid::from_raw(pid))
389399
}
390400

@@ -399,7 +409,7 @@ pub fn posix_spawnp<SA: AsRef<CStr>, SE: AsRef<CStr>>(
399409
) -> Result<Pid> {
400410
let mut pid = 0;
401411

402-
let res = unsafe {
412+
let ret = unsafe {
403413
let args_p = to_exec_array(args);
404414
let env_p = to_exec_array(envp);
405415

@@ -413,6 +423,9 @@ pub fn posix_spawnp<SA: AsRef<CStr>, SE: AsRef<CStr>>(
413423
)
414424
};
415425

416-
Errno::result(res)?;
426+
if ret != 0 {
427+
return Err(Errno::from_raw(ret));
428+
}
429+
417430
Ok(Pid::from_raw(pid))
418431
}

src/sys/aio.rs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -455,10 +455,9 @@ impl<'a> AioFsync<'a> {
455455
/// * `fd`: File descriptor to sync.
456456
/// * `mode`: Whether to sync file metadata too, or just data.
457457
/// * `prio`: If POSIX Prioritized IO is supported, then the
458-
/// operation will be prioritized at the process's
459-
/// priority level minus `prio`.
460-
/// * `sigev_notify`: Determines how you will be notified of event
461-
/// completion.
458+
/// operation will be prioritized at the process's priority level minus
459+
/// `prio`.
460+
/// * `sigev_notify`: Determines how you will be notified of event completion.
462461
pub fn new(
463462
fd: BorrowedFd<'a>,
464463
mode: AioFsyncMode,
@@ -573,11 +572,9 @@ impl<'a> AioRead<'a> {
573572
/// * `fd`: File descriptor to read from
574573
/// * `offs`: File offset
575574
/// * `buf`: A memory buffer. It must outlive the `AioRead`.
576-
/// * `prio`: If POSIX Prioritized IO is supported, then the
577-
/// operation will be prioritized at the process's
578-
/// priority level minus `prio`
579-
/// * `sigev_notify`: Determines how you will be notified of event
580-
/// completion.
575+
/// * `prio`: If POSIX Prioritized IO is supported, then the operation
576+
/// will be prioritized at the process's priority level minus `prio`
577+
/// * `sigev_notify`: Determines how you will be notified of event completion.
581578
pub fn new(
582579
fd: BorrowedFd<'a>,
583580
offs: off_t,
@@ -805,11 +802,9 @@ impl<'a> AioWrite<'a> {
805802
/// * `fd`: File descriptor to write to
806803
/// * `offs`: File offset
807804
/// * `buf`: A memory buffer. It must outlive the `AioWrite`.
808-
/// * `prio`: If POSIX Prioritized IO is supported, then the
809-
/// operation will be prioritized at the process's
810-
/// priority level minus `prio`
811-
/// * `sigev_notify`: Determines how you will be notified of event
812-
/// completion.
805+
/// * `prio`: If POSIX Prioritized IO is supported, then the operation
806+
/// will be prioritized at the process's priority level minus `prio`
807+
/// * `sigev_notify`: Determines how you will be notified of event completion.
813808
pub fn new(
814809
fd: BorrowedFd<'a>,
815810
offs: off_t,

src/sys/ioctl/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -655,8 +655,10 @@ macro_rules! ioctl_readwrite {
655655
pub unsafe fn $name(fd: $crate::libc::c_int,
656656
data: *mut $ty)
657657
-> $crate::Result<$crate::libc::c_int> {
658+
let ioty = $ioty;
659+
let nr = $nr;
658660
unsafe {
659-
convert_ioctl_res!($crate::libc::ioctl(fd, request_code_readwrite!($ioty, $nr, ::std::mem::size_of::<$ty>()) as $crate::sys::ioctl::ioctl_num_type, data))
661+
convert_ioctl_res!($crate::libc::ioctl(fd, request_code_readwrite!(ioty, nr, ::std::mem::size_of::<$ty>()) as $crate::sys::ioctl::ioctl_num_type, data))
660662
}
661663
}
662664
)

src/sys/socket/addr.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -655,15 +655,13 @@ pub trait SockaddrLike: private::SockaddrLikePriv {
655655
///
656656
/// # Arguments
657657
///
658-
/// - `addr`: raw pointer to something that can be cast to a
659-
/// `libc::sockaddr`. For example, `libc::sockaddr_in`,
660-
/// `libc::sockaddr_in6`, etc.
661-
/// - `len`: For fixed-width types like `sockaddr_in`, it will be
662-
/// validated if present and ignored if not. For variable-width
663-
/// types it is required and must be the total length of valid
664-
/// data. For example, if `addr` points to a
665-
/// named `sockaddr_un`, then `len` must be the length of the
666-
/// structure up to but not including the trailing NUL.
658+
/// - `addr`: raw pointer to something that can be cast to a `libc::sockaddr`.
659+
/// For example, `libc::sockaddr_in`, `libc::sockaddr_in6`, etc.
660+
/// - `len`: For fixed-width types like `sockaddr_in`, it will be validated
661+
/// if present and ignored if not. For variable-width types it is required
662+
/// and must be the total length of valid data. For example, if `addr`
663+
/// points to a named `sockaddr_un`, then `len` must be the length of the
664+
/// structure up to but not including the trailing NUL.
667665
///
668666
/// # Safety
669667
///

src/sys/socket/sockopt.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ const TCP_CA_NAME_MAX: usize = 16;
3333
///
3434
/// * `$name:ident`: name of the type you want to implement `SetSockOpt` for.
3535
/// * `$level:expr` : socket layer, or a `protocol level`: could be *raw sockets*
36-
/// (`libc::SOL_SOCKET`), *ip protocol* (libc::IPPROTO_IP), *tcp protocol* (`libc::IPPROTO_TCP`),
37-
/// and more. Please refer to your system manual for more options. Will be passed as the second
38-
/// argument (`level`) to the `setsockopt` call.
36+
/// (`libc::SOL_SOCKET`), *ip protocol* (libc::IPPROTO_IP), *tcp protocol* (`libc::IPPROTO_TCP`),
37+
/// and more. Please refer to your system manual for more options. Will be passed as the second
38+
/// argument (`level`) to the `setsockopt` call.
3939
/// * `$flag:path`: a flag name to set. Some examples: `libc::SO_REUSEADDR`, `libc::TCP_NODELAY`,
40-
/// `libc::IP_ADD_MEMBERSHIP` and others. Will be passed as the third argument (`option_name`)
41-
/// to the `setsockopt` call.
40+
/// `libc::IP_ADD_MEMBERSHIP` and others. Will be passed as the third argument (`option_name`)
41+
/// to the `setsockopt` call.
4242
/// * Type of the value that you are going to set.
43-
/// * Type that implements the `Set` trait for the type from the previous item (like `SetBool` for
44-
/// `bool`, `SetUsize` for `usize`, etc.).
43+
/// * Type that implements the `Set` trait for the type from the previous item
44+
/// (like `SetBool` for `bool`, `SetUsize` for `usize`, etc.).
4545
#[macro_export]
4646
macro_rules! setsockopt_impl {
4747
($name:ident, $level:expr, $flag:path, $ty:ty, $setter:ty) => {
@@ -87,15 +87,15 @@ macro_rules! setsockopt_impl {
8787
///
8888
/// * Name of the type you want to implement `GetSockOpt` for.
8989
/// * Socket layer, or a `protocol level`: could be *raw sockets* (`lic::SOL_SOCKET`), *ip
90-
/// protocol* (libc::IPPROTO_IP), *tcp protocol* (`libc::IPPROTO_TCP`), and more. Please refer
91-
/// to your system manual for more options. Will be passed as the second argument (`level`) to
92-
/// the `getsockopt` call.
90+
/// protocol* (libc::IPPROTO_IP), *tcp protocol* (`libc::IPPROTO_TCP`), and more. Please refer
91+
/// to your system manual for more options. Will be passed as the second argument (`level`) to
92+
/// the `getsockopt` call.
9393
/// * A flag to set. Some examples: `libc::SO_REUSEADDR`, `libc::TCP_NODELAY`,
94-
/// `libc::SO_ORIGINAL_DST` and others. Will be passed as the third argument (`option_name`) to
95-
/// the `getsockopt` call.
94+
/// `libc::SO_ORIGINAL_DST` and others. Will be passed as the third argument (`option_name`) to
95+
/// the `getsockopt` call.
9696
/// * Type of the value that you are going to get.
9797
/// * Type that implements the `Get` trait for the type from the previous item (`GetBool` for
98-
/// `bool`, `GetUsize` for `usize`, etc.).
98+
/// `bool`, `GetUsize` for `usize`, etc.).
9999
#[macro_export]
100100
macro_rules! getsockopt_impl {
101101
($name:ident, $level:expr, $flag:path, $ty:ty, $getter:ty) => {
@@ -161,15 +161,15 @@ macro_rules! getsockopt_impl {
161161
/// # Arguments
162162
///
163163
/// * `GetOnly`, `SetOnly` or `Both`: whether you want to implement only getter, only setter or
164-
/// both of them.
164+
/// both of them.
165165
/// * `$name:ident`: name of type `GetSockOpt`/`SetSockOpt` will be implemented for.
166166
/// * `$level:expr` : socket layer, or a `protocol level`: could be *raw sockets*
167-
/// (`libc::SOL_SOCKET`), *ip protocol* (libc::IPPROTO_IP), *tcp protocol* (`libc::IPPROTO_TCP`),
168-
/// and more. Please refer to your system manual for more options. Will be passed as the second
169-
/// argument (`level`) to the `getsockopt`/`setsockopt` call.
167+
/// (`libc::SOL_SOCKET`), *ip protocol* (libc::IPPROTO_IP), *tcp protocol* (`libc::IPPROTO_TCP`),
168+
/// and more. Please refer to your system manual for more options. Will be passed as the second
169+
/// argument (`level`) to the `getsockopt`/`setsockopt` call.
170170
/// * `$flag:path`: a flag name to set. Some examples: `libc::SO_REUSEADDR`, `libc::TCP_NODELAY`,
171-
/// `libc::IP_ADD_MEMBERSHIP` and others. Will be passed as the third argument (`option_name`)
172-
/// to the `setsockopt`/`getsockopt` call.
171+
/// `libc::IP_ADD_MEMBERSHIP` and others. Will be passed as the third argument (`option_name`)
172+
/// to the `setsockopt`/`getsockopt` call.
173173
/// * `$ty:ty`: type of the value that will be get/set.
174174
/// * `$getter:ty`: `Get` implementation; optional; only for `GetOnly` and `Both`.
175175
/// * `$setter:ty`: `Set` implementation; optional; only for `SetOnly` and `Both`.

src/unistd.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,9 +265,9 @@ impl ForkResult {
265265
/// # Safety
266266
///
267267
/// In a multithreaded program, only [async-signal-safe] functions like `pause`
268-
/// and `_exit` may be called by the child (the parent isn't restricted). Note
269-
/// that memory allocation may **not** be async-signal-safe and thus must be
270-
/// prevented.
268+
/// and `_exit` may be called by the child (the parent isn't restricted) until
269+
/// a call of `execve(2)`. Note that memory allocation may **not** be
270+
/// async-signal-safe and thus must be prevented.
271271
///
272272
/// Those functions are only a small subset of your operating system's API, so
273273
/// special care must be taken to only invoke code you can control and audit.

0 commit comments

Comments
 (0)