creates sh in empty environment
This commit is contained in:
14
src/main.rs
14
src/main.rs
@@ -16,7 +16,6 @@ use vte::{Params, Parser, Perform};
|
|||||||
use zeno::{Mask, Transform};
|
use zeno::{Mask, Transform};
|
||||||
|
|
||||||
// params
|
// params
|
||||||
const SHELL: &str = "/home/andromeda/.nix-profile/bin/sh";
|
|
||||||
const FONT: &str = "/home/andromeda/.nix-profile/share/fonts/truetype/Miracode.ttf";
|
const FONT: &str = "/home/andromeda/.nix-profile/share/fonts/truetype/Miracode.ttf";
|
||||||
|
|
||||||
struct Buffer<T: std::clone::Clone> {
|
struct Buffer<T: std::clone::Clone> {
|
||||||
@@ -186,7 +185,7 @@ fn main() {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
window.set_target_fps(60);
|
window.set_target_fps(60);
|
||||||
|
|
||||||
let pty = spawn_pty(&SHELL).unwrap();
|
let pty = spawn_pty().unwrap();
|
||||||
fcntl(
|
fcntl(
|
||||||
&pty,
|
&pty,
|
||||||
F_SETFL(OFlag::from_bits_truncate(fcntl(&pty, F_GETFL).unwrap()) | OFlag::O_NONBLOCK),
|
F_SETFL(OFlag::from_bits_truncate(fcntl(&pty, F_GETFL).unwrap()) | OFlag::O_NONBLOCK),
|
||||||
@@ -257,7 +256,7 @@ fn main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// forks a new pty and returns file descriptor of the master
|
// forks a new pty and returns file descriptor of the master
|
||||||
fn spawn_pty(shell: &str) -> Option<PtyMaster> {
|
fn spawn_pty() -> Option<PtyMaster> {
|
||||||
// SAFETY safe unless os out of PTYs; incredibly unlikely
|
// SAFETY safe unless os out of PTYs; incredibly unlikely
|
||||||
match unsafe { forkpty(None, None) } {
|
match unsafe { forkpty(None, None) } {
|
||||||
Ok(fork_pty_res) => match fork_pty_res {
|
Ok(fork_pty_res) => match fork_pty_res {
|
||||||
@@ -266,7 +265,14 @@ fn spawn_pty(shell: &str) -> Option<PtyMaster> {
|
|||||||
return Some(unsafe { PtyMaster::from_owned_fd(master) });
|
return Some(unsafe { PtyMaster::from_owned_fd(master) });
|
||||||
}
|
}
|
||||||
ForkptyResult::Child => {
|
ForkptyResult::Child => {
|
||||||
let _ = execv::<CString>(&CString::new(shell).unwrap(), &[]);
|
let _ = execv::<CString>(
|
||||||
|
&CString::new("/usr/bin/env").unwrap(),
|
||||||
|
&[ CString::new("/usr/bin/env").unwrap(),
|
||||||
|
CString::new("-i").unwrap(),
|
||||||
|
CString::new("sh").unwrap(),
|
||||||
|
CString::new("--norc").unwrap(),
|
||||||
|
CString::new("--noprofile").unwrap() ],
|
||||||
|
);
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user