From eischen@vigrid.com Wed Jul 28 10:02:06 1999
Return-Path: <eischen@vigrid.com>
Received: from pcnet1.pcnet.com (pcnet1.pcnet.com [204.213.232.3])
	by hub.freebsd.org (Postfix) with ESMTP id 4CF5414EF1
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 28 Jul 1999 10:01:56 -0700 (PDT)
	(envelope-from eischen@vigrid.com)
Received: (from eischen@localhost)
	by pcnet1.pcnet.com (8.8.7/PCNet) id MAA06499;
	Wed, 28 Jul 1999 12:59:28 -0400 (EDT)
Message-Id: <199907281659.MAA06499@pcnet1.pcnet.com>
Date: Wed, 28 Jul 1999 12:59:28 -0400 (EDT)
From: Daniel Eischen <eischen@vigrid.com>
To: FreeBSD-gnats-submit@freebsd.org, mi@aldan.algebra.com
Cc: eischen@vigrid.com, jb@cimlogic.com.au, lawlopez@cisco.com,
	msestina@cisco.com, sjlee@cisco.com
Subject: Re: resend: uthread_init.c PANICs in case of (legally) close stdin

>Number:         12854
>Category:       bin
>Synopsis:       Re: resend: uthread_init.c PANICs in case of (legally) close stdin
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    gnats-admin
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Jul 28 10:10:00 PDT 1999
>Closed-Date:    Thu Jul 29 12:57:42 PDT 1999
>Last-Modified:  Wed Oct 26 06:08:36 GMT 2005
>Originator:     
>Release:        
>Organization:
>Environment:
>Description:
 Wow, this CC: list is growing!
 
 Can you please try this more complete patch (made against -stable)?
 I believe it better handles initialization of the fd tables for fds
 < 3.
 
 Index: uthread_fd.c
 ===================================================================
 RCS file: /A/cvs/src/lib/libc_r/uthread/uthread_fd.c,v
 retrieving revision 1.9.2.2
 diff -u -r1.9.2.2 uthread_fd.c
 --- uthread_fd.c	1999/07/23 13:00:27	1.9.2.2
 +++ uthread_fd.c	1999/07/28 16:31:33
 @@ -94,13 +94,13 @@
  		TAILQ_INIT(&entry->w_queue);
  
  		/* Get the flags for the file: */
 -		if (fd >= 3 && (entry->flags =
 -		    _thread_sys_fcntl(fd, F_GETFL, 0)) == -1) {
 +		if (((fd >= 3) || (_pthread_stdio_flags[fd] == -1)) &&
 +		    (entry->flags = _thread_sys_fcntl(fd, F_GETFL, 0)) == -1) {
  			ret = -1;
 -		    }
 +		}
  		else {
  			/* Check if a stdio descriptor: */
 -			if (fd < 3)
 +			if ((fd < 3) && (_pthread_stdio_flags[fd] != -1))
  				/*
  				 * Use the stdio flags read by
  				 * _pthread_init() to avoid
 Index: uthread_init.c
 ===================================================================
 RCS file: /A/cvs/src/lib/libc_r/uthread/uthread_init.c,v
 retrieving revision 1.9.2.3
 diff -u -r1.9.2.3 uthread_init.c
 --- uthread_init.c	1999/07/23 13:00:29	1.9.2.3
 +++ uthread_init.c	1999/07/28 16:43:27
 @@ -121,8 +121,9 @@
  
  	/* Get the standard I/O flags before messing with them : */
  	for (i = 0; i < 3; i++)
 -		if ((_pthread_stdio_flags[i] =
 -		    _thread_sys_fcntl(i,F_GETFL, NULL)) == -1)
 +		if (((_pthread_stdio_flags[i] =
 +		    _thread_sys_fcntl(i,F_GETFL, NULL)) == -1) &&
 +		    (errno != EBADF))
  			PANIC("Cannot get stdio flags");
  
  	/*
 @@ -292,12 +293,18 @@
  			}
  
  			/* Initialize stdio file descriptor table entries: */
 -			if ((_thread_fd_table_init(0) != 0) ||
 -			    (_thread_fd_table_init(1) != 0) ||
 -			    (_thread_fd_table_init(2) != 0)) {
 -				PANIC("Cannot initialize stdio file descriptor "
 -				    "table entries");
 -			}
 +			if ((_thread_fd_table_init(0) != 0) &&
 +			    (errno != EBADF))
 +				PANIC("Cannot initialize stdio file "
 +				    "descriptor table entries");
 +			else if ((_thread_fd_table_init(1) != 0) &&
 +			    (errno != EBADF))
 +				PANIC("Cannot initialize stdout file "
 +				    "descriptor table entries");
 +			else if ((_thread_fd_table_init(2) != 0) &&
 +			    (errno != EBADF))
 +				PANIC("Cannot initialize stderr file "
 +				    "descriptor table entries");
  		}
  	}
  
 
 Dan Eischen
 eischen@vigrid.com
 
>How-To-Repeat:
>Fix:
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: sheldonh 
State-Changed-When: Thu Jul 29 12:57:42 PDT 1999 
State-Changed-Why:  
Mis-filed en route to PR 12853. 
>Unformatted:
