Skip to content

Commit cfbba2f

Browse files
authored
Merge pull request #62 from ROCm/enrootdocs
Fix for #59
2 parents d36872b + 22172ca commit cfbba2f

3 files changed

Lines changed: 22 additions & 7 deletions

File tree

cmd/amd-ctk/runtime/configure/configure.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package configure
1818

1919
import (
2020
"fmt"
21-
"os/user"
2221

2322
"github.com/ROCm/container-toolkit/cmd/amd-ctk/runtime/engine"
2423
"github.com/ROCm/container-toolkit/cmd/amd-ctk/runtime/engine/docker"
@@ -90,11 +89,6 @@ func AddNewCommand() *cli.Command {
9089
}
9190

9291
func validateConfigOptions(c *cli.Context, cfgOptions *configOptions) error {
93-
94-
curUser, err := user.Current()
95-
if err != nil || curUser.Uid != "0" {
96-
return fmt.Errorf("Permission denied: Not running as root")
97-
}
9892
if cfgOptions.runtime != "docker" {
9993
return fmt.Errorf("unsupported runtime engine: %v", cfgOptions.runtime)
10094
}

internal/cdi/cdi_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func TestInterface(t *testing.T) {
6161
err := cdi.GenerateSpec()
6262
Assert(t, err == nil, fmt.Sprintf("failed to generate cdi spec, Err: %v", err))
6363

64-
cdi.specPath = "/tmp"
64+
cdi.specPath = "/tmp/"
6565
err = cdi.WriteSpec()
6666
Assert(t, err == nil, fmt.Sprintf("WriteSpec() returned error %v", err))
6767

internal/logger/logger.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,31 @@ func SetLogFile(file string) {
4444

4545
// SetLogDir sets the path to the directory of logs
4646
func SetLogDir() {
47+
48+
isWriteable := func(path string) bool {
49+
// Create a temporary file in the specified directory.
50+
// os.CreateTemp will return an error if the directory is not writable.
51+
file, err := os.CreateTemp(path, "tmp-test-")
52+
if err != nil {
53+
return false
54+
}
55+
file.Close() // Close the file
56+
os.Remove(file.Name()) // Clean up the temporary file
57+
58+
return true
59+
}
60+
4761
if os.Getenv("LOGDIR") != "" {
4862
logdir = os.Getenv("LOGDIR")
63+
64+
//check if the user has permission to write to this location
65+
if !isWriteable(logdir) {
66+
log.Fatalf("User doesn't have write permission for the specified directory: %v", logdir)
67+
}
68+
4969
return
5070
}
71+
5172
// Get the current user's information.
5273
currentUser, err := user.Current()
5374
if err != nil {

0 commit comments

Comments
 (0)