Skip to content

Commit 5ea3e16

Browse files
mountennotgull
authored andcommitted
fix: CommandExt uid,gid param type error for target_os=nto
- define UserId, GroupId alias - use i32 for UserId, GroupId for target_os ntoo
1 parent 81112a9 commit 5ea3e16

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

src/unix.rs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,26 @@ use std::ffi::OsStr;
44
use std::io;
55
use std::os::unix::process::CommandExt as _;
66

7+
use cfg_if::cfg_if;
8+
79
use crate::Command;
810

11+
cfg_if! {
12+
if #[cfg(any(target_os = "vxworks", target_os = "espidf", target_os = "horizon", target_os = "vita"))] {
13+
type UserId = u16;
14+
type GroupId = u16;
15+
} else if #[cfg(target_os = "nto")] {
16+
// Both IDs are signed, see `sys/target_nto.h` of the QNX Neutrino SDP.
17+
// Only positive values should be used, see e.g.
18+
// https://www.qnx.com/developers/docs/7.1/#com.qnx.doc.neutrino.lib_ref/topic/s/setuid.html
19+
type UserId = i32;
20+
type GroupId = i32;
21+
} else {
22+
type UserId = u32;
23+
type GroupId = u32;
24+
}
25+
}
26+
927
/// Unix-specific extensions to the [`Command`] builder.
1028
///
1129
/// This trait is sealed: it cannot be implemented outside `async-process`.
@@ -14,11 +32,11 @@ pub trait CommandExt: crate::sealed::Sealed {
1432
/// Sets the child process's user ID. This translates to a
1533
/// `setuid` call in the child process. Failure in the `setuid`
1634
/// call will cause the spawn to fail.
17-
fn uid(&mut self, id: u32) -> &mut Command;
35+
fn uid(&mut self, id: UserId) -> &mut Command;
1836

1937
/// Similar to `uid`, but sets the group ID of the child process. This has
2038
/// the same semantics as the `uid` field.
21-
fn gid(&mut self, id: u32) -> &mut Command;
39+
fn gid(&mut self, id: GroupId) -> &mut Command;
2240

2341
/// Performs all the required setup by this `Command`, followed by calling
2442
/// the `execvp` syscall.
@@ -60,12 +78,12 @@ pub trait CommandExt: crate::sealed::Sealed {
6078

6179
impl crate::sealed::Sealed for Command {}
6280
impl CommandExt for Command {
63-
fn uid(&mut self, id: u32) -> &mut Command {
81+
fn uid(&mut self, id: UserId) -> &mut Command {
6482
self.inner.uid(id);
6583
self
6684
}
6785

68-
fn gid(&mut self, id: u32) -> &mut Command {
86+
fn gid(&mut self, id: GroupId) -> &mut Command {
6987
self.inner.gid(id);
7088
self
7189
}

0 commit comments

Comments
 (0)