MCPcopy
hub / github.com/keploy/keploy / ShouldReexecWithSudo

Function ShouldReexecWithSudo

utils/reexec_linux.go:70–91  ·  view source on GitHub ↗

ShouldReexecWithSudo checks if keploy should re-execute itself with sudo. Returns true if: 1. A Docker/Docker Compose command is detected in the -c/--command flag, OR 2. The "cloud replay" subcommand is being used (it generates a docker-compose internally) AND Keploy is NOT currently running as root

()

Source from the content-addressed store, hash-verified

68// 2. The "cloud replay" subcommand is being used (it generates a docker-compose internally)
69// AND Keploy is NOT currently running as root.
70func ShouldReexecWithSudo() bool {
71 // Already running as root - no need to re-exec
72 if os.Geteuid() == 0 {
73 return false
74 }
75
76 // Check if this is a "cloud replay" command, which always needs root
77 // because it generates and runs a docker-compose file internally.
78 if isCloudReplayCmd(os.Args) {
79 return true
80 }
81
82 // Extract the command from arguments
83 cmd := ExtractCommandFromArgs(os.Args)
84 if cmd == "" {
85 return false
86 }
87
88 // Check if it's a Docker command
89 cmdType := FindDockerCmd(cmd)
90 return IsDockerCmd(cmdType)
91}
92
93// isCloudReplayCmd checks if the args represent the "keploy cloud replay" subcommand.
94func isCloudReplayCmd(args []string) bool {

Callers

nothing calls this directly

Calls 4

isCloudReplayCmdFunction · 0.85
ExtractCommandFromArgsFunction · 0.85
FindDockerCmdFunction · 0.85
IsDockerCmdFunction · 0.85

Tested by

no test coverage detected