[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#212697: static linking with lpthread and system call causes crash



Package: libc6-dev
Version: 2.2.5-11.2

Description: a system function call within a pthread (when statically linked) ends the program but leaves the processus zombified
The same problem does not occur on unstable systems (with libc6 2.3.2-4)

Here is a test program that demonstrates the problem, it consists of a main function which calls ThreadFunction which itself calls system(const char*).

/* test.c */
#include <stdlib.h>
#include <pthread.h>
#include <stdio.h>

void* ThreadFunction(void* arg)
{
   printf("Thread Started\n");

   system("ls -l");

   printf("Thread Stopping\n");

   return NULL;
}

int main(int argc, char** argv)
{
   pthread_t thread;
   void* result;
pthread_create(&thread, NULL, ThreadFunction, NULL);

   pthread_join(thread, &result);

   return 0;
}
/* END test.c

example of dynamic linking:
# gcc test.c -lpthread -o test
# ldd test
   libpthread.so.0 => /lib/lipthread.so (0x40017000)
   libc.so.6 => /lib/libc.so.6 (0x4002b000)
   /lib/ld-linux.so.2 => (0x40000000)
# ./test
   Thread Started
   ... (output of ls -l)
   Thread Stopping
// CORRECT BEHAVIOUR

example of static linkinkg:
# gcc test.c -static -lpthread -o test
# ldd test
   not a dynamic executable
# ./test
   Thread Started
# ps aux | grep test
   root   20027   0.0   0.1   2548   160 pts/1   S   13:26   ./test
   root   20028   0.0   0.1   2548   160 pts/1   S   13:26   ./test

// after launching ./test, Thread Started is printed out, but the command prompt shows up immediately and ps sees the processus still running.

if i do this on a machine running 2.3.2-4 or gentoo using 2.3.2 as well, the problem does not occur...
i used diiferent compilers with no noticeable change:
# dpkg -l gcc*
   ii gcc-2.95   2.95.4-7
   ii gcc-3.0   3.0.4-7

is this a bug?
is this backportable from the 2.3 series?

oh by the way, uname -a shows 2.4.18-586tsc but fails as well on 2.4.21 (homemade) and 2.4.22 (gentoo).

Severity: unknown (annoying to me)


have a nice day,

Gabriel Biberian




Reply to: