]> Projects (at) Tadryanom (dot) Me - AdrOS.git/commitdiff
Fix fulltest TIOCGPGRP failure when run from shell
authorTulio A M Mendes <[email protected]>
Fri, 17 Apr 2026 17:01:34 +0000 (14:01 -0300)
committerTulio A M Mendes <[email protected]>
Fri, 17 Apr 2026 17:01:34 +0000 (14:01 -0300)
When fulltest runs from /bin/sh (rather than as init directly), the
shell has already claimed the controlling TTY via setsid(), setting
tty_fg_pgrp to a non-zero value. The test assumed fg == 0, which
only holds when running as PID 1 (session_id=0, pgrp_id=0).

Fix: compare TIOCGPGRP result against sys_getpgrp() instead of
hardcoded 0, use our own pgrp for TIOCSPGRP success test, and use
fg=-1 (EINVAL) instead of fg=1 for the expected-failure case.

Also rename 'hello from init.elf' to 'hello from fulltest.elf' in
both the test binary and the smoke test expectations.

tests/smoke_test.exp
user/cmds/fulltest/fulltest.c

index 33f119190ac89424d4f45e60b50d910ffdf126c2..baa9501082013ccc325ea9cdc7ddeada3b41cabe 100755 (executable)
@@ -49,7 +49,7 @@ set tests {
     {"ATA DMA mode"         "\\[ATA\\] Channel 0: DMA mode."}
     {"SMP CPUs active"      "CPU\\(s\\) active."}
     {"User ring3 entry"     "\\[USER\\] enter ring3"}
-    {"init.elf hello"       "\\[test\\] hello from init.elf"}
+    {"fulltest.elf hello"   "\\[test\\] hello from fulltest.elf"}
     {"open/read/close"      "\\[test\\] open/read/close OK"}
     {"overlay copy-up"      "\\[test\\] overlay copy-up OK"}
     {"lseek/stat/fstat"     "\\[test\\] lseek/stat/fstat OK"}
index a9e41110d03a3271809390b8aafc32a9c46f95dd..b9adacdce4aa9e22c96056262042165ad46aa7bf 100644 (file)
@@ -1463,7 +1463,7 @@ void _start(void) {
         "mov %ax, %gs\n"
     );
 
-    static const char msg[] = "[test] hello from init.elf\n";
+    static const char msg[] = "[test] hello from fulltest.elf\n";
     (void)sys_write(1, msg, (uint32_t)(sizeof(msg) - 1));
 
     static const char path[] = "/sbin/fulltest";
@@ -1820,21 +1820,23 @@ void _start(void) {
             sys_exit(1);
         }
 
+        int my_pgrp = sys_getpgrp();
+
         int fg = -1;
-        if (sys_ioctl(fd, TIOCGPGRP, &fg) < 0 || fg != 0) {
+        if (sys_ioctl(fd, TIOCGPGRP, &fg) < 0 || fg != my_pgrp) {
             sys_write(1, "[test] ioctl TIOCGPGRP failed\n",
                       (uint32_t)(sizeof("[test] ioctl TIOCGPGRP failed\n") - 1));
             sys_exit(1);
         }
 
-        fg = 0;
+        fg = my_pgrp;
         if (sys_ioctl(fd, TIOCSPGRP, &fg) < 0) {
             sys_write(1, "[test] ioctl TIOCSPGRP failed\n",
                       (uint32_t)(sizeof("[test] ioctl TIOCSPGRP failed\n") - 1));
             sys_exit(1);
         }
 
-        fg = 1;
+        fg = -1;
         if (sys_ioctl(fd, TIOCSPGRP, &fg) >= 0) {
             sys_write(1, "[test] ioctl TIOCSPGRP expected fail\n",
                       (uint32_t)(sizeof("[test] ioctl TIOCSPGRP expected fail\n") - 1));