Skip to contentSkip to conversation

cpupower: monitor: Exit with error status if execvp() fail

PATCH Superseded Yiwei Lin 2 participants 3 messages Feb 11, 2025 – Feb 20, 2025 CPU power monitoring

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Yiwei Lin

author
#0 lore raw

PATCH 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.

---
 tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c | 2 ++
 1 file changed, 2 insertions(+)
tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c +2 -0
index f746099b5dac..0fc0e229739d 100644
@@ -6,6 +6,7 @@
  */
 
 
+#include <errno.h>
 #include <stdio.h>
 #include <unistd.h>
 #include <stdlib.h>
@@ -295,6 +296,7 @@ int fork_it(char **argv)
 	if (!child_pid) {
 		/* child */
 		execvp(argv[0], argv);
+		exit(errno);
 	} else {
 		/* parent */
 		if (child_pid == -1) {
Signature · 1 line
2.34.1
maintainer
#1 lore raw
Quoted 24 lines · Yiwei Lin

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.

---
  tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c | 2 ++
  1 file changed, 2 insertions(+)
tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c +1 -0
index f746099b5dac..0fc0e229739d 100644
@@ -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 298

Quoted 3 lines
tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c +0 -0
@@ -295,6 +296,7 @@ int fork_it(char **argv)
  	if (!child_pid) {
  		/* child */
  		execvp(argv[0], argv);

Good find.

Add a check for execvp() fail and print a message to say that it is an invalid command and then exit.

thanks,
-- Shuah

author
#2 lore raw
Quoted 29 lines · Shuah Khan
Quoted 22 lines · Yiwei Lin

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.

---
  tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c | 2 ++

  1 file changed, 2 insertions(+)
tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c +0 -0
index f746099b5dac..0fc0e229739d 100644
@@ -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 298

Quoted 3 lines
tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c +0 -0
@@ -295,6 +296,7 @@ int fork_it(char **argv)
       if (!child_pid) {
           /* child */
           execvp(argv[0], argv);

Good find.

Quoted 3 lines

Add a check for execvp() fail and print a message to say that it is an invalid command and then exit.

Thank you! I'll send another patch according to the comment.

Quoted 2 lines

thanks,
-- Shuah