Date: Wed, 28 Jul 1999 12:29:15 -0400 (EDT) From: Mikhail Teterin <mi@misha.cisco.com> To: FreeBSD-gnats-submit@freebsd.org Cc: eischen@VIGRID.COM Subject: bin/12853: resend: uthread_init.c PANICs in case of (legally) close stdin Message-ID: <199907281629.MAA09267@misha.cisco.com>
next in thread | raw e-mail | index | archive | help
>Number: 12853 >Category: bin >Synopsis: uthread_init.c PANICs in case of (legally) close stdin >Confidential: no >Severity: serious >Priority: high >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Wed Jul 28 09:40:01 PDT 1999 >Closed-Date: >Last-Modified: >Originator: Mikhail Teterin >Release: FreeBSD 3.2-STABLE i386 >Organization: Virtual Estates, Inc. >Environment: >Description: It appears, a thread-using (linked with -lc_r) application must have a valid stdin at startup (and stdout, and stderr). Otherwise, it will PANIC("Cannot get stdio flags") and may then seg-fault (because of the closed stderr too). The discussion of the matter with John Birrell and Dan Eischen yielded a patch below, which fixed our problem. >How-To-Repeat: We are replacing the HylaFAX's ${PREFIX}/sbin/faxsend with our own thread-using application. The app works fine when started from command line, but dies a horrible death when started normally -- by HylaFAX's ${PREFIX}/sbin/faxq. I managed to produce the ktrace (had to make /usr/bin/ktrace suid), which helped me identify the problem and, most importantly, helped the "thread people" come up with the fix: 1157 ktrace RET ktrace 0 1157 ktrace CALL execve(0xbfbfdc23,0xbfbfdaec,0xbfbfdb00) 1157 ktrace NAMI "/usr/local/sbin/faxsend.bin" 1157 faxsend.bin RET execve 0 1157 faxsend.bin CALL getpid 1157 faxsend.bin RET getpid 1157/0x485 1157 faxsend.bin CALL fcntl(0,0x3,0) 1157 faxsend.bin RET fcntl -1 errno 9 Bad file descriptor 1157 faxsend.bin CALL write(0x2,0xbfbfd9ac,0x6e) 1157 faxsend.bin GIO fd 2 wrote 110 bytes "Fatal error 'Cannot get stdio flags' at line ? in file /usr/src/lib/libc_r/ut\ hread/uthread_init.c (errno = ?) " 1157 faxsend.bin RET write 110/0x6e 1157 faxsend.bin CALL setitimer(0x2,0xbfbfd968,0) 1157 faxsend.bin RET setitimer 0 1157 faxsend.bin CALL close(0xffffffff) 1157 faxsend.bin RET close -1 errno 9 Bad file descriptor 1157 faxsend.bin CALL close(0xffffffff) 1157 faxsend.bin RET close -1 errno 9 Bad file descriptor 1157 faxsend.bin PSIG SIGSEGV SIG_DFL >Fix: This fix does NOT fix the seg-fault itself, but only prevents the panic from happening in this legal case. I hope, this gets commited before the seg-fault is hunted down, as it is a different problem. --- uthread_init.c.orig Wed Jul 28 10:48:25 1999 +++ uthread_init.c Wed Jul 28 10:33:50 1999 @@ -118,5 +118,13 @@ if ((_pthread_stdio_flags[i] = - _thread_sys_fcntl(i,F_GETFL, NULL)) == -1) - PANIC("Cannot get stdio flags"); - + _thread_sys_fcntl(i,F_GETFL, NULL)) == -1 && errno != EBADF) { + const char *panics[] = { + "Cannot initialize " "stdin" " file descriptor " + "table entry", + "Cannot initialize " "stdout" " file descriptor " + "table entry", + "Cannot initialize " "stderr" " file descriptor " + "table entry" + }; + PANIC(panics[i]); + } /* >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199907281629.MAA09267>