Skip to contentSkip to conversation

getpgid01: On Android, pgid(1) is 0 instead of 1

PATCH Superseded Edward Liaw via ltp 3 participants 5 messages Sep 30, 2023 – Oct 26, 2023

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 getpgid01: On Android, pgid(1) is 0 instead of 1

Android's init does not call setpgid(0, 0) so it does not have pgid=1. 0 is functionally equivalent, since pgid 0 means the pgid is the same as the process pid.

---
 testcases/kernel/syscalls/getpgid/getpgid01.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
testcases/kernel/syscalls/getpgid/getpgid01.c +1 -1
index 479fe5dcb..8640f2c93 100644
@@ -37,7 +37,7 @@ static void run(void)
 		TST_EXP_EQ_LI(TST_RET, pgid);
 
 		TST_EXP_PID(getpgid(1));
-		TST_EXP_EQ_LI(TST_RET, 1);
+		TST_EXP_EXPR(TST_RET == 1 || TST_RET == 0, "getpgid(1) == 1 or 0");
 	}
 
 	tst_reap_children();
Signature · 5 lines
2.42.0.582.g8ccd20d70d-goog


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

Hi Edward,

Quoted 14 lines

Android's init does not call setpgid(0, 0) so it does not have pgid=1. 0 is functionally equivalent, since pgid 0 means the pgid is the same as the process pid.

---
 testcases/kernel/syscalls/getpgid/getpgid01.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
testcases/kernel/syscalls/getpgid/getpgid01.c +0 -0
index 479fe5dcb..8640f2c93 100644

testcases/kernel/syscalls/getpgid/getpgid01.c static void run(void) · line 40

Quoted 5 lines
testcases/kernel/syscalls/getpgid/getpgid01.c +1 -1
@@ -37,7 +37,7 @@ static void run(void)
 		TST_EXP_EQ_LI(TST_RET, pgid);
 
 		TST_EXP_PID(getpgid(1));
-		TST_EXP_EQ_LI(TST_RET, 1);
+		TST_EXP_EXPR(TST_RET == 1 || TST_RET == 0, "getpgid(1) == 1 or 0");

Although I don't prefer using often libc specific code, here I'd use it:

#ifndef __ANDROID__ 
		TST_EXP_EQ_LI(TST_RET, 0);
#else
		TST_EXP_EQ_LI(TST_RET, 1);

#endif

Because your code would loosen testing for other libc. Cyril, Li, WDYT?

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#2 lore raw

Hi Petr,

Quoted 24 lines · Petr Vorel

Hi Edward,

Quoted 14 lines

Android's init does not call setpgid(0, 0) so it does not have pgid=1. 0 is functionally equivalent, since pgid 0 means the pgid is the same as the process pid.

---
 testcases/kernel/syscalls/getpgid/getpgid01.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
testcases/kernel/syscalls/getpgid/getpgid01.c +0 -0
index 479fe5dcb..8640f2c93 100644

testcases/kernel/syscalls/getpgid/getpgid01.c static void run(void) · line 40

Quoted 5 lines
testcases/kernel/syscalls/getpgid/getpgid01.c +1 -1
@@ -37,7 +37,7 @@ static void run(void)
              TST_EXP_EQ_LI(TST_RET, pgid);
 
              TST_EXP_PID(getpgid(1));
-             TST_EXP_EQ_LI(TST_RET, 1);
+             TST_EXP_EXPR(TST_RET == 1 || TST_RET == 0, "getpgid(1) == 1 or 0");

Although I don't prefer using often libc specific code, here I'd use it:

Quoted 7 lines
#ifndef __ANDROID__
                TST_EXP_EQ_LI(TST_RET, 0);
#else
                TST_EXP_EQ_LI(TST_RET, 1);

#endif

Because your code would loosen testing for other libc.

I'm fine with that. I tried looking up whether pgid of init should always be 1 but wasn't able to find a good answer, so I defer to your / the team's judgement here. Will send a v2.

Quoted 4 lines

Cyril, Li, WDYT?

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#3 lore raw
In reply to Petr Vorel

Hi!

Quoted 12 lines

testcases/kernel/syscalls/getpgid/getpgid01.c static void run(void) · line 40

Quoted 10 lines
testcases/kernel/syscalls/getpgid/getpgid01.c +1 -1
index 479fe5dcb..8640f2c93 100644
@@ -37,7 +37,7 @@ static void run(void)
 		TST_EXP_EQ_LI(TST_RET, pgid);
 
 		TST_EXP_PID(getpgid(1));
-		TST_EXP_EQ_LI(TST_RET, 1);
+		TST_EXP_EXPR(TST_RET == 1 || TST_RET == 0, "getpgid(1) == 1 or 0");

Although I don't prefer using often libc specific code, here I'd use it:

Quoted 8 lines
#ifndef __ANDROID__ 
		TST_EXP_EQ_LI(TST_RET, 0);
#else
		TST_EXP_EQ_LI(TST_RET, 1);

#endif

Because your code would loosen testing for other libc. Cyril, Li, WDYT?

@Peter what about the case where we bypass all init and boot with init=/bin/sh or init=ltx? I suppose that we will have pgrp set to 0 as well.

What about parsing /proc/1/stat and checking that the value there is the same as reported here, that should work regardless of what pid is the init.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#4 lore raw

Hi,

...

Quoted 6 lines
Quoted 5 lines
#ifndef __ANDROID__ 
		TST_EXP_EQ_LI(TST_RET, 0);
#else
		TST_EXP_EQ_LI(TST_RET, 1);

#endif

Quoted 6 lines
Quoted 2 lines

Because your code would loosen testing for other libc. Cyril, Li, WDYT?

@Peter what about the case where we bypass all init and boot with init=/bin/sh or init=ltx? I suppose that we will have pgrp set to 0 as well.

Ah, so v1 version was better, right?

Quoted 3 lines

What about parsing /proc/1/stat and checking that the value there is the same as reported here, that should work regardless of what pid is the init.

That sounds best to me. I'm sorry Edward, could you please send v3?

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp