cpupower: monitor: Exit with error status if execvp() fail
PATCH v2 1/1 cpupower: monitor: Exit with error status if execvp() fail
In the case that we give a invalid command to idle_monitor for monitoring, the execvp() will fail and thus go to the next line. As a result, we'll see two differnt monitoring output. For example, running cpupower monitor -i 5 invalidcmd which invalidcmd is not executable.
---
V2:
- fix according to review from Shuah
---
--- tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c +5 -1
@@ -6,6 +6,7 @@*/ +#include <errno.h> #include <stdio.h> #include <unistd.h> #include <stdlib.h>
@@ -294,7 +295,10 @@ int fork_it(char **argv)if (!child_pid) {/* child */ -execvp (argv[0 ], argv); +if (execvp (argv[0 ], argv) ==-1 ) { +printf ("Fail to execute %s\n" , argv[0 ]); +exit (errno); + } }else {/* parent */ if (child_pid ==-1 ) {
Signature · 1 line
2.34.1
Shuah Khan
maintainerQuoted 29 lines · Yiwei Lin
In the case that we give a invalid command to
idle_monitorfor monitoring, theexecvp()will fail and thus go to the next line. As a result, we'll see two differnt monitoring output. For example, runningcpupower monitor -i 5 invalidcmdwhichinvalidcmdis not executable.---
V2:
- fix according to review from Shuah
---Signed-off-by Yiwei Lin <[email protected]>--- tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c +1
-0@@ -6,6 +6,7 @@*/ +#include <errno.h> #include <stdio.h> #include <unistd.h> #include <stdlib.h>
tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c int fork_it(char **argv) · line 299
Quoted 6 lines
tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c +2
-1@@ -294,7 +295,10 @@ int fork_it(char **argv)if (!child_pid) {/* child */ -execvp (argv[0 ], argv); +if (execvp (argv[0 ], argv) ==-1 ) { +printf ("Fail to execute %s\n" , argv[0 ]);
Invalid monitor command will be a better message than saying "failed to execute"
thanks,
-- Shuahg