Skip to content

Instantly share code, notes, and snippets.

@mrnugget
Created February 22, 2024 16:11
Show Gist options
  • Save mrnugget/f9e204807dd4d2485cf6739a6ca21ce6 to your computer and use it in GitHub Desktop.
Save mrnugget/f9e204807dd4d2485cf6739a6ca21ce6 to your computer and use it in GitHub Desktop.

Revisions

  1. mrnugget created this gist Feb 22, 2024.
    35 changes: 35 additions & 0 deletions main.go
    Original 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...")
    }
    }
    27 changes: 27 additions & 0 deletions main.rs
    Original 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...");
    }
    }