ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libev/ev.c
(Generate patch)

Comparing libev/ev.c (file contents):
Revision 1.45 by root, Sat Nov 3 09:19:58 2007 UTC vs.
Revision 1.47 by root, Sat Nov 3 11:44:44 2007 UTC

476#ifndef WCONTINUED 476#ifndef WCONTINUED
477# define WCONTINUED 0 477# define WCONTINUED 0
478#endif 478#endif
479 479
480static void 480static void
481child_reap (struct ev_signal *sw, int chain, int pid, int status)
482{
483 struct ev_child *w;
484
485 for (w = childs [chain & (PID_HASHSIZE - 1)]; w; w = w->next)
486 if (w->pid == pid || !w->pid)
487 {
488 w->priority = sw->priority; /* need to do it *now* */
489 w->rpid = pid;
490 w->rstatus = status;
491 printf ("rpid %p %d %d\n", w, pid, w->pid);//D
492 event ((W)w, EV_CHILD);
493 }
494}
495
496static void
481childcb (struct ev_signal *sw, int revents) 497childcb (struct ev_signal *sw, int revents)
482{ 498{
483 struct ev_child *w;
484 int pid, status; 499 int pid, status;
485 500
501 printf ("chld %x\n", revents);//D
486 while ((pid = waitpid (-1, &status, WNOHANG | WUNTRACED | WCONTINUED)) != -1) 502 if (0 < (pid = waitpid (-1, &status, WNOHANG | WUNTRACED | WCONTINUED)))
487 for (w = childs [pid & (PID_HASHSIZE - 1)]; w; w = w->next) 503 {
488 if (w->pid == pid || !w->pid) 504 /* make sure we are called again until all childs have been reaped */
489 {
490 w->status = status;
491 event ((W)w, EV_CHILD); 505 event ((W)sw, EV_SIGNAL);
492 } 506
507 child_reap (sw, pid, pid, status);
508 child_reap (sw, 0, pid, status); /* this might trigger a watcher twice, but event catches that */
509 }
493} 510}
494 511
495#endif 512#endif
496 513
497/*****************************************************************************/ 514/*****************************************************************************/
570#endif 587#endif
571 588
572 if (ev_method) 589 if (ev_method)
573 { 590 {
574 ev_watcher_init (&sigev, sigcb); 591 ev_watcher_init (&sigev, sigcb);
592 ev_set_priority (&sigev, EV_MAXPRI);
575 siginit (); 593 siginit ();
576 594
577#ifndef WIN32 595#ifndef WIN32
578 ev_signal_init (&childev, childcb, SIGCHLD); 596 ev_signal_init (&childev, childcb, SIGCHLD);
597 ev_set_priority (&childev, EV_MAXPRI);
579 ev_signal_start (&childev); 598 ev_signal_start (&childev);
580#endif 599#endif
581 } 600 }
582 } 601 }
583 602
1007 } 1026 }
1008 1027
1009 ev_stop ((W)w); 1028 ev_stop ((W)w);
1010} 1029}
1011 1030
1031#ifndef SA_RESTART
1032# define SA_RESTART 0
1033#endif
1034
1012void 1035void
1013ev_signal_start (struct ev_signal *w) 1036ev_signal_start (struct ev_signal *w)
1014{ 1037{
1015 if (ev_is_active (w)) 1038 if (ev_is_active (w))
1016 return; 1039 return;
1024 if (!w->next) 1047 if (!w->next)
1025 { 1048 {
1026 struct sigaction sa; 1049 struct sigaction sa;
1027 sa.sa_handler = sighandler; 1050 sa.sa_handler = sighandler;
1028 sigfillset (&sa.sa_mask); 1051 sigfillset (&sa.sa_mask);
1029 sa.sa_flags = 0; 1052 sa.sa_flags = SA_RESTART; /* if restarting works we save one iteration */
1030 sigaction (w->signum, &sa, 0); 1053 sigaction (w->signum, &sa, 0);
1031 } 1054 }
1032} 1055}
1033 1056
1034void 1057void

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines