Package: manpages-dev
Version: 6.03-2

Dear Maintainer,

I saw that the manual for exit(3) claimed "the least significant byte of
status (i.e., status & 0xFF) is returned to the parent".  This surprised
me because I was pretty sure that POSIX required the full status to made
available.  It does:
   "the full value shall be available from waitid() and in the siginfo_t
    passed to a signal handler for SIGCHLD."
   https://pubs.opengroup.org/onlinepubs/9699919799/functions/exit.html

And the wait(2) manual page documents it as such:
   "waitid()
    …
    si_status
        Either the exit status of the child, as given  to  _exit(2)  (or
        exit(3)),  or  the  signal  that  caused the child to terminate,
        stop, or continue.  The si_code field can be used  to  determine
        how to interpret this field."

However, this doesn't actually work on Linux.  Here's a test program:
        #include <sys/wait.h>
        #include <stdlib.h>
        #include <stdio.h>
        #include <unistd.h>
        int main() {
                pid_t pid=fork();
                if(pid<0){perror("fork"); exit(1);}
                if(pid==0)_exit(12345);
                siginfo_t si={0};
                pid=waitid(P_PID,pid,&si,WEXITED);
                if(pid<0)perror("waitid");
                printf("pid=%d, status=%d\n",pid,si.si_status);
        }

It prints status=57 (12345 & 255), which is not "as given".  Until Linux
is changed to follow the recent POSIX requirement, the manual should say
that si_status is the low 8 bits.  It might also be helpful to note this
as a deviation from the 2018 edition of POSIX.

By the way, running the test with "strace -f" shows that the child gives
the full status code to the kernel, and the waitid() syscall returns the
truncated version.

- Michael


-- System Information:
Debian Release: trixie/sid
  APT prefers unstable-debug
  APT policy: (500, 'unstable-debug'), (500, 'unstable'), (1, 'experimental')
Architecture: amd64 (x86_64)

Kernel: Linux 6.5.0-1-amd64 (SMP w/32 CPU threads; PREEMPT)
Locale: LANG=en_CA.UTF-8, LC_CTYPE=en_CA.UTF-8 (charmap=UTF-8), 
LANGUAGE=en_CA:en
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled

Versions of packages manpages-dev depends on:
ii  manpages  6.03-2

manpages-dev recommends no packages.

Versions of packages manpages-dev suggests:
ii  man-db [man-browser]  2.12.0-1

-- no debconf information

Attachment: signature.asc
Description: PGP signature

Reply via email to