diff --git a/main.go b/main.go index dbf790b..2466301 100644 --- a/main.go +++ b/main.go @@ -20,6 +20,7 @@ import ( "net/http" "os" "os/exec" + "os/user" "os/signal" "regexp" "strings" @@ -84,6 +85,14 @@ func (c *CmdIO) Close() error { return nil } +func isRoot() bool { + currentUser, err := user.Current() + if err != nil { + log.Fatalf("[isRoot] Unable to get current user: %s", err) + } + return currentUser.Username == "root" +} + func main() { sigc := make(chan os.Signal, 1) signal.Notify(sigc, @@ -151,6 +160,10 @@ func main() { } else if !strings.Contains(*fioFlags, "--directory") && !strings.Contains(*fioFlags, "--filename") { fioArgs.WriteString(" --directory=/data") } + if ! isRoot() { + log.Printf("Can't invalidate the cache because we're not root") + fioArgs.WriteString(" --invalidate=0") + } cmd := fmt.Sprintf( "%s --name=%s --runtime=%s --status-interval=%s %s %s", *fioPath,