Bug 792 - Error in example code on job control in Glibs manual
Summary: Error in example code on job control in Glibs manual
Status: NEW
Alias: None
Product: glibc
Classification: Unclassified
Component: manual (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Roland McGrath
Depends on:
Reported: 2005-03-17 11:43 UTC by Axel Liljencrantz
Modified: 2018-04-19 14:59 UTC (History)
2 users (show)

See Also:
Last reconfirmed:
fweimer: security-


Note You need to log in before you can comment on or make changes to this bug.
Description Axel Liljencrantz 2005-03-17 11:43:45 UTC
The page "Job Control/Implementing a shell/Launching Jobs" contains a code
snippet on how to launch a job. In this code snippet, a newly launched process
tries to call exec before it knows that the entire pipeline has been created.
This is a bug, because a process may change it's session or otherwise change it
status in a way that will make the shell unable to correctly set the process
group of the following programs in the pipeline. Simple pipelines like 'ls -la
--color|more' seem to break from this, which is strange since ls shouldn't do
anything strange. Therefore, each process should wait for the shell to tell them
that they can launch before calling exec. My proposed method for doing this is
to change the code snippet

if (pgid == 0) pgid = pid;
    setpgid (pid, pgid);
if (foreground)
    tcsetpgrp (shell_terminal, pgid);


        while( getpgid(pid) != pgid )

        if (foreground)
            while( tcgetpgrp( 0 ) != pgid )

but there may be other issues with that code.