aboutsummaryrefslogtreecommitdiffhomepage
path: root/container
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2025-12-27 09:12:02 +0900
committerOphestra <cat@gensokyo.uk>2025-12-27 09:12:02 +0900
commit3d720ada922def503977d6972aa953ffe924e714 (patch)
treeb8dcbf6a5f162066a34a69f730d9787125a1b097 /container
parent2e5362e536d477b47858748a8792c64175320aa7 (diff)
container: optionally allow orphan
This is required for the typical daemonise use case. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'container')
-rw-r--r--container/container.go8
1 files changed, 6 insertions, 2 deletions
diff --git a/container/container.go b/container/container.go
index 428309c0..bb60c23e 100644
--- a/container/container.go
+++ b/container/container.go
@@ -35,6 +35,8 @@ type (
// Container represents a container environment being prepared or run.
// None of [Container] methods are safe for concurrent use.
Container struct {
+ // Whether the container init should stay alive after its parent terminates.
+ AllowOrphan bool
// Cgroup fd, nil to disable.
Cgroup *int
// ExtraFiles passed through to initial process in the container,
@@ -252,8 +254,7 @@ func (p *Container) Start() error {
}
p.cmd.Dir = fhs.Root
p.cmd.SysProcAttr = &SysProcAttr{
- Setsid: !p.RetainSession,
- Pdeathsig: SIGKILL,
+ Setsid: !p.RetainSession,
Cloneflags: CLONE_NEWUSER | CLONE_NEWPID | CLONE_NEWNS |
CLONE_NEWIPC | CLONE_NEWUTS | CLONE_NEWCGROUP,
@@ -268,6 +269,9 @@ func (p *Container) Start() error {
UseCgroupFD: p.Cgroup != nil,
}
+ if !p.AllowOrphan {
+ p.cmd.SysProcAttr.Pdeathsig = SIGKILL
+ }
if p.cmd.SysProcAttr.UseCgroupFD {
p.cmd.SysProcAttr.CgroupFD = *p.Cgroup
}