diff options
author | Angel Pons <th3fanbus@gmail.com> | 2024-05-13 17:52:22 +0200 |
---|---|---|
committer | Nico Huber <nico.h@gmx.de> | 2024-08-05 08:58:18 +0000 |
commit | ea54d3e4d03654410d673354e2d1f90dad8a7cde (patch) | |
tree | a9ac33c50da2d044b1dd2d090960617b60bc4567 /util/autoport/log_maker.go | |
parent | 52a1c61b97792ea592eeaa13a61692f4dd0580e8 (diff) |
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>
Diffstat (limited to 'util/autoport/log_maker.go')
-rw-r--r-- | util/autoport/log_maker.go | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/util/autoport/log_maker.go b/util/autoport/log_maker.go index ed157c70df..6183fb4d80 100644 --- a/util/autoport/log_maker.go +++ b/util/autoport/log_maker.go @@ -18,14 +18,22 @@ type LogMakingProgram struct { 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 @@ func (prog LogMakingProgram) TryRunAndSave(output string, prefix string) error { 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 @@ func (prog LogMakingProgram) RunAndSave(outDir string) { 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 MakeHDALogs(outDir string, cardName string) { 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 @@ func MakeLogs(outDir string) { fmt.Println("Making logs...") for _, prog := range programs { - prog.RunAndSave(outDir) + prog.RunAndSave(outDir, sudo) } SysSound := "/sys/class/sound/" |