Bug 97353 - init is calling tcgetpgrp() with the wrong argument type.
init is calling tcgetpgrp() with the wrong argument type.
Status: CLOSED RAWHIDE
Product: Red Hat Linux
Classification: Retired
Component: SysVinit (Show other bugs)
9
All Linux
medium Severity medium
: ---
: ---
Assigned To: Bill Nottingham
David Lawrence
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2003-06-13 12:23 EDT by James Olin Oden
Modified: 2014-03-16 22:36 EDT (History)
1 user (show)

See Also:
Fixed In Version: 2.85-1
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2003-06-13 12:27:23 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description James Olin Oden 2003-06-13 12:23:26 EDT
Description of problem:

In init.c the following code exists on line 947 in spawn():

   if (pid > 0) {
        /*
         *      Ignore keyboard signals etc.
         *      Then wait for child to exit.
         */
        SETSIG(sa, SIGINT, SIG_IGN, SA_RESTART);
        SETSIG(sa, SIGTSTP, SIG_IGN, SA_RESTART);
        SETSIG(sa, SIGQUIT, SIG_IGN, SA_RESTART);
        SETSIG(sa, SIGCHLD, SIG_DFL, SA_RESTART);

        while ((f = waitpid(pid, &st, 0)) != pid)
           if (f < 0 && errno == ECHILD)
              break;

        /*
         *      Small optimization. See if stealing
         *      controlling tty back is needed.
         */
        pgrp = tcgetpgrp(f);
        if (pgrp != getpid())
           exit(0);

If f is set in the while loop then it is set to a pid_t (which is
an int), whereas tcgetpgrp expects a filedescriptor of a tty (which
is also an int thus explaining why it even compiles).  Up above in the
code he actually opens the console and sets f to the fd of the console.
The intervening code with waitpid, though, will overwrite the value
of the fd.

I don't fully understand the repurcussions of this but its certainly wrong.

Version-Release number of selected component (if applicable):
2.84-13

How reproducible:
N/A

Steps to Reproduce:
N/A    

Actual results:
N/A

Expected results:
N/A

Additional info:

The fix is to use another variable other than f to capture the return
code of waitpid():

        while ((gotpid = waitpid(pid, &st, 0)) != pid)
           if (gotpid < 0 && errno == ECHILD)
              break;

Of course intializing the new variable is required also.
Comment 1 Bill Nottingham 2003-06-13 12:27:23 EDT
This is fixed in 2.85-1 and later.

Note You need to log in before you can comment on or make changes to this bug.