Nico Huber has submitted this change. ( https://review.coreboot.org/c/coreboot/+/82404?usp=email )
Change subject: util/autoport: Use sudo to call log-making programs ......................................................................
util/autoport: Use sudo to call log-making programs
Running autoport as root has the annoying side effect of making all generated files owned by root. Prevent this by using sudo to invoke log-making programs (lspci, dmidecode, acpidump, inteltool, ectool, superiotool). These programs either need to be run as root or allow collecting more information if run as root (lspci).
In case there's a valid reason not to use sudo, provide a prompt to let autoport run the programs directly, as it originally did. There might be someone trying to run autoport from an OS that lacks sudo.
Change-Id: I4bf4ddf8dd2cb930e9b7303e2ea986d8c072aa7a Signed-off-by: Angel Pons th3fanbus@gmail.com Reviewed-on: https://review.coreboot.org/c/coreboot/+/82404 Tested-by: build bot (Jenkins) no-reply@coreboot.org Reviewed-by: Nico Huber nico.h@gmx.de --- M util/autoport/log_maker.go 1 file changed, 19 insertions(+), 5 deletions(-)
Approvals: build bot (Jenkins): Verified Nico Huber: Looks good to me, approved
diff --git a/util/autoport/log_maker.go b/util/autoport/log_maker.go index ed157c7..6183fb4d 100644 --- a/util/autoport/log_maker.go +++ b/util/autoport/log_maker.go @@ -18,14 +18,22 @@ args []string }
-func (prog LogMakingProgram) TryRunAndSave(output string, prefix string) error { +func ExecCommand(sudo bool, name string, arg []string) *exec.Cmd { + if sudo { + return exec.Command("sudo", append([]string{name}, arg...)...) + } else { + return exec.Command(name, arg...) + } +} + +func (prog LogMakingProgram) TryRunAndSave(output string, sudo bool, prefix string) error { f, err := os.Create(output) if err != nil { log.Fatal(err) } defer f.Close()
- cmd := exec.Command(prefix+prog.name, prog.args...) + cmd := ExecCommand(sudo, prefix+prog.name, prog.args) cmd.Stdout = f cmd.Stderr = f
@@ -36,7 +44,7 @@ return cmd.Wait() }
-func (prog LogMakingProgram) RunAndSave(outDir string) { +func (prog LogMakingProgram) RunAndSave(outDir string, sudo bool) { output := fmt.Sprintf("%s/%s.log", outDir, prog.name) cmdline := strings.Join(append([]string{prog.name}, prog.args...), " ")
@@ -44,7 +52,7 @@
var sb strings.Builder for _, prefix := range prog.prefixes { - err := prog.TryRunAndSave(output, prefix) + err := prog.TryRunAndSave(output, sudo, prefix) if err == nil { return } @@ -157,6 +165,12 @@ func MakeLogs(outDir string) { os.MkdirAll(outDir, 0700)
+ sudo := PromptUserBool("Should autoport use sudo to run the commands to make the logs? "+ + "This is recommended over running autoport as root, since the generated files "+ + "won't be owned by root. If running as root already because sudo isn't available, "+ + "choose 'no'. Otherwise, run autoport as a regular (non-root) user and choose 'yes'.", + true) + probeGFX := PromptUserBool("WARNING: Running inteltool MAY cause your system to hang when it attempts "+ "to probe for graphics registers. Having the graphics registers will help create a better port. "+ "Should autoport probe these registers?", @@ -202,7 +216,7 @@
fmt.Println("Making logs...") for _, prog := range programs { - prog.RunAndSave(outDir) + prog.RunAndSave(outDir, sudo) }
SysSound := "/sys/class/sound/"