From: Karel Zak Date: Wed, 5 Jun 2013 12:31:00 +0000 (+0200) Subject: login: use TCSANOW to remove HUPCL X-Git-Tag: 7-start~48 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8998ad001fdb58ceba4147f8aa4c72203117db25;p=thirdparty%2Futil-linux.git login: use TCSANOW to remove HUPCL 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 --- diff --git a/login-utils/login.c b/login-utils/login.c index 442ad4048a..554c46d4c1 100644 --- a/login-utils/login.c +++ b/login-utils/login.c @@ -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 */