Skip to content

Commit 9b13f5c

Browse files
committed
merge branch 'pr-1453'
propagate argv0 when re-execing from /proc/self/exe LGTMs: @crosbymichael @cyphar Closes #1453
2 parents ff4481d + 8098828 commit 9b13f5c

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
@@ -119,7 +119,8 @@ func New(root string, options ...func(*LinuxFactory) error) (Factory, error) {
119119
}
120120
l := &LinuxFactory{
121121
Root: root,
122-
InitArgs: []string{"/proc/self/exe", "init"},
122+
InitPath: "/proc/self/exe",
123+
InitArgs: []string{os.Args[0], "init"},
123124
Validator: validate.New(),
124125
CriuPath: "criu",
125126
}
@@ -140,6 +141,10 @@ type LinuxFactory struct {
140141
// Root directory for the factory to store state.
141142
Root string
142143

144+
// InitPath is the path for calling the init responsibilities for spawning
145+
// a container.
146+
InitPath string
147+
143148
// InitArgs are arguments for calling the init responsibilities for spawning
144149
// a container.
145150
InitArgs []string
@@ -189,6 +194,7 @@ func (l *LinuxFactory) Create(id string, config *configs.Config) (Container, err
189194
id: id,
190195
root: containerRoot,
191196
config: config,
197+
initPath: l.InitPath,
192198
initArgs: l.InitArgs,
193199
criuPath: l.CriuPath,
194200
newuidmapPath: l.NewuidmapPath,
@@ -221,6 +227,7 @@ func (l *LinuxFactory) Load(id string) (Container, error) {
221227
initProcessStartTime: state.InitProcessStartTime,
222228
id: id,
223229
config: &state.Config,
230+
initPath: l.InitPath,
224231
initArgs: l.InitArgs,
225232
criuPath: l.CriuPath,
226233
newuidmapPath: l.NewuidmapPath,

0 commit comments

Comments
 (0)