Date: Fri, 13 Jul 2001 15:57:04 +0200 (CEST) From: sdalu@loria.fr To: FreeBSD-gnats-submit@freebsd.org Subject: kern/28947: dup2 closing pthread file descriptor Message-ID: <200107131357.f6DDv4d71477@hyperion.loria.fr>
next in thread | raw e-mail | index | archive | help
>Number: 28947 >Category: kern >Synopsis: dup2 closing pthread file descriptor >Confidential: no >Severity: non-critical >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Fri Jul 13 07:00:01 PDT 2001 >Closed-Date: >Last-Modified: >Originator: Stephane D'Alu >Release: FreeBSD 4.2-RELEASE i386 >Organization: >Environment: >Description: when using pthread 2 file descriptors are used for pipes (see lsof output), these file descriptors can't be closed by close(), but dup2() manage to duplicate other fd at these positions (fcntl/F_DUPFD cannot) the real problem occurs when doing an exec, when presumably the pthread is doing some cleanup and closes its files descriptor, unfortunatelly these descriptors are not its own anymore but the copy done but dup2. would have expected dup2() to fail (the problem is perhaps more with the pthread librairy than the kernel) >How-To-Repeat: -- a ------------------------ #include <pthread.h> int main() { if (close(3) < 0) perror("close"); if (dup2(0, 3) < 0) perror("dup2"); } ----------------------------- gcc -o a a.c -pthread a 71332 sdalu 0u VCHR 5,14 0t4766 8311 /dev/ttype a 71332 sdalu 1u VCHR 5,14 0t4766 8311 /dev/ttype a 71332 sdalu 2u VCHR 5,14 0t4766 8311 /dev/ttype a 71332 sdalu 3u PIPE 0xd734f260 16384 ->0xd734f300 a 71332 sdalu 4u PIPE 0xd734f300 16384 ->0xd734f260 ./a close: Bad file descriptor >Fix: >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?200107131357.f6DDv4d71477>