relibc/header/utmp/
mod.rs1use crate::{
6 header::{sys_ioctl, unistd},
7 platform::types::{c_int, c_void},
8};
9
10#[unsafe(no_mangle)]
12pub unsafe extern "C" fn login_tty(fd: c_int) -> c_int {
13 unistd::setsid();
15
16 let mut arg: c_int = 0;
18 if unsafe {
19 sys_ioctl::ioctl(
20 fd,
21 sys_ioctl::TIOCSCTTY,
22 core::ptr::from_mut::<c_int>(&mut arg).cast::<c_void>(),
23 )
24 } != 0
25 {
26 return -1;
27 }
28
29 unistd::dup2(fd, 0);
31 unistd::dup2(fd, 1);
32 unistd::dup2(fd, 2);
33
34 if fd > 2 {
36 unistd::close(fd);
37 }
38
39 0
40}