uClibc-0.9.29 daemon and pthread problem

Kasia Binam kasia.binam at texmemsys.com
Fri Jun 1 14:53:01 UTC 2007


Hi,

After daemon()-izing a process, when I use pthread_create to start a new 
thread, the main thread
never wakes up.  For example:
 
void *thread(void *arg)
{
    printf("hello\n");
    return 0;
}
int main(int argc, char **argv)
{
    pthread_t test;
   
    daemon(0,1);
    pthread_create(&test, NULL, thread, NULL);

    sleep(1); // give the thread a little time to run
    printf("exit\n");
    return 0;
}

And here's an strace snippet of the problem:

15388 fork()                            = 15389
15388 exit(0)                           = ?
15389 setsid()                          = 15389
15389 fork()                            = 15390
15389 exit(0)                           = ?
15390 chdir("/")                        = 0
15390 brk(0x10014000)                   = 0x10014000
15390 pipe([3, 4])                      = 0
15390 clone(child_stack=0x10013120, 
flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND) = 15391
15390 write(4, 
"\0\0\0\0\0\0\0\5\0\0\0\0\0\0\0\0\20\0\4H\0\0\0\0\0\0\0"..., 148) = 148
15390 rt_sigprocmask(SIG_SETMASK, NULL, [RTMIN], 8) = 0
15390 write(4, "0\3P 
\0\0\0\0\0\0\0\0\20\0\7\310\0\0\0\0\200\0\0\0\0\0"..., 148) = 148
15390 rt_sigprocmask(SIG_SETMASK, NULL, [RTMIN], 8) = 0
15390 rt_sigsuspend([] <unfinished ...>
15391 rt_sigprocmask(SIG_SETMASK, ~[TRAP RT_1], NULL, 8) = 0
15391 read(3, 
"\0\0\0\0\0\0\0\5\0\0\0\0\0\0\0\0\20\0\4H\0\0\0\0\0\0\0"..., 148) = 148
15391 poll([{fd=3, events=POLLIN, revents=POLLIN}], 1, 2000) = 1
15391 getppid()                         = 15390
15391 read(3, "0\3P 
\0\0\0\0\0\0\0\0\20\0\7\310\0\0\0\0\200\0\0\0\0\0"..., 148) = 148
15391 mmap(0x7f3fc000, 16384, PROT_READ|PROT_WRITE|PROT_EXEC, 
MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS|MAP_GROWSDOWN, -1, 0) = 0x7f3fc000
15391 clone(child_stack=0x7f3ffe10, 
flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|SIGRT_1) = 15392
15391 kill(15388, SIGRTMIN)             = -1 ESRCH (No such process)
15391 poll( <unfinished ...>

So the pthread manager is trying to wake up the original main thread 
before it was daemonized.  If I replace daemon() with a duplicate of the 
daemon() code in my example program, there is no problem.  It seems like 
there's something funny with the alias or build magic so that I'm using 
two different forks?

This was built from 0.9.29 cross-compiled for powerpc, gcc 4.1.2.  Let 
me know if you need more info.  Thanks in advance for your help!  :)

Kasia



More information about the uClibc mailing list