package activator import ( "context" "os/exec" "github.com/carlosframework/platform/internal/cgroup" "github.com/carlosframework/platform/internal/hostwrite" ) // newClaimProcessFor is newClaimProcess for the launcher that produced cmd. // A root launch hands the agent no child and no containment: the agent // watches the unit's main process and stops it only through root. func newClaimProcessFor(cmd *exec.Cmd, p *cgroup.Prepared, root bool) *claimProcess { if !root { return newClaimProcess(cmd, p) } c := &claimProcess{cmd: cmd, root: true, done: make(chan struct{})} if cmd == nil || cmd.Process == nil { close(c.done) } else { watchRootProcess(cmd.Process, c.done) } return c } // stopRoot asks root to stop the reservation and waits for the unit's main // process to be gone. Without root's settle there is no way to stop it, so // it refuses rather than assumes. func (p *claimProcess) stopRoot(ctx context.Context) error { if p.closed { return nil } if p.settle == nil { select { case <-p.done: default: return hostwrite.ErrUnavailable } } else if err := p.settle(ctx); err != nil { return err } select { case <-ctx.Done(): return ctx.Err() case <-p.done: } p.closed = true if p.cmd != nil && p.cmd.Process != nil { _ = p.cmd.Process.Release() } if p.producerFinish != nil { p.producerFinish(nil) } return nil }