From owner-freebsd-bugs@FreeBSD.ORG Thu Apr 10 01:50:08 2003 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id BF5C837B401 for ; Thu, 10 Apr 2003 01:50:08 -0700 (PDT) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 0390B43F3F for ; Thu, 10 Apr 2003 01:50:08 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.12.9/8.12.9) with ESMTP id h3A8o7Up084858 for ; Thu, 10 Apr 2003 01:50:07 -0700 (PDT) (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.9/8.12.9/Submit) id h3A8o7jS084857; Thu, 10 Apr 2003 01:50:07 -0700 (PDT) Resent-Date: Thu, 10 Apr 2003 01:50:07 -0700 (PDT) Resent-Message-Id: <200304100850.h3A8o7jS084857@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Georg Graf Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 9B89837B401 for ; Thu, 10 Apr 2003 01:48:20 -0700 (PDT) Received: from schurli.wu-wien.ac.at (schurli.wu-wien.ac.at [137.208.16.32]) by mx1.FreeBSD.org (Postfix) with SMTP id 7CE1243F93 for ; Thu, 10 Apr 2003 01:48:19 -0700 (PDT) (envelope-from graf@schurli.wu-wien.ac.at) Received: (qmail 14875 invoked by uid 1000); 10 Apr 2003 08:48:17 -0000 Message-Id: <20030410084817.14874.qmail@schurli.wu-wien.ac.at> Date: 10 Apr 2003 08:48:17 -0000 From: Georg Graf To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 cc: georg@graf.priv.at cc: gonter@buddy.wu-wien.ac.at Subject: bin/50770: popen in libc_r not threadsafe X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: Georg Graf List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 10 Apr 2003 08:50:09 -0000 >Number: 50770 >Category: bin >Synopsis: popen in libc_r not threadsafe >Confidential: no >Severity: serious >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Thu Apr 10 01:50:07 PDT 2003 >Closed-Date: >Last-Modified: >Originator: Georg Graf >Release: FreeBSD 4.7-RELEASE-p7 i386 >Organization: WU WIEN >Environment: System: FreeBSD schurli.wu-wien.ac.at 4.7-RELEASE-p7 FreeBSD 4.7-RELEASE-p7 #0: Tue Mar 4 07:47:12 CET 2003 root@mingus.wu-wien.ac.at:/usr/obj/usr/src/sys/GENERIC i386 System: FreeBSD milo.wu-wien.ac.at 4.8-RELEASE FreeBSD 4.8-RELEASE #0: Wed Apr 2 18:22:23 CEST 2003 root@milo.wu-wien.ac.at:/usr/obj/usr/src/sys/GENERIC i386 System: FreeBSD philip.wu-wien.ac.at 5.0-RELEASE FreeBSD 5.0-RELEASE #0: Wed Apr 9 14:30:35 CEST 2003 root@philip.wu-wien.ac.at:/usr/obj/usr/src/sys/PHILIP i386 >Description: Using popen(3) from within a thread causes weird behavior after running the program for a while. I assume that the pipe creation code in popen and the pipe deletion code in pclose should be made reentrant in libc_r. Some of the created childs stay hanging in a fcntl loop before doing the exec, as shown in http://schurli.wu-wien.ac.at/pthread/pr. And in the parent process the pclose(3) call in some threads constantly fails with EAGAIN. Note also that this program may crash a 4.7-RELEASE-p8 (not exactly sure about the patchlevel) SMP machine. Should I file an extra PR for that? >How-To-Repeat: Basically: Call popen() and pclose() in a program compiled with -pthread, and do not protect these calls with a mutex. I have haunted this bug on http://schurli.wu-wien.ac.at/pthread.tgz "co -r1.32 thread.c" gives a version where you can see the described behavior. >Fix: The workaround: protect the popen and pclose calls with a mutex, so that the operations on filedescriptors in the global scope are atomic. (As done in -r1.33 of my program). IMO for a fix this should be moved into the library. Please contact me if you want me to propose a fix for that. Thank you! >Release-Note: >Audit-Trail: >Unformatted: