pkg/pidfile: Write(): don't automatically create parent directories
While this was convenient for our use, it's somewhat unexpected for a function that writes a file to also create all parent directories; even more because this function may be executed as root. This patch makes the package more "safe" to use as a generic package by removing this functionality, and leaving it up to the caller to create parent directories, if needed. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
81945da0ac
commit
7d3e1ad943
2 changed files with 3 additions and 5 deletions
|
@ -139,6 +139,9 @@ func (cli *DaemonCli) start(opts *daemonOptions) (err error) {
|
|||
potentiallyUnderRuntimeDir := []string{cli.Config.ExecRoot}
|
||||
|
||||
if cli.Pidfile != "" {
|
||||
if err = system.MkdirAll(filepath.Dir(cli.Pidfile), 0o755); err != nil {
|
||||
return errors.Wrap(err, "failed to create pidfile directory")
|
||||
}
|
||||
if err = pidfile.Write(cli.Pidfile, os.Getpid()); err != nil {
|
||||
return errors.Wrap(err, "failed to start daemon")
|
||||
}
|
||||
|
|
|
@ -7,11 +7,9 @@ import (
|
|||
"bytes"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
|
||||
"github.com/docker/docker/pkg/process"
|
||||
"github.com/docker/docker/pkg/system"
|
||||
)
|
||||
|
||||
func checkPIDFileAlreadyExists(path string) error {
|
||||
|
@ -41,8 +39,5 @@ func Write(path string, pid int) error {
|
|||
if err := checkPIDFileAlreadyExists(path); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := system.MkdirAll(filepath.Dir(path), 0o755); err != nil {
|
||||
return err
|
||||
}
|
||||
return os.WriteFile(path, []byte(strconv.Itoa(pid)), 0o644)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue