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.48 by root, Sat Nov 3 12:19:31 2007 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines