Bug 97353 - init is calling tcgetpgrp() with the wrong argument type.
Summary: init is calling tcgetpgrp() with the wrong argument type.
Status: CLOSED RAWHIDE
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: SysVinit   
(Show other bugs)
Version: 9
Hardware: All
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Bill Nottingham
QA Contact: David Lawrence
URL:
Whiteboard:
Keywords:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2003-06-13 16:23 UTC by James Olin Oden
Modified: 2014-03-17 02:36 UTC (History)
1 user (show)

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


Attachments (Terms of Use)

Description James Olin Oden 2003-06-13 16:23:26 UTC
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 16:27:23 UTC
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.