1
0
Fork 0
forked from wry/wry

all: mark env::set_var/remove_var unsafe

This commit is contained in:
Julian Orth 2024-10-20 18:43:51 +02:00
parent 73a6e0d5c2
commit a0984a1205
2 changed files with 18 additions and 10 deletions

View file

@ -20,9 +20,11 @@ pub fn main(global: GlobalArgs, args: RunPrivilegedArgs) {
let mut path = PathBuf::from(xrd); let mut path = PathBuf::from(xrd);
path.push(&wd); path.push(&wd);
if path.exists() { if path.exists() {
unsafe {
std::env::set_var(WAYLAND_DISPLAY, &wd); std::env::set_var(WAYLAND_DISPLAY, &wd);
} }
} }
}
let mut argv = UstrPtr::new(); let mut argv = UstrPtr::new();
for arg in &args.program { for arg in &args.program {
argv.push(arg.as_str()); argv.push(arg.as_str());

View file

@ -332,9 +332,11 @@ struct Forker {
impl Forker { impl Forker {
fn handle(ppid: c::pid_t, socket: OwnedFd) -> ! { fn handle(ppid: c::pid_t, socket: OwnedFd) -> ! {
unsafe {
env::set_var("XDG_SESSION_TYPE", "wayland"); env::set_var("XDG_SESSION_TYPE", "wayland");
env::remove_var(DISPLAY); env::remove_var(DISPLAY);
env::remove_var(WAYLAND_DISPLAY); env::remove_var(WAYLAND_DISPLAY);
}
set_process_name("the ol' forker"); set_process_name("the ol' forker");
setup_deathsig(ppid); setup_deathsig(ppid);
reset_signals(); reset_signals();
@ -409,11 +411,13 @@ impl Forker {
fn handle_set_env(self: &Rc<Self>, var: &[u8], val: Option<Vec<u8>>) { fn handle_set_env(self: &Rc<Self>, var: &[u8], val: Option<Vec<u8>>) {
let var = OsStr::from_bytes(var); let var = OsStr::from_bytes(var);
unsafe {
match val { match val {
Some(val) => env::set_var(var, OsStr::from_bytes(&val)), Some(val) => env::set_var(var, OsStr::from_bytes(&val)),
_ => env::remove_var(var), _ => env::remove_var(var),
} }
} }
}
fn handle_spawn( fn handle_spawn(
self: &Rc<Self>, self: &Rc<Self>,
@ -513,11 +517,13 @@ impl Forker {
c::signal(c::SIGCHLD, c::SIG_DFL); c::signal(c::SIGCHLD, c::SIG_DFL);
} }
for (key, val) in env { for (key, val) in env {
unsafe {
match val { match val {
None => env::remove_var(&key), None => env::remove_var(&key),
Some(val) => env::set_var(&key, &val), Some(val) => env::set_var(&key, &val),
} }
} }
}
let prog = prog.into_ustr(); let prog = prog.into_ustr();
let mut argsnt = UstrPtr::new(); let mut argsnt = UstrPtr::new();
argsnt.push(&prog); argsnt.push(&prog);