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

Yiwei Lin posted 1 patch 10 months, 1 week ago
There is a newer version of this series
tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c | 2 ++
1 file changed, 2 insertions(+)
[PATCH] cpupower: monitor: Exit with error status if execvp() fail
Posted by Yiwei Lin 10 months, 1 week ago
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.

Signed-off-by: Yiwei Lin <s921975628@gmail.com>
---
 tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c b/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c
index f746099b5dac..0fc0e229739d 100644
--- a/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c
+++ b/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c
@@ -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) {
-- 
2.34.1
Re: [PATCH] cpupower: monitor: Exit with error status if execvp() fail
Posted by Shuah Khan 10 months ago
On 2/11/25 03:05, Yiwei Lin wrote:
> 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.
> 
> Signed-off-by: Yiwei Lin <s921975628@gmail.com>
> ---
>   tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c | 2 ++
>   1 file changed, 2 insertions(+)
> 
> diff --git a/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c b/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c
> index f746099b5dac..0fc0e229739d 100644
> --- a/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c
> +++ b/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c
> @@ -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);

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
Re: [PATCH] cpupower: monitor: Exit with error status if execvp() fail
Posted by Yiwei Lin 9 months, 4 weeks ago
On 2/20/2025 4:27 AM, Shuah Khan wrote:
> On 2/11/25 03:05, Yiwei Lin wrote:
>> 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.
>>
>> Signed-off-by: Yiwei Lin <s921975628@gmail.com>
>> ---
>>   tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c | 2 ++
>>   1 file changed, 2 insertions(+)
>>
>> diff --git 
>> a/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c 
>> b/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c
>> index f746099b5dac..0fc0e229739d 100644
>> --- a/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c
>> +++ b/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c
>> @@ -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);
>
> Good find.
>
> 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.
> thanks,
> -- Shuah