Created
February 22, 2024 16:11
-
-
Save mrnugget/f9e204807dd4d2485cf6739a6ca21ce6 to your computer and use it in GitHub Desktop.
Revisions
-
mrnugget created this gist
Feb 22, 2024 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,35 @@ package main import ( "fmt" "log" "os/exec" "time" ) func main() { cmd := exec.Command("/opt/homebrew/bin/zsh") // When I run this, I can't `ctrl-c` the program anymore: cmd.Args = []string{"-l", "-i", "-c", "/usr/bin/env -0"} // But if it's this, I can `ctrl-c`: // cmd.Args = []string{"-l", "-i", "-c", "/usr/bin/env -0; exit 0"} // // Even if it's this: // cmd.Args = []string{"-l", "-i", "-c", "/usr/bin/env -0; echo ROFLMAO"} // // WHY?! // // I just launch a subprocess that exits. How can it hijack my signal handling? _, err := cmd.Output() if err != nil { log.Fatal(err) } for { time.Sleep(1 * time.Second) fmt.Println("still running...") } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,27 @@ use std::process::Command; use std::thread; use std::time::Duration; fn main() { let mut cmd = Command::new("/opt/homebrew/bin/zsh"); // When I run this, I can't `ctrl-c` the program anymore: cmd.args(&["-l", "-i", "-c", "/usr/bin/env -0; echo lol"]); // But if it's this, I can `ctrl-c`: // cmd.args(&["-l", "-i", "-c", "/usr/bin/env -0; exit 0"]); // // WHY?! // // I just launch a subprocess that exits. How can it hijack my signal handling? let output = cmd.output().expect("Failed to execute command"); println!("{}", String::from_utf8_lossy(&output.stdout)); println!("{}", String::from_utf8_lossy(&output.stderr)); loop { thread::sleep(Duration::from_secs(1)); println!("still running..."); } }