diff mbox series

Fix issue when running fcntl31 and fcntl31_64 over SSH as session leader

Message ID 20200513121327.16342-1-ysionneau@kalray.eu
State Accepted
Headers show
Series Fix issue when running fcntl31 and fcntl31_64 over SSH as session leader | expand

Commit Message

Yann Sionneau May 13, 2020, 12:13 p.m. UTC
If you run the test like this:
ssh localhost path/to/fcntl31

It will fail like this:
TBROK  :  fcntl31.c:121: setpgrp() failed: errno=EPERM(1): Operation not permitted

As man page for setpgrp says, it is indeed not permitted to change process group ID
when you are session leader (PID == SID).

Signed-off-by: Yann Sionneau <ysionneau@kalray.eu>
---
 testcases/kernel/syscalls/fcntl/fcntl31.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

Comments

Cyril Hrubis Feb. 17, 2021, 4:24 p.m. UTC | #1
Hi!
Applied, thanks.
diff mbox series

Patch

diff --git a/testcases/kernel/syscalls/fcntl/fcntl31.c b/testcases/kernel/syscalls/fcntl/fcntl31.c
index 52b4932fa..fd284fd7e 100644
--- a/testcases/kernel/syscalls/fcntl/fcntl31.c
+++ b/testcases/kernel/syscalls/fcntl/fcntl31.c
@@ -116,9 +116,12 @@  static void setup(void)
 
 	pid = getpid();
 
-	ret = setpgrp();
-	if (ret < 0)
-		tst_brkm(TBROK | TERRNO, cleanup, "setpgrp() failed");
+	/* Changing process group ID is forbidden when PID == SID i.e. we are session leader */
+	if (pid != getsid(0)) {
+		ret = setpgrp();
+		if (ret < 0)
+			tst_brkm(TBROK | TERRNO, cleanup, "setpgrp() failed");
+	}
 	pgrp_pid = getpgid(0);
 	if (pgrp_pid < 0)
 		tst_brkm(TBROK | TERRNO, cleanup, "getpgid() failed");