Skip to content

Commit d36872b

Browse files
authored
Merge pull request #61 from ROCm/enrootdocs
Fix for #59
2 parents 901f3ed + 1585c9f commit d36872b

2 files changed

Lines changed: 23 additions & 5 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ AMD Container Toolkit offers tools to streamline the use of AMD GPUs with contai
66
# Requirements
77
- Ubuntu 22.02 or 24.04, or RHEL/CentOS 9
88
- Docker version 25 or later
9+
- All the 'amd-ctk runtime configure' commands should be run as root/sudo
910

1011
# Quick Start
1112
Install the Container toolkit.
@@ -131,6 +132,7 @@ To install the AMD Container Toolkit on RHEL/CentOS 9 systems, follow these step
131132
```
132133
133134
3. List available GPUs.
135+
If this command is run as root, the container-toolkit logs go to /var/log/amd-container-runtime.log, otherwise they go to the user's home directory.
134136
135137
```text
136138
> amd-ctk cdi list

internal/logger/logger.go

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package logger
1919
import (
2020
"log"
2121
"os"
22+
"os/user"
2223
"path/filepath"
2324
"sync"
2425
)
@@ -42,17 +43,32 @@ func SetLogFile(file string) {
4243
}
4344

4445
// SetLogDir sets the path to the directory of logs
45-
func SetLogDir(dir string) {
46-
logdir = dir
46+
func SetLogDir() {
47+
if os.Getenv("LOGDIR") != "" {
48+
logdir = os.Getenv("LOGDIR")
49+
return
50+
}
51+
// Get the current user's information.
52+
currentUser, err := user.Current()
53+
if err != nil {
54+
log.Fatalf("Failed to get current user: %v", err)
55+
}
56+
// for root user, log dir is /var/log
57+
if currentUser.Uid != "0" {
58+
//Non-Root user, setting log directory to user's home directory
59+
homeDir, err := os.UserHomeDir()
60+
if err != nil {
61+
log.Fatalf("Failed to get user home directory: %v", err)
62+
}
63+
logdir = homeDir
64+
}
4765
}
4866

4967
func initLogger(console bool) {
5068
if console {
5169
Log = log.New(os.Stdout, logPrefix, log.Lmsgprefix)
5270
} else {
53-
if os.Getenv("LOGDIR") != "" {
54-
logdir = os.Getenv("LOGDIR")
55-
}
71+
SetLogDir()
5672

5773
outfile, err := os.OpenFile(filepath.Join(logdir, logfile),
5874
os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0666)

0 commit comments

Comments
 (0)