ref: 8c7365217de5a345d3786208c996e85a8f826ab9
parent: aadf1b1f6d0ecd54975eb3ddf7769a281677e83c
author: penny <penny@limitedideas.org>
date: Tue Dec 2 17:06:37 EST 2025
fork into the background like a real program
--- a/main.go
+++ b/main.go
@@ -4,8 +4,11 @@
"fmt"
"os"
"io"
+ "os/exec"
"sync"
+ "syscall"
"time"
+ "flag"
"golang.org/x/sys/plan9"
"github.com/knusbaum/go9p/fs"
@@ -140,6 +143,29 @@
}
func main() {+ foreground := flag.Bool("f", false, "run in foreground")+ flag.Parse()
+ if *foreground {+ os.Args = append(os.Args[:1], os.Args[2:]...)
+ } else {+ path, err := exec.LookPath(os.Args[0])
+ if err != nil {+ fmt.Fprintf(os.Stderr, "snarflog: couldn't find myself: %s\n", err)
+ os.Exit(1)
+ }
+
+ args := append([]string{os.Args[0], "-f"}, os.Args[1:]...)+
+ _, err = syscall.ForkExec(path, args, &syscall.ProcAttr{+ Files: []uintptr{os.Stdin.Fd(), os.Stdout.Fd(), os.Stderr.Fd()},+ })
+ if err != nil {+ fmt.Fprintf(os.Stderr, "snarflog: fork failed: %s\n", err)
+ os.Exit(1)
+ }
+ os.Exit(0)
+ }
+
_, err := os.Stat("/srv/snarflog") if err == nil { srvFd, err := plan9.Open("/srv/snarflog", plan9.O_RDWR)--
⑨