--- eval.c.orig 2009-12-21 08:11:42.000000000 +0000 +++ eval.c @@ -10879,7 +10879,7 @@ rb_thread_remove(th) #if defined(_THREAD_SAFE) || defined(HAVE_SETITIMER) /* if this is the last ruby thread, stop timer signals */ if (th->next == th->prev && th->next == main_thread) { - rb_thread_stop_timer(); + rb_thread_stop_timer(0); } #endif } @@ -12329,6 +12329,18 @@ thread_timer(dummy) return NULL; } +/* fix inconsistent data */ +static void +rb_thread_stop_timer_atfork(void) +{ + if (!thread_init) return; +#if !defined(__NetBSD__) + (void)pthread_cond_init(&time_thread.cond, NULL); + (void)pthread_mutex_init(&time_thread.lock, NULL); +#endif + thread_init = 0; +} + void rb_thread_start_timer() { @@ -12343,21 +12355,27 @@ rb_thread_start_timer() safe_mutex_lock(&time_thread.lock); if (pthread_create(&time_thread.thread, 0, thread_timer, args) == 0) { thread_init = 1; - pthread_atfork(0, 0, rb_thread_stop_timer); + pthread_atfork(0, 0, rb_thread_stop_timer_atfork); pthread_cond_wait(&start, &time_thread.lock); } pthread_cleanup_pop(1); } void -rb_thread_stop_timer() +rb_thread_stop_timer(int doexec) { if (!thread_init) return; +#if defined(__NetBSD__) + if (doexec) { +#endif safe_mutex_lock(&time_thread.lock); pthread_cond_signal(&time_thread.cond); thread_init = 0; pthread_cleanup_pop(1); pthread_join(time_thread.thread, NULL); +#if defined(__NetBSD__) + } +#endif } #elif defined(HAVE_SETITIMER) static void @@ -12389,7 +12407,7 @@ rb_thread_start_timer() } void -rb_thread_stop_timer() +rb_thread_stop_timer(int dummy) { struct itimerval tval; @@ -12406,7 +12424,7 @@ int rb_thread_tick = THREAD_TICK; #if defined(HAVE_SETITIMER) || defined(_THREAD_SAFE) #define START_TIMER() (thread_init ? (void)0 : rb_thread_start_timer()) -#define STOP_TIMER() (rb_thread_stop_timer()) +#define STOP_TIMER() (rb_thread_stop_timer(0)) #else #define START_TIMER() ((void)0) #define STOP_TIMER() ((void)0) --- process.c.orig 2008-06-29 09:34:43.000000000 +0000 +++ process.c @@ -115,6 +115,7 @@ static VALUE S_Tms; #define preserving_errno(stmts) \ do {int saved_errno = errno; stmts; errno = saved_errno;} while (0) +static int doing_rb_f_exec = 0; /* * call-seq: @@ -920,7 +921,7 @@ char *strtok(); #endif #ifdef HAVE_SETITIMER -#define before_exec() rb_thread_stop_timer() +#define before_exec() rb_thread_stop_timer(doing_rb_f_exec) #define after_exec() rb_thread_start_timer() #else #define before_exec() @@ -1289,7 +1290,13 @@ rb_f_exec(argc, argv) SafeStringValue(prog); } proc_prepare_args(&earg, argc, argv, prog); +#if defined(__NetBSD__) + doing_rb_f_exec = 1; +#endif proc_exec_args((VALUE)&earg); +#if defined(__NetBSD__) + doing_rb_f_exec = 0; +#endif rb_sys_fail(RSTRING(argv[0])->ptr); return Qnil; /* dummy */ } --- intern.h.orig 2009-01-22 06:22:00.000000000 +0000 +++ intern.h @@ -208,7 +208,7 @@ int ruby_cleanup _((int)); int ruby_exec _((void)); void rb_gc_mark_threads _((void)); void rb_thread_start_timer _((void)); -void rb_thread_stop_timer _((void)); +void rb_thread_stop_timer _((int)); void rb_thread_schedule _((void)); void rb_thread_wait_fd _((int)); int rb_thread_fd_writable _((int));