Skip to content

Commit 9d0b84e

Browse files
committed
Make cwd required
Signed-off-by: Mrunal Patel <[email protected]>
1 parent 4c767d7 commit 9d0b84e

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

libcontainer/init_linux.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,8 @@ func finalizeNamespace(config *initConfig) error {
134134
if err := w.drop(); err != nil {
135135
return err
136136
}
137-
if config.Cwd != "" {
138-
if err := syscall.Chdir(config.Cwd); err != nil {
139-
return err
140-
}
137+
if err := syscall.Chdir(config.Cwd); err != nil {
138+
return err
141139
}
142140
return nil
143141
}

spec.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ var specCommand = cli.Command{
5353
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
5454
"TERM=xterm",
5555
},
56+
Cwd: "/",
5657
},
5758
Hostname: "shell",
5859
Mounts: []specs.MountPoint{

start.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ func startContainer(context *cli.Context, spec *specs.LinuxSpec, rspec *specs.Li
108108
// ensure that the container is always removed if we were the process
109109
// that created it.
110110
defer destroy(container)
111+
112+
if spec.Process.Cwd == "" {
113+
return -1, fmt.Errorf("Cwd property must not be empty")
114+
}
111115
process := newProcess(spec.Process)
112116

113117
// Support on-demand socket activation by passing file descriptors into the container init process.

0 commit comments

Comments
 (0)