Add login process. Remove debugging. Fix order of arguments
This commit is contained in:
parent
afe7a99700
commit
046236c10f
1 changed files with 70 additions and 97 deletions
38
programs/login/src/main.rs
Normal file
38
programs/login/src/main.rs
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
extern crate syscall;
|
||||
|
||||
use std::env;
|
||||
use std::process::Command;
|
||||
use std::thread;
|
||||
|
||||
pub fn main() {
|
||||
let mut args = env::args().skip(1);
|
||||
|
||||
let tty = args.next().expect("login: no tty provided");
|
||||
let sh = args.next().expect("login: no sh provided");
|
||||
let sh_args: Vec<String> = args.collect();
|
||||
|
||||
syscall::close(2);
|
||||
syscall::close(1);
|
||||
syscall::close(0);
|
||||
|
||||
syscall::open(&tty, syscall::flag::O_RDWR);
|
||||
syscall::open(&tty, syscall::flag::O_RDWR);
|
||||
syscall::open(&tty, syscall::flag::O_RDWR);
|
||||
|
||||
thread::spawn(move || {
|
||||
loop {
|
||||
let mut command = Command::new(&sh);
|
||||
for arg in sh_args.iter() {
|
||||
command.arg(arg);
|
||||
}
|
||||
|
||||
match command.spawn() {
|
||||
Ok(mut child) => match child.wait() {
|
||||
Ok(_status) => (), //println!("login: waited for {}: {:?}", sh, status.code()),
|
||||
Err(err) => panic!("login: failed to wait for '{}': {}", sh, err)
|
||||
},
|
||||
Err(err) => panic!("login: failed to execute '{}': {}", sh, err)
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
Loading…
Reference in a new issue