From 122b77d4821404f7c3753c8b138c3150d7e6c3e9 Mon Sep 17 00:00:00 2001 From: "Harper, Jason M" Date: Sun, 8 Dec 2024 17:04:05 -0800 Subject: [PATCH 1/2] timeout on commands --- internal/script/script_defs.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/internal/script/script_defs.go b/internal/script/script_defs.go index eead1c6..65465a2 100644 --- a/internal/script/script_defs.go +++ b/internal/script/script_defs.go @@ -471,7 +471,7 @@ rdmsr 0x2FFE`, // uncore client cha count, uncore cha count, uncore cha count sp }, { Name: LshwScriptName, - Script: "lshw -businfo -numeric", + Script: "timeout 30 lshw -businfo -numeric", Depends: []string{"lshw"}, Superuser: true, }, @@ -489,7 +489,7 @@ rdmsr 0x2FFE`, // uncore client cha count, uncore cha count, uncore cha count sp }, { Name: NicInfoScriptName, - Script: `lshw -businfo -numeric | grep -E "^(pci|usb).*? \S+\s+network\s+\S.*?" \ + Script: `timeout 30 lshw -businfo -numeric | grep -E "^(pci|usb).*? \S+\s+network\s+\S.*?" \ | while read -r a ifc c ; do ethtool "$ifc" ethtool -i "$ifc" @@ -588,26 +588,26 @@ done`, }, { Name: IpmitoolSensorsScriptName, - Script: "LC_ALL=C ipmitool sdr list full", + Script: "LC_ALL=C timeout 30 ipmitool sdr list full", Superuser: true, Depends: []string{"ipmitool"}, }, { Name: IpmitoolChassisScriptName, - Script: "LC_ALL=C ipmitool chassis status", + Script: "LC_ALL=C timeout 30 ipmitool chassis status", Superuser: true, Depends: []string{"ipmitool"}, }, { Name: IpmitoolEventsScriptName, - Script: `LC_ALL=C ipmitool sel elist | tail -n20 | cut -d'|' -f2-`, + Script: `LC_ALL=C timeout 30 ipmitool sel elist | tail -n20 | cut -d'|' -f2-`, Superuser: true, Lkms: []string{"ipmi_devintf", "ipmi_si"}, Depends: []string{"ipmitool"}, }, { Name: IpmitoolEventTimeScriptName, - Script: "LC_ALL=C ipmitool sel time get", + Script: "LC_ALL=C timeout 30 ipmitool sel time get", Superuser: true, Depends: []string{"ipmitool"}, }, From 472d7a281b945aca6bda55642eae2f4c453d8024 Mon Sep 17 00:00:00 2001 From: "Harper, Jason M" Date: Sun, 8 Dec 2024 17:14:21 -0800 Subject: [PATCH 2/2] remove timeout from script definition as it is unused --- internal/script/script.go | 15 +-------------- internal/script/script_defs.go | 12 ++++++++++++ internal/script/script_test.go | 3 --- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/internal/script/script.go b/internal/script/script.go index e19f9fe..4f970c1 100644 --- a/internal/script/script.go +++ b/internal/script/script.go @@ -21,19 +21,6 @@ import ( //go:embed resources var Resources embed.FS -type ScriptDefinition struct { - Name string // just a name - Script string // the bash script that will be run - Architectures []string // architectures, i.e., x86_64, arm64. If empty, it will run on all architectures. - Families []string // families, e.g., 6, 7. If empty, it will run on all families. - Models []string // models, e.g., 62, 63. If empty, it will run on all models. - Lkms []string // loadable kernel modules - Depends []string // binary dependencies that must be available for the script to run - Superuser bool // requires sudo or root - Sequential bool // run script sequentially (not at the same time as others) - Timeout int // seconds -} - type ScriptOutput struct { ScriptDefinition Stdout string @@ -254,7 +241,7 @@ func RunScriptAsync(myTarget target.Target, script ScriptDefinition, localTempDi }() } cmd := prepareCommand(script, myTarget.GetTempDirectory()) - err = myTarget.RunCommandAsync(cmd, stdoutChannel, stderrChannel, exitcodeChannel, script.Timeout, cmdChannel) + err = myTarget.RunCommandAsync(cmd, stdoutChannel, stderrChannel, exitcodeChannel, 0, cmdChannel) errorChannel <- err } diff --git a/internal/script/script_defs.go b/internal/script/script_defs.go index 65465a2..42bf16d 100644 --- a/internal/script/script_defs.go +++ b/internal/script/script_defs.go @@ -11,6 +11,18 @@ import ( "strings" ) +type ScriptDefinition struct { + Name string // just a name + Script string // the bash script that will be run + Architectures []string // architectures, i.e., x86_64, arm64. If empty, it will run on all architectures. + Families []string // families, e.g., 6, 7. If empty, it will run on all families. + Models []string // models, e.g., 62, 63. If empty, it will run on all models. + Lkms []string // loadable kernel modules + Depends []string // binary dependencies that must be available for the script to run + Superuser bool // requires sudo or root + Sequential bool // run script sequentially (not at the same time as others) +} + const ( HostnameScriptName = "hostname" DateScriptName = "date" diff --git a/internal/script/script_test.go b/internal/script/script_test.go index b3ea5c9..66ed591 100644 --- a/internal/script/script_test.go +++ b/internal/script/script_test.go @@ -38,7 +38,6 @@ func TestRunScript(t *testing.T) { Superuser: superuser, Lkms: []string{}, Depends: []string{}, - Timeout: 0, } tempDir, err := os.MkdirTemp(os.TempDir(), "test") if err != nil { @@ -73,7 +72,6 @@ echo "Core Count: $num_cores_per_socket"`, Superuser: superuser, Lkms: []string{}, Depends: []string{}, - Timeout: 0, } tempDir, err = os.MkdirTemp(os.TempDir(), "test") if err != nil { @@ -109,7 +107,6 @@ mpstat -u -T -I SCPU -P ALL 1 $count`, Superuser: superuser, Lkms: []string{}, Depends: []string{"mpstat"}, - Timeout: 0, } tempDir, err := os.MkdirTemp(os.TempDir(), "test") if err != nil {