Bug 22590 - Job Control Shell mark_process_status always returns -1
Summary: Job Control Shell mark_process_status always returns -1
Status: UNCONFIRMED
Alias: None
Product: glibc
Classification: Unclassified
Component: manual (show other bugs)
Version: unspecified
: P2 minor
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-12-12 07:29 UTC by Bob
Modified: 2020-05-23 19:37 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:
fweimer: security-


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Bob 2017-12-12 07:29:15 UTC
First off, the manual is really excellent, thank you to everyone involved.

Section 28.6.2 Initializing the Shell sets the signal handler for SIGCHLD to SIG_IGN, but does not explain why.

As a consequence, in Section 28.6.5 Stopped and Terminated Jobs, wait_for_job always calls mark_process_status with pid=-1 and status=ECHILD, causing jobs in the first_job linked list to never get updated.

This is the correct behavior given POSIX:

> If the parent process of the calling process has set its SA_NOCLDWAIT flag or has set the action for the SIGCHLD signal to SIG_IGN:
> ...
> If a thread in the parent process of the calling process is blocked in wait(), waitpid(), or waitid(), and the parent process has no remaining child processes in the set of waited-for children, the wait(), waitid(), or waitpid() function shall fail and set errno to [ECHILD].

http://pubs.opengroup.org/onlinepubs/9699919799/

The paragraphs above the example in Section 28.6.5 Stopped and Terminated Jobs do call out installing/uninstalling the signal handler for SIGCHLD during specific times of the program's execution. However, it does not document this issue.

Potential Patches:

1. Remove the `signal (SIGCHLD, SIG_IGN);` line from Section 28.6.2 Initializing the Shell
2. Reset the signal handler for SIGCHLD back to SIG_IGN before calling waitpid in update_status and wait_for_job and use this as an opportunity to explain this behavior as an edit to the documentation in Section 28.6.5 Stopped and Terminated Jobs.
Comment 1 aurelien.aptel 2020-05-23 19:37:28 UTC
I have wasted a lot of hours on this. I can confirm this bug: the sample code in the manual cannot work unless you comment out the ignoring of SIGCHLD in init_shell().