From oleg@core.zp.ua  Wed Dec 18 03:37:18 2002
Return-Path: <oleg@core.zp.ua>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id A960A37B401
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 18 Dec 2002 03:37:18 -0800 (PST)
Received: from core.zp.ua (core.zp.ua [193.108.112.7])
	by mx1.FreeBSD.org (Postfix) with ESMTP id A831D43ED4
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 18 Dec 2002 03:37:16 -0800 (PST)
	(envelope-from oleg@core.zp.ua)
Received: from core.zp.ua (oleg@localhost [127.0.0.1])
	by core.zp.ua with ESMTP id gBIBb5af050363
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 18 Dec 2002 13:37:05 +0200 (EET)
	(envelope-from oleg@core.zp.ua)
Received: (from oleg@localhost)
	by core.zp.ua  id gBIBb53K050362;
	 Wed, 18 Dec 2002 13:37:05 +0200 (EET)
Message-Id: <200212181137.gBIBb53K050362@core.zp.ua>
Date: Wed, 18 Dec 2002 13:37:05 +0200 (EET)
From: "Oleg V. Nauman" <oleg@reis.zp.ua>
Reply-To: "Oleg V. Nauman" <oleg@reis.zp.ua>
To: FreeBSD-gnats-submit@freebsd.org
Subject: Open file descriptors and signal handling in the child login process
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         46352
>Category:       bin
>Synopsis:       [patch] login(1) open file descriptors and signal handling in the child login process
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Dec 18 03:40:01 PST 2002
>Closed-Date:    
>Last-Modified:  Sat May 24 16:25:14 UTC 2008
>Originator:     Oleg V. Nauman <oleg@reis.zp.ua>
>Release:        FreeBSD 4.7-STABLE i386
>Organization:
ReIS Ltd.
>Environment:
>Description:
	Child login process in STABLE leaves open file descriptors associated with terminal
	and has some problems with signals handling.
>How-To-Repeat:
	Log in on the terminal line, start pppd and then kill -HUP pppd
	This leaves some errors in the ppp log file, such as:
	pppd: ioctl (PPPIOCGFLAGS): Inappropriate ioctl for device
	pppd: ioctl (PPPIOCGFLAGS): Inappropriate ioctl for device
	pppd: ioctl(PPPIOCSASYNCMAP): Inappropriate ioctl for device
	pppd: Couldn't restore device fd flags: Inappropriate ioctl for device
	pppd: ioctl(TIOCSETD): Inappropriate ioctl for device
	pppd: tcsetattr: Inappropriate ioctl for device
>Fix:

--- /usr/src/usr.bin/login/login.c	Thu Mar 14 18:16:16 2002
+++ login.c	Mon Dec 16 22:45:05 2002
@@ -632,6 +633,17 @@
 		} else if (pid) {
 			/* parent - wait for child to finish, then cleanup
 			   session */
+			fpurge(stdin);
+			close(STDIN_FILENO);
+			fpurge(stdout);
+			close(STDOUT_FILENO);
+			fpurge(stderr);
+			close(STDERR_FILENO);
+			(void)signal(SIGHUP, SIG_IGN);
+			(void)signal(SIGALRM, SIG_IGN);
+			(void)signal(SIGQUIT, SIG_IGN);
+			(void)signal(SIGINT, SIG_IGN);
+
 			wait(NULL);
 			PAM_END;
 			exit(0);

	As I understand, this is NOT better fix for signal handling problem.
But it works for me and leaves for kill(0, SIG...) from pppd much smaller
window for signal handling races in the current process group.

>Release-Note:
>Audit-Trail:
>Unformatted:
 Environment:	System: FreeBSD core.zp.ua 4.7-STABLE FreeBSD 4.7-STABLE #0:
 		Mon Oct 28 21:50:40 EET 2002 root@core.zp.ua:/usr/src/sys/compile/core i386
