I often have orphaned FDs in threaded programs...

Juli Mallett <[email protected]> Thu, 17 Oct 2002 03:41:28 -0700
Newsgroups gmane.os.freebsd.devel.audit
Message-ID <[email protected]>
I have a program which shares a lot of (orphaned) FDs between threads,
and requesting a dump (SIGINFO) results in a core, because the FD owner
si NULL.  Here's a diff from my local tree, for review:

%%%
Index: uthread_info.c
===================================================================
RCS file: /home/ncvs/src/lib/libc_r/uthread/uthread_info.c,v
retrieving revision 1.21
diff -d -u -r1.21 uthread_info.c
--- uthread_info.c	13 Oct 2002 11:23:31 -0000	1.21
+++ uthread_info.c	17 Oct 2002 10:38:49 -0000
@@ -252,10 +252,16 @@
 			    pthread->data.fd.fname,
 			    pthread->data.fd.branch);
 			__sys_write(fd, s, strlen(s));
-			snprintf(s, sizeof(s), "owner %pr/%pw\n",
-			    _thread_fd_table[pthread->data.fd.fd]->r_owner,
-			    _thread_fd_table[pthread->data.fd.fd]->w_owner);
-			__sys_write(fd, s, strlen(s));
+			/*
+			 * XXX _thread_fd_table[pthread->data.fd.fd] often comes
+			 *     up as NULL for me, bandaid it.  Is this right?
+			 */
+			if (_thread_fd_table[pthread->data.fd.fd] != NULL) {
+				snprintf(s, sizeof(s), "owner %pr/%pw\n",
+				    _thread_fd_table[pthread->data.fd.fd]->r_owner,
+				    _thread_fd_table[pthread->data.fd.fd]->w_owner);
+				__sys_write(fd, s, strlen(s));
+			}
 			break;
 		case PS_SIGWAIT:
 			snprintf(s, sizeof(s), "sigmask (hi)");
%%%

I think it's right to just print no owner, or possibly a no owner message,
in these cases.  Comments?
-- 
Juli Mallett <[email protected]>       | FreeBSD: The Power To Serve
Will break world for fulltime employment. | finger [email protected]
http://people.FreeBSD.org/~jmallett/      | Support my FreeBSD hacking!

To Unsubscribe: send mail to [email protected]
with "unsubscribe freebsd-audit" in the body of the message