Integrate with wine-access logging.
This commit is contained in:
1 parent
8e98321e6b
commit
d756ceb2b2
4 files changed
+369
-7
No files matched your search
@@ -11,6 +11,7 @@ import (
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"syscall"
|
||||
"time"
|
||||
)
|
||||
@@ -29,6 +30,7 @@ type process struct {
|
||||
seen time.Time
|
||||
failures int
|
||||
next time.Time
|
||||
stopping atomic.Bool
|
||||
}
|
||||
|
||||
type Manager struct {
|
||||
@@ -178,9 +180,12 @@ func backoff(failures int) time.Duration {
|
||||
|
||||
func (manager *Manager) launch(child *process, source prefix, now time.Time) error {
|
||||
cmd := exec.Command(manager.helper)
|
||||
diagnostics := newHelperDiagnostics()
|
||||
cmd.Stdin = nil
|
||||
cmd.Stdout = nil
|
||||
cmd.Stderr = nil
|
||||
cmd.Stderr = diagnostics
|
||||
// Bound stderr draining if a Wine descendant retains the inherited pipe.
|
||||
cmd.WaitDelay = 200 * time.Millisecond
|
||||
cmd.SysProcAttr = &syscall.SysProcAttr{Setsid: true}
|
||||
environment := os.Environ()
|
||||
for _, key := range []string{"DISPLAY", "WAYLAND_DISPLAY", "XDG_RUNTIME_DIR", "DBUS_SESSION_BUS_ADDRESS"} {
|
||||
@@ -197,17 +202,29 @@ func (manager *Manager) launch(child *process, source prefix, now time.Time) err
|
||||
return err
|
||||
}
|
||||
child.cmd, child.done, child.started = cmd, make(chan struct{}), now
|
||||
go manager.wait(cmd, child)
|
||||
manager.logger.Info("Wine accessibility helper started")
|
||||
child.stopping.Store(false)
|
||||
logger := manager.logger.With("helper_pid", cmd.Process.Pid)
|
||||
logger.Info("Wine accessibility helper started")
|
||||
logger.Debug("Wine accessibility helper launch configuration", "executable", cmd.Path,
|
||||
"wine_loader", source.loader, "wine_prefix", source.path)
|
||||
go diagnostics.logRecords(logger)
|
||||
go manager.wait(cmd, child, diagnostics, logger)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (manager *Manager) wait(cmd *exec.Cmd, child *process) {
|
||||
func (manager *Manager) wait(cmd *exec.Cmd, child *process, diagnostics *helperDiagnostics, logger *slog.Logger) {
|
||||
err := cmd.Wait()
|
||||
if err != nil {
|
||||
manager.logger.Warn("Wine accessibility helper exited", "error", err)
|
||||
diagnostics.finish()
|
||||
// Preserve record order at normal exit without letting a slow log sink
|
||||
// hold process supervision indefinitely.
|
||||
select {
|
||||
case <-diagnostics.done:
|
||||
case <-time.After(100 * time.Millisecond):
|
||||
}
|
||||
if err != nil && !child.stopping.Load() {
|
||||
logger.Warn("Wine accessibility helper exited", "error", err)
|
||||
} else {
|
||||
manager.logger.Info("Wine accessibility helper exited")
|
||||
logger.Info("Wine accessibility helper exited", "requested_stop", child.stopping.Load())
|
||||
}
|
||||
close(child.done)
|
||||
}
|
||||
@@ -222,6 +239,7 @@ func stop(child *process) {
|
||||
return
|
||||
default:
|
||||
}
|
||||
child.stopping.Store(true)
|
||||
_ = child.cmd.Process.Signal(syscall.SIGTERM)
|
||||
select {
|
||||
case <-child.done:
|
||||
|
||||
Reference in new issue
Block a user