shim: abort setup on failed start and process exit
All checks were successful
test / test (push) Successful in 25s

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 <cat@ophivana.moe>
This commit is contained in:
2024-10-21 21:23:56 +09:00
parent 42e0b168e3
commit cafed5f234
3 changed files with 37 additions and 7 deletions

View File

@@ -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

View File

@@ -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)
}