Skip to contentSkip to conversation

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

PATCH In review Yiwei Lin 2 participants 3 messages Feb 20, 2025 CPU power monitoring

lore
Share & tools
lore

Yiwei Lin

author
#0 lore raw

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

---
V3:
- Modify output message content

V2:
- Check return value from execvp and print message for invalid command
---

---
 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
index f746099b5dac..e123aa578881 100644
@@ -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("Invalid monitor command %s\n", argv[0]);
+			exit(errno);
+		}
 	} else {
 		/* parent */
 		if (child_pid == -1) {
Signature · 1 line
2.34.1
maintainer
#1 lore raw
Quoted 7 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.

---

Note that everything below this gets thrown away.

Quoted 6 lines

V3:
- Modify output message content

V2:
- Check return value from execvp and print message for invalid command
---

These version information goes after the --- below the Signed-off-by

Note that everything below the

Quoted 3 lines

---

This where the patch version stuff goes. I fixed this for now.

thanks,
-- Shuah

author
#2 lore raw
Quoted 20 lines · Shuah Khan
Quoted 7 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.

---

Note that everything below this gets thrown away.

Quoted 6 lines

V3:
- Modify output message content

V2:
- Check return value from execvp and print message for invalid command
---

These version information goes after the --- below the Signed-off-by

Quoted 8 lines

Note that everything below the

Quoted 3 lines

---

This where the patch version stuff goes. I fixed this for now.

Thank you to help for the fix! I'll be careful with the commit message next time. I'm sorry if you experienced any inconvenience with this.

All the best,

Yiwei Lin