Files
OpsLog/fatalbox_other.go
T
rouggy bb596c8aa9 fix(linux): a refusal to start is shown, not written to nobody
fatalBox off Windows was a single println. That goes to stderr, and a
binary started from a file manager or a .desktop launcher has no stderr
anyone will read — so a carefully worded refusal ("the folder OpsLog
keeps everything in cannot be written to…") reached the operator as "I
click it and nothing happens", which is the least useful thing a program
can say.

It now opens a dialog through zenity or kdialog when either is present —
both ship with every distribution's desktop task — and writes to stderr
either way. Neither is required: the startup log already carries the
same text, and nothing here may stop OpsLog from exiting.
2026-09-11 10:41:40 +02:00

40 lines
1.2 KiB
Go

//go:build !windows
package main
import (
"os"
"os/exec"
)
// fatalBox says why OpsLog is not starting, as visibly as the desktop allows.
//
// It used to be one println. That goes to stderr, and a binary started from a
// file manager or a .desktop launcher has no stderr anybody will ever read — so
// the refusal that was carefully worded arrived as "I click it and nothing
// happens", which is the least useful thing a program can say.
//
// So: a real dialog when the desktop has one of the two tools that every
// distribution ships with its desktop task, and stderr regardless. Neither is
// required — the startup log has the same text, and nothing here is allowed to
// stop OpsLog from exiting.
func fatalBox(title, text string) {
os.Stderr.WriteString(title + ": " + text + "\n")
for _, c := range [][]string{
{"zenity", "--error", "--no-wrap", "--title", title, "--text", text},
{"kdialog", "--title", title, "--error", text},
// Neither is a hard requirement, and on a headless box there is nothing
// to show a dialog on anyway.
} {
if _, err := exec.LookPath(c[0]); err != nil {
continue
}
cmd := exec.Command(c[0], c[1:]...)
if err := cmd.Start(); err != nil {
continue
}
_ = cmd.Wait()
return
}
}