Calling endhostent(), when such a call is not needed, ends up closing fd 0 by accident. main() { endhostent(); } Breakpoint 2, 0x281a8dc0 in close () from /lib/libc.so.7 (gdb) where #0 0x281a8dc0 in close () from /lib/libc.so.7 #1 0x28152518 in __res_nclose () from /lib/libc.so.7 #2 0x2817c585 in __dns_getanswer () from /lib/libc.so.7 #3 0x080485b3 in main () at endhostent_bug.c:4 hopo $ truss ./a.out ... close(0) = 0 (0x0) ... process exit, rval = 0 Except the usual runtime chores, close(0) is the only visible systemcall.
I think res_nclose() in lib/libc/resolv/res_init.c should skip its close logic if ((statp->options & RES_INIT) == 0).
I don't think it's a bug. Calling endhostent() alone is rather caller's bug.
For bugs matching the following conditions: - Status == In Progress - Assignee == "bugs@FreeBSD.org" - Last Modified Year <= 2017 Do - Set Status to "Open"