- Subject: libc/1273: system() blocks forever when called from a threaded program
- From: jbuhler@cs.washington.edu
- Date: Fri Aug 27 18:39:39 1999
Topics:
libc/1273: system() blocks forever when called from a threaded program
----------------------------------------------------------------------
Date: 27 Aug 1999 07:51:38 -0000
From: jbuhler@cs.washington.edu
To: bugs@gnu.org
Subject: libc/1273: system() blocks forever when called from a threaded program
Message-Id: <19990827075138.28172.qmail@jbuhler.dsl.speakeasy.net>
>Number: 1273
>Category: libc
>Synopsis: calling system() from a threaded program hangs until ^C pressed
>Confidential: no
>Severity: serious
>Priority: high
>Responsible: libc-gnats
>State: open
>Class: sw-bug
>Submitter-Id: unknown
>Arrival-Date: Fri Aug 27 04:00:02 EDT 1999
>Last-Modified:
>Originator: Jeremy Buhler
>Organization:
University of Washington
>
>Release: libc-2.1.2 (pre3)
>Environment:
Intel Pentium III
Linux 2.2.12
glibc 2.1.2pre3 w/matching linuxthreads
Shell used for system() is /bin/bash, version 2.03.0(1) w/IFS fix.
Host type: i686-pc-linux-gnu
System: Linux boadicea 2.2.12 #2 Wed Aug 25 20:23:58 PDT 1999 i686 unknown
Architecture: i686
Addons: crypt linuxthreads
Build CFLAGS: -O2 -march=pentiumpro
Build CC: gcc
Compiler version: 2.95.1 19990816 (release)
Kernel headers: 2.2.12
Symbol versioning: yes
Build static: yes
Build shared: yes
Build pic-default: no
Build profile: no
Build omitfp: no
Build bounded: no
Build static-nss: no
Stdio: libio
>Description:
After installing glibc 2.1.2pre3, I found that the xmms MP3 player
(v0.9.1) would reliably hang on startup. This behavior was not
observed with pre2. xmms is a threaded program, but the hang occurs
in the main thread (ie not one created by pthread_create()) when the
program calls system() to untar its skin file. Pressing Ctrl-C aborts
the hang, but the command passed to system() is never executed, and
system() itself returns exit status 2.
Perhaps this is a bad interaction between the signal usage by system()
and the signal usage by pthreads, which changed between 2.1.2pre2 and
pre3.
>How-To-Repeat:
The following code reproduces the observed bad behavior. Please
excuse poor usage of pthreads on my part; I've never actually hacked
them prior to this bug report.
###CUT##HERE###
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
void *athread(void *arg)
{
while (1) {} /* loop forever */
pthread_exit((void *) 0);
}
int main(void)
{
char *cmd = "echo 'Hello, world!' > /tmp/foo";
pthread_t tid;
pthread_create(&tid, NULL, athread, NULL);
printf("%d\n", system(cmd));
return 0;
}
###CUT##HERE###
Compile this code normally, e.g. 'gcc tryme.c -lpthread', and run the
resulting binary. I used gcc 2.95.1 for the compile.
I expect the program to execute the system() command, print '0' for success,
and exit. In fact, it hangs in the call to system until Ctrl-C is pressed,
then prints '2' from system() and exits without having executed the
command.
If I remove the call to pthread_create(), the main thread and the call
to system() behave as I expect, i.e. the program completes the system()
call without hanging.
I don't have an older glibc 2.1 installation handy, but the program
compiles and behaves correctly on a standard RedHat 5.2 system, again
using gcc 2.95.1.
>Fix:
Unknown, but probably involves some tweak to system() and/or the
signal-related changes in libpthread introduced in 2.1.2pre3.
>Audit-Trail:
>Unformatted:
------------------------------
End of forwardHeFRNY Digest
***************************