Created
February 22, 2024 16:11
-
-
Save mrnugget/f9e204807dd4d2485cf6739a6ca21ce6 to your computer and use it in GitHub Desktop.
Why?
This file contains 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 characters
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 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 characters
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..."); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment