Skip to content

Commit

Permalink
[feat] Prompt user and exit if process on macOS is not running with s…
Browse files Browse the repository at this point in the history
…udo privileges
  • Loading branch information
zzzk1 committed Sep 2, 2024
1 parent 7a321a4 commit 91e233e
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions cmd/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"os"
"os/signal"
"os/user"
"runtime"
"strconv"
"strings"
Expand Down Expand Up @@ -46,6 +47,15 @@ func Main() {
klog.Infof("FLAG: --%s=%q", flag.Name, flag.Value)
})

// Process on macOS must run using sudo
if runtime.GOOS == "darwin" {
currentUser, _ := user.Current()
if currentUser.Uid != "0" {
fmt.Println("Please run this again with `sudo`.")
os.Exit(1)
}
}

// trap Ctrl+C and call cancel on the context
ctx := context.Background()
ctx, cancel := context.WithCancel(ctx)
Expand Down

0 comments on commit 91e233e

Please sign in to comment.