Skip to content

Commit

Permalink
WIP: debugging
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
  • Loading branch information
thaJeztah committed Nov 28, 2022
1 parent 6e5c11f commit 0962d0b
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 9 deletions.
2 changes: 1 addition & 1 deletion daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -943,7 +943,7 @@ func NewDaemon(ctx context.Context, config *config.Config, pluginStore *plugin.S
return nil, errors.New("Devices cgroup isn't mounted")
}

d.id, err = loadOrCreateID(filepath.Join(config.Root, "engine-id"), rootIDs)
d.id, err = loadOrCreateID(filepath.Join(config.Root, "engine-id"))
if err != nil {
return nil, err
}
Expand Down
10 changes: 3 additions & 7 deletions daemon/id.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"os"
"path/filepath"

"github.com/docker/docker/pkg/idtools"
"github.com/docker/docker/pkg/ioutils"
"github.com/google/uuid"
"github.com/pkg/errors"
Expand All @@ -17,21 +16,18 @@ import (
// Note that this function expects the daemon's root directory to already have
// been created with the right permissions and ownership (usually this would
// be done by daemon.CreateDaemonRoot().
func loadOrCreateID(idPath string, identity idtools.Identity) (string, error) {
func loadOrCreateID(idPath string) (string, error) {
var id string
idb, err := os.ReadFile(idPath)
if os.IsNotExist(err) {
parentDir := filepath.Dir(idPath)
if _, err := os.Stat(parentDir); err != nil {
return "", errors.Wrap(err, "error saving ID file: root directory")
return "", errors.Wrap(err, "error saving ID file")
}
id = uuid.New().String()
if err := ioutils.AtomicWriteFile(idPath, []byte(id), os.FileMode(0600)); err != nil {
if err := ioutils.AtomicWriteFile(idPath, []byte(id), os.FileMode(0o600)); err != nil {
return "", errors.Wrap(err, "error saving ID file")
}
if err := identity.Chown(idPath); err != nil {
return "", err
}
} else if err != nil {
return "", errors.Wrapf(err, "error loading ID file %s", idPath)
} else {
Expand Down
2 changes: 1 addition & 1 deletion integration/daemon/daemon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestConfigDaemonID(t *testing.T) {
// Verify that (if present) the engine-id file takes precedence
const engineID = "this-is-the-engine-id"
idFile := filepath.Join(d.RootDir(), "engine-id")
err := os.WriteFile(idFile, []byte(engineID), 0600)
err := os.WriteFile(idFile, []byte(engineID), 0o644)
assert.NilError(t, err)

d.Start(t, "--iptables=false")
Expand Down

0 comments on commit 0962d0b

Please sign in to comment.