From cafed5f23468daf2765655325ebe7d879acdde24 Mon Sep 17 00:00:00 2001 From: Ophestra Umiker Date: Mon, 21 Oct 2024 21:23:56 +0900 Subject: shim: abort setup on failed start and process exit Shim setup listens on a socket in the process share, if shim setup hasn't happened on exit revert will fail. This change makes sure shim setup is aborted on a doomed launch. Signed-off-by: Ophestra Umiker --- internal/app/app.go | 2 ++ internal/app/start.go | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) (limited to 'internal/app') diff --git a/internal/app/app.go b/internal/app/app.go index 5c5e3452..0055dd76 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -24,6 +24,8 @@ type app struct { id *ID // underlying user switcher process cmd *exec.Cmd + // shim setup abort reason and completion + abort chan error // child process related information seal *appSeal // error returned waiting for process diff --git a/internal/app/start.go b/internal/app/start.go index b6c94041..464d23df 100644 --- a/internal/app/start.go +++ b/internal/app/start.go @@ -63,7 +63,8 @@ func (a *app) Start() error { a.cmd.Stdin, a.cmd.Stdout, a.cmd.Stderr = os.Stdin, os.Stdout, os.Stderr a.cmd.Dir = a.seal.RunDirPath - if err := shim.ServeConfig(confSockPath, a.seal.sys.UID(), &shim.Payload{ + a.abort = make(chan error) + if err := shim.ServeConfig(confSockPath, a.abort, a.seal.sys.UID(), &shim.Payload{ Argv: a.seal.command, Exec: shimExec, Bwrap: a.seal.sys.bwrap, @@ -71,6 +72,8 @@ func (a *app) Start() error { Verbose: fmsg.Verbose(), }, a.seal.wl); err != nil { + a.abort <- err + <-a.abort return fmsg.WrapErrorSuffix(err, "cannot serve shim setup:") } @@ -232,6 +235,8 @@ func (a *app) Wait() (int, error) { } } + a.abort <- errors.New("shim exited") + <-a.abort if err := a.seal.sys.Revert(ec); err != nil { return err.(RevertCompoundError) } -- cgit v1.3.1