Merge branch 'pwd-pty-cleanup' into 'master'

pty and pwd cleanup

See merge request redox-os/relibc!1032
This commit is contained in:
Jeremy Soller
2026-02-23 06:25:06 -07:00
5 changed files with 24 additions and 22 deletions
+5 -3
View File
@@ -1,3 +1,5 @@
use core::ptr;
use crate::{
header::{fcntl, sys_ioctl, unistd},
io::{Cursor, Write},
@@ -16,7 +18,7 @@ pub(super) unsafe fn openpty(name: &mut [u8]) -> Result<(c_int, c_int), ()> {
sys_ioctl::ioctl(
master,
sys_ioctl::TIOCSPTLCK,
&mut lock as *mut c_int as *mut c_void,
ptr::from_mut::<c_int>(&mut lock).cast::<c_void>(),
)
} != 0
{
@@ -29,7 +31,7 @@ pub(super) unsafe fn openpty(name: &mut [u8]) -> Result<(c_int, c_int), ()> {
sys_ioctl::ioctl(
master,
sys_ioctl::TIOCGPTN,
&mut ptn as *mut c_int as *mut c_void,
ptr::from_mut::<c_int>(&mut ptn).cast::<c_void>(),
)
} != 0
{
@@ -42,7 +44,7 @@ pub(super) unsafe fn openpty(name: &mut [u8]) -> Result<(c_int, c_int), ()> {
let slave = unsafe {
fcntl::open(
cursor.get_ref().as_ptr() as *const c_char,
cursor.get_ref().as_ptr().cast::<c_char>(),
fcntl::O_RDWR | fcntl::O_NOCTTY,
0,
)
+6 -6
View File
@@ -31,7 +31,7 @@ pub unsafe extern "C" fn openpty(
) -> c_int {
let mut tmp_name = [0; limits::PATH_MAX];
let name = if !namep.is_null() {
unsafe { slice::from_raw_parts_mut(namep as *mut u8, limits::PATH_MAX) }
unsafe { slice::from_raw_parts_mut(namep.cast::<u8>(), limits::PATH_MAX) }
} else {
&mut tmp_name
};
@@ -52,7 +52,7 @@ pub unsafe extern "C" fn openpty(
unsafe { *amaster = master };
unsafe { *aslave = slave };
return 0;
0
}
/// See <https://www.man7.org/linux/man-pages/man3/openpty.3.html>.
@@ -77,7 +77,7 @@ pub unsafe extern "C" fn forkpty(
}
unsafe { signal::sigfillset(&mut set) };
unsafe { signal::pthread_sigmask(signal::SIG_BLOCK, &mut set, &mut oldset) };
unsafe { signal::pthread_sigmask(signal::SIG_BLOCK, &set, &mut oldset) };
unsafe { pthread::pthread_setcancelstate(pthread::PTHREAD_CANCEL_DISABLE, &mut cs) };
if unsafe { unistd::pipe2(p.as_mut_ptr(), fcntl::O_CLOEXEC) } != 0 {
@@ -99,7 +99,7 @@ pub unsafe extern "C" fn forkpty(
}
unistd::close(p[1]);
unsafe { pthread::pthread_setcancelstate(cs, ptr::null_mut()) };
unsafe { signal::pthread_sigmask(signal::SIG_SETMASK, &mut oldset, ptr::null_mut()) };
unsafe { signal::pthread_sigmask(signal::SIG_SETMASK, &oldset, ptr::null_mut()) };
return 0;
}
@@ -109,7 +109,7 @@ pub unsafe extern "C" fn forkpty(
if unsafe {
unistd::read(
p[0],
&mut ec as *mut c_int as *mut c_void,
ptr::from_mut::<c_int>(&mut ec).cast::<c_void>(),
mem::size_of::<c_int>(),
)
} > 0
@@ -127,6 +127,6 @@ pub unsafe extern "C" fn forkpty(
unistd::close(m);
}
unsafe { pthread::pthread_setcancelstate(cs, ptr::null_mut()) };
unsafe { signal::pthread_sigmask(signal::SIG_SETMASK, &mut oldset, ptr::null_mut()) };
unsafe { signal::pthread_sigmask(signal::SIG_SETMASK, &oldset, ptr::null_mut()) };
pid
}
+5 -5
View File
@@ -4,12 +4,12 @@ use crate::platform::types::c_char;
pub fn split(line: &mut [u8]) -> Option<passwd> {
let mut parts = line.split_mut(|&c| c == b'\0');
Some(passwd {
pw_name: parts.next()?.as_mut_ptr() as *mut c_char,
pw_passwd: parts.next()?.as_mut_ptr() as *mut c_char,
pw_name: parts.next()?.as_mut_ptr().cast::<c_char>(),
pw_passwd: parts.next()?.as_mut_ptr().cast::<c_char>(),
pw_uid: parsed(parts.next())?,
pw_gid: parsed(parts.next())?,
pw_gecos: parts.next()?.as_mut_ptr() as *mut c_char,
pw_dir: parts.next()?.as_mut_ptr() as *mut c_char,
pw_shell: parts.next()?.as_mut_ptr() as *mut c_char,
pw_gecos: parts.next()?.as_mut_ptr().cast::<c_char>(),
pw_dir: parts.next()?.as_mut_ptr().cast::<c_char>(),
pw_shell: parts.next()?.as_mut_ptr().cast::<c_char>(),
})
}
+3 -3
View File
@@ -278,7 +278,7 @@ pub unsafe extern "C" fn getpwnam_r(
pwd_lookup(
|parts| strcmp(parts.pw_name, name) == 0,
Some(DestBuffer {
ptr: buf as *mut u8,
ptr: buf.cast::<u8>(),
len: size,
}),
),
@@ -305,13 +305,13 @@ pub unsafe extern "C" fn getpwuid_r(
size: size_t,
result: *mut *mut passwd,
) -> c_int {
let slice = unsafe { core::slice::from_raw_parts_mut(buf as *mut u8, size) };
let slice = unsafe { core::slice::from_raw_parts_mut(buf.cast::<u8>(), size) };
unsafe {
mux(
pwd_lookup(
|part| part.pw_uid == uid,
Some(DestBuffer {
ptr: buf as *mut u8,
ptr: buf.cast::<u8>(),
len: size,
}),
),
+5 -5
View File
@@ -4,12 +4,12 @@ use crate::platform::types::c_char;
pub fn split(line: &mut [u8]) -> Option<passwd> {
let mut parts = line.split_mut(|&c| c == b'\0');
Some(passwd {
pw_name: parts.next()?.as_mut_ptr() as *mut c_char,
pw_passwd: "x\0".as_ptr() as *const c_char as *mut c_char,
pw_name: parts.next()?.as_mut_ptr().cast::<c_char>(),
pw_passwd: c"x".as_ptr() as *const c_char as *mut c_char,
pw_uid: parsed(parts.next())?,
pw_gid: parsed(parts.next())?,
pw_gecos: parts.next()?.as_mut_ptr() as *mut c_char,
pw_dir: parts.next()?.as_mut_ptr() as *mut c_char,
pw_shell: parts.next()?.as_mut_ptr() as *mut c_char,
pw_gecos: parts.next()?.as_mut_ptr().cast::<c_char>(),
pw_dir: parts.next()?.as_mut_ptr().cast::<c_char>(),
pw_shell: parts.next()?.as_mut_ptr().cast::<c_char>(),
})
}