|
@@ -10,6 +10,7 @@ import (
|
|
"os/exec"
|
|
"os/exec"
|
|
"path"
|
|
"path"
|
|
"path/filepath"
|
|
"path/filepath"
|
|
|
|
+ "strconv"
|
|
"strings"
|
|
"strings"
|
|
"syscall"
|
|
"syscall"
|
|
)
|
|
)
|
|
@@ -564,6 +565,21 @@ func (devices *DeviceSetDM) setupBaseImage() error {
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+func setCloseOnExec(name string) {
|
|
|
|
+ fileInfos, _ := ioutil.ReadDir("/proc/self/fd")
|
|
|
|
+ if fileInfos != nil {
|
|
|
|
+ for _, i := range fileInfos {
|
|
|
|
+ link, _ := os.Readlink(filepath.Join("/proc/self/fd", i.Name()))
|
|
|
|
+ if link == name {
|
|
|
|
+ fd, err := strconv.Atoi(i.Name())
|
|
|
|
+ if err == nil {
|
|
|
|
+ syscall.CloseOnExec(fd)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
func (devices *DeviceSetDM) initDevmapper() error {
|
|
func (devices *DeviceSetDM) initDevmapper() error {
|
|
info, err := devices.getInfo(devices.getPoolName())
|
|
info, err := devices.getInfo(devices.getPoolName())
|
|
if info == nil {
|
|
if info == nil {
|
|
@@ -572,6 +588,11 @@ func (devices *DeviceSetDM) initDevmapper() error {
|
|
}
|
|
}
|
|
utils.Debugf("initDevmapper(). Pool exists: %v", info.Exists)
|
|
utils.Debugf("initDevmapper(). Pool exists: %v", info.Exists)
|
|
|
|
|
|
|
|
+ // It seems libdevmapper opens this without O_CLOEXEC, and go exec will not close files
|
|
|
|
+ // that are not Close-on-exec, and lxc-start will die if it inherits any unexpected files,
|
|
|
|
+ // so we add this badhack to make sure it closes itself
|
|
|
|
+ setCloseOnExec("/dev/mapper/control")
|
|
|
|
+
|
|
if info.Exists != 0 {
|
|
if info.Exists != 0 {
|
|
/* Pool exists, assume everything is up */
|
|
/* Pool exists, assume everything is up */
|
|
if err := devices.loadMetaData(); err != nil {
|
|
if err := devices.loadMetaData(); err != nil {
|