pty and pwd cleanup

This commit is contained in:
auronandace
2026-02-23 08:51:05 +00:00
parent 6f00355741
commit 53912fa029
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
}