浏览代码

mkdirall on the PID file path

Signed-off-by: John Howard <jhoward@microsoft.com>
John Howard 8 年之前
父节点
当前提交
745f3ece53
共有 1 个文件被更改,包括 7 次插入0 次删除
  1. 7 0
      pkg/pidfile/pidfile.go

+ 7 - 0
pkg/pidfile/pidfile.go

@@ -7,8 +7,11 @@ import (
 	"fmt"
 	"io/ioutil"
 	"os"
+	"path/filepath"
 	"strconv"
 	"strings"
+
+	"github.com/docker/docker/pkg/system"
 )
 
 // PIDFile is a file used to store the process ID of a running process.
@@ -33,6 +36,10 @@ func New(path string) (*PIDFile, error) {
 	if err := checkPIDFileAlreadyExists(path); err != nil {
 		return nil, err
 	}
+	// Note MkdirAll returns nil if a directory already exists
+	if err := system.MkdirAll(filepath.Dir(path), os.FileMode(0755)); err != nil {
+		return nil, err
+	}
 	if err := ioutil.WriteFile(path, []byte(fmt.Sprintf("%d", os.Getpid())), 0644); err != nil {
 		return nil, err
 	}