2014-06-25 19:40:15

by Shuah Khan

[permalink] [raw]
Subject: [PATCH] tools: msgque improve error handling when not running as root

The test fails in the middle when it is not run as root while
accessing /proc/sys/kernel/msg_next_id. Changed it to check
for root at the beginning of the test. Also added messages
to indicate start and test pass status.

Signed-off-by: Shuah Khan <[email protected]>
---
tools/testing/selftests/ipc/msgque.c | 7 +++++++
1 file changed, 7 insertions(+)

diff --git a/tools/testing/selftests/ipc/msgque.c b/tools/testing/selftests/ipc/msgque.c
index aa290c0..30c627a 100644
--- a/tools/testing/selftests/ipc/msgque.c
+++ b/tools/testing/selftests/ipc/msgque.c
@@ -193,6 +193,12 @@ int main(int argc, char **argv)
int msg, pid, err;
struct msgque_data msgque;

+ if (getuid() != 0) {
+ fprintf(stderr, "Please run the test as root - Exiting.\n");
+ exit(1);
+ }
+
+ printf("Starting ipc tests:\n");
msgque.key = ftok(argv[0], 822155650);
if (msgque.key == -1) {
printf("Can't make key\n");
@@ -235,6 +241,7 @@ int main(int argc, char **argv)
printf("Failed to test queue\n");
goto err_out;
}
+ printf("All ipc tests Passsed\n");
return 0;

err_destroy:
--
1.9.1


2014-06-25 20:05:51

by Davidlohr Bueso

[permalink] [raw]
Subject: Re: [PATCH] tools: msgque improve error handling when not running as root

On Wed, 2014-06-25 at 13:40 -0600, Shuah Khan wrote:
> The test fails in the middle when it is not run as root while
> accessing /proc/sys/kernel/msg_next_id. Changed it to check
> for root at the beginning of the test. Also added messages
> to indicate start and test pass status.
>
> Signed-off-by: Shuah Khan <[email protected]>
> ---
> tools/testing/selftests/ipc/msgque.c | 7 +++++++
> 1 file changed, 7 insertions(+)
>
> diff --git a/tools/testing/selftests/ipc/msgque.c b/tools/testing/selftests/ipc/msgque.c
> index aa290c0..30c627a 100644
> --- a/tools/testing/selftests/ipc/msgque.c
> +++ b/tools/testing/selftests/ipc/msgque.c
> @@ -193,6 +193,12 @@ int main(int argc, char **argv)
> int msg, pid, err;
> struct msgque_data msgque;
>
> + if (getuid() != 0) {
> + fprintf(stderr, "Please run the test as root - Exiting.\n");
> + exit(1);
> + }

Please use err(3).

> + printf("Starting ipc tests:\n");

This is unnecessary and adds nothing to the program.

> msgque.key = ftok(argv[0], 822155650);
> if (msgque.key == -1) {
> printf("Can't make key\n");
> @@ -235,6 +241,7 @@ int main(int argc, char **argv)
> printf("Failed to test queue\n");
> goto err_out;
> }
> + printf("All ipc tests Passsed\n");

So is this.

> return 0;
>
> err_destroy:

2014-06-25 20:15:47

by Shuah Khan

[permalink] [raw]
Subject: Re: [PATCH] tools: msgque improve error handling when not running as root

On 06/25/2014 02:05 PM, Davidlohr Bueso wrote:
> On Wed, 2014-06-25 at 13:40 -0600, Shuah Khan wrote:
>> The test fails in the middle when it is not run as root while
>> accessing /proc/sys/kernel/msg_next_id. Changed it to check
>> for root at the beginning of the test. Also added messages
>> to indicate start and test pass status.
>>
>> Signed-off-by: Shuah Khan <[email protected]>
>> ---
>> tools/testing/selftests/ipc/msgque.c | 7 +++++++
>> 1 file changed, 7 insertions(+)
>>
>> diff --git a/tools/testing/selftests/ipc/msgque.c b/tools/testing/selftests/ipc/msgque.c
>> index aa290c0..30c627a 100644
>> --- a/tools/testing/selftests/ipc/msgque.c
>> +++ b/tools/testing/selftests/ipc/msgque.c
>> @@ -193,6 +193,12 @@ int main(int argc, char **argv)
>> int msg, pid, err;
>> struct msgque_data msgque;
>>
>> + if (getuid() != 0) {
>> + fprintf(stderr, "Please run the test as root - Exiting.\n");
>> + exit(1);
>> + }
>
> Please use err(3).

I will make this printf to be consistent with the rest of the
printfs in this file.

>
>> + printf("Starting ipc tests:\n");
>
> This is unnecessary and adds nothing to the program.

The reason for doing this is it becomes easier to parse when this test
is run as part of run_tests at the top level:

make -C tools/testing/selftests run_tests

-- Shuah

--
Shuah Khan
Senior Linux Kernel Developer - Open Source Group
Samsung Research America(Silicon Valley)
[email protected] | (970) 672-0658

