remove remount: was killing 9pfuse on exit

The retry-with-remount pattern called ollie-remount (which does
sudo umount -f) from goroutines that raced with os.Exit, nuking
the shared FUSE mount. The watchdog handles recovery now.
This commit is contained in:
Levi Neely 2026-06-15 16:18:47 +02:00
parent 2da9867f99
commit 4a2c8e41b2
1 changed files with 10 additions and 48 deletions

52
main.go
View File

@ -4,19 +4,16 @@ package main
import ( import (
"log" "log"
"os" "os"
"os/exec"
"path/filepath" "path/filepath"
"sort" "sort"
"strings" "strings"
"sync" "sync"
"sync/atomic"
"time" "time"
"9fans.net/go/acme" "9fans.net/go/acme"
) )
var ollie string var ollie string
var exiting atomic.Bool
func init() { func init() {
ollie = os.Getenv("OLLIE") ollie = os.Getenv("OLLIE")
@ -25,40 +22,6 @@ func init() {
} }
} }
func remount() {
if exiting.Load() {
return
}
exec.Command("ollie-remount").Run() //nolint:errcheck
}
func readFileRetry(path string) ([]byte, error) {
data, err := os.ReadFile(path)
if err != nil {
remount()
data, err = os.ReadFile(path)
}
return data, err
}
func writeFileRetry(path string, data []byte) error {
err := os.WriteFile(path, data, 0644)
if err != nil {
remount()
err = os.WriteFile(path, data, 0644)
}
return err
}
func statRetry(path string) (os.FileInfo, error) {
fi, err := os.Stat(path)
if err != nil {
remount()
fi, err = os.Stat(path)
}
return fi, err
}
func main() { func main() {
acme.AutoExit(true) acme.AutoExit(true)
if err := newSessionList(); err != nil { if err := newSessionList(); err != nil {
@ -90,7 +53,7 @@ func newSessionList() error {
} }
func (sl *sessionList) refresh() { func (sl *sessionList) refresh() {
data, err := readFileRetry(filepath.Join(ollie, "s", "idx")) data, err := os.ReadFile(filepath.Join(ollie, "s", "idx"))
if err != nil { if err != nil {
sl.win.Errf("read idx: %v", err) sl.win.Errf("read idx: %v", err)
return return
@ -150,7 +113,7 @@ func (sl *sessionList) eventLoop() {
arg := strings.TrimSpace(string(e.Arg)) arg := strings.TrimSpace(string(e.Arg))
sid := sl.resolveFullSID(arg) sid := sl.resolveFullSID(arg)
if sid != "" { if sid != "" {
writeFileRetry(filepath.Join(ollie, "s", sid, "ctl"), []byte("kill")) os.WriteFile(filepath.Join(ollie, "s", sid, "ctl"), []byte("kill"), 0644) //nolint:errcheck
sl.refresh() sl.refresh()
} }
continue continue
@ -169,12 +132,11 @@ func (sl *sessionList) eventLoop() {
sl.win.WriteEvent(e) sl.win.WriteEvent(e)
} }
} }
exiting.Store(true)
os.Exit(0) os.Exit(0)
} }
func sessionExists(sid string) bool { func sessionExists(sid string) bool {
_, err := statRetry(filepath.Join(ollie, "s", sid)) _, err := os.Stat(filepath.Join(ollie, "s", sid))
return err == nil return err == nil
} }
@ -201,7 +163,7 @@ func openChat(sid string) {
return return
} }
winName := "ollie/sessions/" + sid winName := "ollie/sessions/" + sid
if data, err := readFileRetry(filepath.Join(ollie, "s", "idx")); err == nil { if data, err := os.ReadFile(filepath.Join(ollie, "s", "idx")); err == nil {
for _, line := range strings.Split(string(data), "\n") { for _, line := range strings.Split(string(data), "\n") {
fields := strings.Split(line, "\t") fields := strings.Split(line, "\t")
if len(fields) >= 3 && fields[0] == sid { if len(fields) >= 3 && fields[0] == sid {
@ -219,7 +181,7 @@ func openChat(sid string) {
// Load existing chat. // Load existing chat.
chatPath := filepath.Join(ollie, "s", sid, "chat") chatPath := filepath.Join(ollie, "s", sid, "chat")
if data, err := readFileRetry(chatPath); err == nil && len(data) > 0 { if data, err := os.ReadFile(chatPath); err == nil && len(data) > 0 {
w.Write("body", data) w.Write("body", data)
cw.offset = len(data) cw.offset = len(data)
} }
@ -239,7 +201,7 @@ func (cw *chatWin) eventLoop() {
case "Prompt": case "Prompt":
openFile(filepath.Join(ollie, "s", cw.sid, "prompt")) openFile(filepath.Join(ollie, "s", cw.sid, "prompt"))
case "Stop": case "Stop":
writeFileRetry(filepath.Join(ollie, "s", cw.sid, "ctl"), []byte("stop")) os.WriteFile(filepath.Join(ollie, "s", cw.sid, "ctl"), []byte("stop"), 0644) //nolint:errcheck
case "Ctl": case "Ctl":
openFile(filepath.Join(ollie, "s", cw.sid, "ctl")) openFile(filepath.Join(ollie, "s", cw.sid, "ctl"))
default: default:
@ -256,7 +218,7 @@ func (cw *chatWin) tail() {
chatPath := filepath.Join(ollie, "s", cw.sid, "chat") chatPath := filepath.Join(ollie, "s", cw.sid, "chat")
for { for {
fi, err := statRetry(chatPath) fi, err := os.Stat(chatPath)
if err != nil { if err != nil {
if os.IsNotExist(err) { if os.IsNotExist(err) {
return return