On Thu, 2005-03-31 at 09:31 -0500, Jeff Bailey wrote: > Miguel, > > I was looking through the sysklogd patch that you provided, and looked > through the glibc code. I don't see any __libc_lock magic happening.
ctime() -> localtime() -> __tz_convert() -> __libc_lock_lock() > Since ctime isn't reentrant, no effort is made to protect the coder > against threaded programming. I also checked the 'time' function in > case you were worried about that. > > Which glibc function were you worried about? > > I can see this code being included for completeness so that an entry > isn't lost, but I don't think this is what's causing your breakage. It is, I tested it :) Compile the attached C program, run with sarge glibc on a 2.6 kernel. It's the most clear if you run it like this: $ strace -e trace=\!time ./a.out Lockup within a fraction of a second. Mike.
#include <sys/time.h> #include <time.h> #include <signal.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> volatile char *r; void handler(int sig) { time_t t; time(&t); r = ctime(&t); } int main() { struct itimerval it; struct sigaction sa; time_t t; memset(&sa, 0, sizeof(sa)); sa.sa_handler = handler; sigaction(SIGALRM, &sa, NULL); it.it_value.tv_sec = 0; it.it_value.tv_usec = 1000; it.it_interval.tv_sec = 0; it.it_interval.tv_usec = 1000; setitimer(ITIMER_REAL, &it, NULL); while(1) { time(&t); r = ctime(&t); } return 0; }