Debian Bug report logs - #1053688
wait(2) says si_status will contain the exit code "as given"

version graph

Package: manpages-dev; Maintainer for manpages-dev is Dr. Tobias Quathamer <[email protected]>; Source for manpages-dev is src:manpages (PTS, buildd, popcon).

Reported by: Michael Gold <[email protected]>

Date: Sun, 8 Oct 2023 19:45:02 UTC

Severity: normal

Found in version manpages/6.03-2

Reply or subscribe to this bug.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to [email protected], Dr. Tobias Quathamer <[email protected]>:
Bug#1053688; Package manpages-dev. (Sun, 08 Oct 2023 19:45:04 GMT) (full text, mbox, link).


Acknowledgement sent to Michael Gold <[email protected]>:
New Bug report received and forwarded. Copy sent to Dr. Tobias Quathamer <[email protected]>. (Sun, 08 Oct 2023 19:45:04 GMT) (full text, mbox, link).


Message #5 received at [email protected] (full text, mbox, reply):

From: Michael Gold <[email protected]>
To: Debian Bug Tracking System <[email protected]>
Subject: wait(2) says si_status will contain the exit code "as given"
Date: Sun, 8 Oct 2023 19:43:16 +0000
[Message part 1 (text/plain, inline)]
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
[signature.asc (application/pgp-signature, inline)]

Send a report that this bug log contains spam.


Debian bug tracking system administrator <[email protected]>. Last modified: Sun Sep 22 03:33:11 2024; Machine Name: buxtehude

Debian Bug tracking system

Debbugs is free software and licensed under the terms of the GNU Public License version 2. The current version can be obtained from https://bugs.debian.org/debbugs-source/.

Copyright © 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson, 2005-2017 Don Armstrong, and many other contributors.