2014-06-25 20:22:17

by Davidlohr Bueso

[permalink] [raw]
Subject: Re: [PATCH] tools: msgque improve error handling when not running as root

On Wed, 2014-06-25 at 14:15 -0600, Shuah Khan wrote:
> On 06/25/2014 02:05 PM, Davidlohr Bueso wrote:
> > On Wed, 2014-06-25 at 13:40 -0600, Shuah Khan wrote:
> >> The test fails in the middle when it is not run as root while
> >> accessing /proc/sys/kernel/msg_next_id. Changed it to check
> >> for root at the beginning of the test. Also added messages
> >> to indicate start and test pass status.
> >>
> >> Signed-off-by: Shuah Khan <[email protected]>
> >> ---
> >> tools/testing/selftests/ipc/msgque.c | 7 +++++++
> >> 1 file changed, 7 insertions(+)
> >>
> >> diff --git a/tools/testing/selftests/ipc/msgque.c b/tools/testing/selftests/ipc/msgque.c
> >> index aa290c0..30c627a 100644
> >> --- a/tools/testing/selftests/ipc/msgque.c
> >> +++ b/tools/testing/selftests/ipc/msgque.c
> >> @@ -193,6 +193,12 @@ int main(int argc, char **argv)
> >> int msg, pid, err;
> >> struct msgque_data msgque;
> >>
> >> + if (getuid() != 0) {
> >> + fprintf(stderr, "Please run the test as root - Exiting.\n");
> >> + exit(1);
> >> + }
> >
> > Please use err(3).
>
> I will make this printf to be consistent with the rest of the
> printfs in this file.

Can you please update the file then. err(EXIT_FAILURE, ...) is a lot
nicer than fprintf+exit combos all over the place.

>
> >
> >> + printf("Starting ipc tests:\n");
> >
> > This is unnecessary and adds nothing to the program.
>
> The reason for doing this is it becomes easier to parse when this test
> is run as part of run_tests at the top level:

Parsing reasons should not determine such things. What if I add shm, or
semaphore tests to the ipc dir?? Then the text would be bogus. What if
not all tests pass? There is no way of determining a percentage of
completeness. Please do not add such things for a simple msg queue
program as it doesn't necessarily represent ipc selftests.

2014-06-25 20:32:09

by Shuah Khan

[permalink] [raw]
Subject: Re: [PATCH] tools: msgque improve error handling when not running as root

On 06/25/2014 02:22 PM, Davidlohr Bueso wrote:
> On Wed, 2014-06-25 at 14:15 -0600, Shuah Khan wrote:
>> On 06/25/2014 02:05 PM, Davidlohr Bueso wrote:
>>> On Wed, 2014-06-25 at 13:40 -0600, Shuah Khan wrote:
>>>> The test fails in the middle when it is not run as root while
>>>> accessing /proc/sys/kernel/msg_next_id. Changed it to check
>>>> for root at the beginning of the test. Also added messages
>>>> to indicate start and test pass status.
>>>>
>>>> Signed-off-by: Shuah Khan <[email protected]>
>>>> ---
>>>> tools/testing/selftests/ipc/msgque.c | 7 +++++++
>>>> 1 file changed, 7 insertions(+)
>>>>
>>>> diff --git a/tools/testing/selftests/ipc/msgque.c b/tools/testing/selftests/ipc/msgque.c
>>>> index aa290c0..30c627a 100644
>>>> --- a/tools/testing/selftests/ipc/msgque.c
>>>> +++ b/tools/testing/selftests/ipc/msgque.c
>>>> @@ -193,6 +193,12 @@ int main(int argc, char **argv)
>>>> int msg, pid, err;
>>>> struct msgque_data msgque;
>>>>
>>>> + if (getuid() != 0) {
>>>> + fprintf(stderr, "Please run the test as root - Exiting.\n");
>>>> + exit(1);
>>>> + }
>>>
>>> Please use err(3).
>>
>> I will make this printf to be consistent with the rest of the
>> printfs in this file.
>
> Can you please update the file then. err(EXIT_FAILURE, ...) is a lot
> nicer than fprintf+exit combos all over the place.

That would make sense as a separate patch and not as part of fix for
this problem.

>
>>
>>>
>>>> + printf("Starting ipc tests:\n");
>>>
>>> This is unnecessary and adds nothing to the program.
>>
>> The reason for doing this is it becomes easier to parse when this test
>> is run as part of run_tests at the top level:
>
> Parsing reasons should not determine such things. What if I add shm, or
> semaphore tests to the ipc dir?? Then the text would be bogus. What if
> not all tests pass? There is no way of determining a percentage of
> completeness. Please do not add such things for a simple msg queue
> program as it doesn't necessarily represent ipc selftests.
>

I can drop these messages. However, I do think it would make sense
to add a summary of tests passed. Similar to what mqueue does for
example.

-- Shuah

--
Shuah Khan
Senior Linux Kernel Developer - Open Source Group
Samsung Research America(Silicon Valley)
[email protected] | (970) 672-0658