Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)
| ... | ... |
@@ -623,31 +623,11 @@ func (container *Container) Start() (err error) {
|
| 623 | 623 |
var workingDir string |
| 624 | 624 |
if container.Config.WorkingDir != "" {
|
| 625 | 625 |
workingDir = path.Clean(container.Config.WorkingDir) |
| 626 |
- utils.Debugf("[working dir] working dir is %s", workingDir)
|
|
| 627 |
- |
|
| 628 | 626 |
if err := os.MkdirAll(path.Join(container.RootfsPath(), workingDir), 0755); err != nil {
|
| 629 | 627 |
return nil |
| 630 | 628 |
} |
| 631 | 629 |
} |
| 632 | 630 |
|
| 633 |
- /* |
|
| 634 |
- if RootIsShared() {
|
|
| 635 |
- // lxc-start really needs / to be non-shared, or all kinds of stuff break |
|
| 636 |
- // when lxc-start unmount things and those unmounts propagate to the main |
|
| 637 |
- // mount namespace. |
|
| 638 |
- // What we really want is to clone into a new namespace and then |
|
| 639 |
- // mount / MS_REC|MS_SLAVE, but since we can't really clone or fork |
|
| 640 |
- // without exec in go we have to do this horrible shell hack... |
|
| 641 |
- shellString := |
|
| 642 |
- "mount --make-rslave /; exec " + |
|
| 643 |
- utils.ShellQuoteArguments(params) |
|
| 644 |
- |
|
| 645 |
- params = []string{
|
|
| 646 |
- "unshare", "-m", "--", "/bin/sh", "-c", shellString, |
|
| 647 |
- } |
|
| 648 |
- } |
|
| 649 |
- */ |
|
| 650 |
- |
|
| 651 | 631 |
root := container.RootfsPath() |
| 652 | 632 |
envPath, err := container.EnvConfigPath() |
| 653 | 633 |
if err != nil {
|
| ... | ... |
@@ -4,6 +4,8 @@ import ( |
| 4 | 4 |
"errors" |
| 5 | 5 |
"fmt" |
| 6 | 6 |
"github.com/dotcloud/docker/execdriver" |
| 7 |
+ "github.com/dotcloud/docker/utils" |
|
| 8 |
+ "io/ioutil" |
|
| 7 | 9 |
"os" |
| 8 | 10 |
"os/exec" |
| 9 | 11 |
"path" |
| ... | ... |
@@ -22,8 +24,9 @@ var ( |
| 22 | 22 |
) |
| 23 | 23 |
|
| 24 | 24 |
type driver struct {
|
| 25 |
- root string // root path for the driver to use |
|
| 26 |
- apparmor bool |
|
| 25 |
+ root string // root path for the driver to use |
|
| 26 |
+ apparmor bool |
|
| 27 |
+ sharedRoot bool |
|
| 27 | 28 |
} |
| 28 | 29 |
|
| 29 | 30 |
func NewDriver(root string, apparmor bool) (execdriver.Driver, error) {
|
| ... | ... |
@@ -32,8 +35,9 @@ func NewDriver(root string, apparmor bool) (execdriver.Driver, error) {
|
| 32 | 32 |
return nil, err |
| 33 | 33 |
} |
| 34 | 34 |
return &driver{
|
| 35 |
- apparmor: apparmor, |
|
| 36 |
- root: root, |
|
| 35 |
+ apparmor: apparmor, |
|
| 36 |
+ root: root, |
|
| 37 |
+ sharedRoot: rootIsShared(), |
|
| 37 | 38 |
}, nil |
| 38 | 39 |
} |
| 39 | 40 |
|
| ... | ... |
@@ -70,6 +74,23 @@ func (d *driver) Start(c *execdriver.Process) error {
|
| 70 | 70 |
params = append(params, "-w", c.WorkingDir) |
| 71 | 71 |
} |
| 72 | 72 |
|
| 73 |
+ if d.sharedRoot {
|
|
| 74 |
+ // lxc-start really needs / to be non-shared, or all kinds of stuff break |
|
| 75 |
+ // when lxc-start unmount things and those unmounts propagate to the main |
|
| 76 |
+ // mount namespace. |
|
| 77 |
+ // What we really want is to clone into a new namespace and then |
|
| 78 |
+ // mount / MS_REC|MS_SLAVE, but since we can't really clone or fork |
|
| 79 |
+ // without exec in go we have to do this horrible shell hack... |
|
| 80 |
+ shellString := |
|
| 81 |
+ "mount --make-rslave /; exec " + |
|
| 82 |
+ utils.ShellQuoteArguments(params) |
|
| 83 |
+ |
|
| 84 |
+ params = []string{
|
|
| 85 |
+ "unshare", "-m", "--", "/bin/sh", "-c", shellString, |
|
| 86 |
+ } |
|
| 87 |
+ |
|
| 88 |
+ } |
|
| 89 |
+ |
|
| 73 | 90 |
params = append(params, "--", c.Entrypoint) |
| 74 | 91 |
params = append(params, c.Arguments...) |
| 75 | 92 |
|
| ... | ... |
@@ -218,3 +239,17 @@ func linkLxcStart(root string) error {
|
| 218 | 218 |
} |
| 219 | 219 |
return os.Symlink(sourcePath, targetPath) |
| 220 | 220 |
} |
| 221 |
+ |
|
| 222 |
+func rootIsShared() bool {
|
|
| 223 |
+ if data, err := ioutil.ReadFile("/proc/self/mountinfo"); err == nil {
|
|
| 224 |
+ for _, line := range strings.Split(string(data), "\n") {
|
|
| 225 |
+ cols := strings.Split(line, " ") |
|
| 226 |
+ if len(cols) >= 6 && cols[4] == "/" {
|
|
| 227 |
+ return strings.HasPrefix(cols[6], "shared") |
|
| 228 |
+ } |
|
| 229 |
+ } |
|
| 230 |
+ } |
|
| 231 |
+ |
|
| 232 |
+ // No idea, probably safe to assume so |
|
| 233 |
+ return true |
|
| 234 |
+} |
| ... | ... |
@@ -5,7 +5,6 @@ import ( |
| 5 | 5 |
"github.com/dotcloud/docker/archive" |
| 6 | 6 |
"github.com/dotcloud/docker/pkg/namesgenerator" |
| 7 | 7 |
"github.com/dotcloud/docker/utils" |
| 8 |
- "io/ioutil" |
|
| 9 | 8 |
"strconv" |
| 10 | 9 |
"strings" |
| 11 | 10 |
) |
| ... | ... |
@@ -328,20 +327,6 @@ func parseLink(rawLink string) (map[string]string, error) {
|
| 328 | 328 |
return utils.PartParser("name:alias", rawLink)
|
| 329 | 329 |
} |
| 330 | 330 |
|
| 331 |
-func RootIsShared() bool {
|
|
| 332 |
- if data, err := ioutil.ReadFile("/proc/self/mountinfo"); err == nil {
|
|
| 333 |
- for _, line := range strings.Split(string(data), "\n") {
|
|
| 334 |
- cols := strings.Split(line, " ") |
|
| 335 |
- if len(cols) >= 6 && cols[4] == "/" {
|
|
| 336 |
- return strings.HasPrefix(cols[6], "shared") |
|
| 337 |
- } |
|
| 338 |
- } |
|
| 339 |
- } |
|
| 340 |
- |
|
| 341 |
- // No idea, probably safe to assume so |
|
| 342 |
- return true |
|
| 343 |
-} |
|
| 344 |
- |
|
| 345 | 331 |
type checker struct {
|
| 346 | 332 |
runtime *Runtime |
| 347 | 333 |
} |