]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
login: use TCSANOW to remove HUPCL
authorKarel Zak <kzak@redhat.com>
Wed, 5 Jun 2013 12:31:00 +0000 (14:31 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 5 Jun 2013 12:43:21 +0000 (14:43 +0200)
Fedora 19, kernel 3.9, systemd 204, telnetd with socket activation.

login(1) code:

        ttt.c_cflag &= ~HUPCL;
        tcsetattr(0, TCSAFLUSH, &ttt);

        close(STDIN_FILENO);
        close(STDOUT_FILENO);
        close(STDERR_FILENO);

        signal(SIGHUP, SIG_IGN);        /* so vhangup() wont kill us */
        vhangup();
        signal(SIGHUP, SIG_DFL);

strace :

ioctl(0, SNDCTL_TMR_CONTINUE or SNDRV_TIMER_IOCTL_GPARAMS or TCSETSF, {B9600 opost isig icanon echo ...}) = 0
close(0)                                = 0
close(1)                                = 0
close(2)                                = 0
--- SIGHUP {si_signo=SIGHUP, si_code=SI_KERNEL} ---
--- SIGTERM {si_signo=SIGTERM, si_code=SI_USER, si_pid=1, si_uid=0} ---
+++ killed by SIGTERM +++

It seems we get SIGHUP (and SIGTERM from systemd) before vhangup().
The problem occur sometimes.

I guess it's because TCSAFLUSH is not applied immediately, so it would
be probably better to use TCSANOW to make the code more robust.

References: https://bugzilla.redhat.com/show_bug.cgi?id=962145
Signed-off-by: Karel Zak <kzak@redhat.com>
login-utils/login.c

index 442ad4048addd9e2ddb4635383c8c8bf1003231d..554c46d4c190b805cfce571f868fa394706f812e 100644 (file)
@@ -395,7 +395,7 @@ static void init_tty(struct login_context *cxt)
        }
 
        /* Kill processes left on this tty */
-       tcsetattr(0, TCSAFLUSH, &ttt);
+       tcsetattr(0, TCSANOW, &ttt);
 
        /*
         * Let's close file decriptors before vhangup
@@ -1312,10 +1312,10 @@ int main(int argc, char **argv)
                close(cnt);
 
        setpgrp();       /* set pgid to pid this means that setsid() will fail */
+       init_tty(&cxt);
 
        openlog("login", LOG_ODELAY, LOG_AUTHPRIV);
 
-       init_tty(&cxt);
        init_loginpam(&cxt);
 
        /* login -f, then the user has already been authenticated */