Skip to content

Commit 8098828

Browse files
committed
propagate argv0 when re-execing from /proc/self/exe
This allows runc to be used as a target for docker's reexec module that depends on a correct argv0 to select which process entrypoint to invoke. Without this patch, when runc re-execs argv0 is set to "/proc/self/exe" and the reexec module doesn't know what to do with it. Signed-off-by: Petros Angelatos <[email protected]>
1 parent 6d30f7a commit 8098828

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

libcontainer/container_linux.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ type linuxContainer struct {
4040
config *configs.Config
4141
cgroupManager cgroups.Manager
4242
intelRdtManager intelrdt.Manager
43+
initPath string
4344
initArgs []string
4445
initProcess parentProcess
4546
initProcessStartTime uint64
@@ -413,7 +414,8 @@ func (c *linuxContainer) newParentProcess(p *Process, doInit bool) (parentProces
413414
}
414415

415416
func (c *linuxContainer) commandTemplate(p *Process, childPipe *os.File) (*exec.Cmd, error) {
416-
cmd := exec.Command(c.initArgs[0], c.initArgs[1:]...)
417+
cmd := exec.Command(c.initPath, c.initArgs[1:]...)
418+
cmd.Args[0] = c.initArgs[0]
417419
cmd.Stdin = p.Stdin
418420
cmd.Stdout = p.Stdout
419421
cmd.Stderr = p.Stderr

libcontainer/factory_linux.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ func New(root string, options ...func(*LinuxFactory) error) (Factory, error) {
134134
}
135135
l := &LinuxFactory{
136136
Root: root,
137-
InitArgs: []string{"/proc/self/exe", "init"},
137+
InitPath: "/proc/self/exe",
138+
InitArgs: []string{os.Args[0], "init"},
138139
Validator: validate.New(),
139140
CriuPath: "criu",
140141
}
@@ -155,6 +156,10 @@ type LinuxFactory struct {
155156
// Root directory for the factory to store state.
156157
Root string
157158

159+
// InitPath is the path for calling the init responsibilities for spawning
160+
// a container.
161+
InitPath string
162+
158163
// InitArgs are arguments for calling the init responsibilities for spawning
159164
// a container.
160165
InitArgs []string
@@ -207,6 +212,7 @@ func (l *LinuxFactory) Create(id string, config *configs.Config) (Container, err
207212
id: id,
208213
root: containerRoot,
209214
config: config,
215+
initPath: l.InitPath,
210216
initArgs: l.InitArgs,
211217
criuPath: l.CriuPath,
212218
newuidmapPath: l.NewuidmapPath,
@@ -243,6 +249,7 @@ func (l *LinuxFactory) Load(id string) (Container, error) {
243249
initProcessStartTime: state.InitProcessStartTime,
244250
id: id,
245251
config: &state.Config,
252+
initPath: l.InitPath,
246253
initArgs: l.InitArgs,
247254
criuPath: l.CriuPath,
248255
newuidmapPath: l.NewuidmapPath,

0 commit comments

Comments
 (0)