… | |
… | |
476 | #ifndef WCONTINUED |
476 | #ifndef WCONTINUED |
477 | # define WCONTINUED 0 |
477 | # define WCONTINUED 0 |
478 | #endif |
478 | #endif |
479 | |
479 | |
480 | static void |
480 | static void |
|
|
481 | child_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 | |
|
|
496 | static void |
481 | childcb (struct ev_signal *sw, int revents) |
497 | childcb (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->rpid = pid; |
|
|
491 | w->rstatus = status; |
|
|
492 | event ((W)w, EV_CHILD); |
505 | event ((W)sw, EV_SIGNAL); |
493 | } |
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 | } |
494 | } |
510 | } |
495 | |
511 | |
496 | #endif |
512 | #endif |
497 | |
513 | |
498 | /*****************************************************************************/ |
514 | /*****************************************************************************/ |
… | |
… | |
571 | #endif |
587 | #endif |
572 | |
588 | |
573 | if (ev_method) |
589 | if (ev_method) |
574 | { |
590 | { |
575 | ev_watcher_init (&sigev, sigcb); |
591 | ev_watcher_init (&sigev, sigcb); |
|
|
592 | ev_set_priority (&sigev, EV_MAXPRI); |
576 | siginit (); |
593 | siginit (); |
577 | |
594 | |
578 | #ifndef WIN32 |
595 | #ifndef WIN32 |
579 | ev_signal_init (&childev, childcb, SIGCHLD); |
596 | ev_signal_init (&childev, childcb, SIGCHLD); |
|
|
597 | ev_set_priority (&childev, EV_MAXPRI); |
580 | ev_signal_start (&childev); |
598 | ev_signal_start (&childev); |
581 | #endif |
599 | #endif |
582 | } |
600 | } |
583 | } |
601 | } |
584 | |
602 | |
… | |
… | |
1008 | } |
1026 | } |
1009 | |
1027 | |
1010 | ev_stop ((W)w); |
1028 | ev_stop ((W)w); |
1011 | } |
1029 | } |
1012 | |
1030 | |
|
|
1031 | #ifndef SA_RESTART |
|
|
1032 | # define SA_RESTART 0 |
|
|
1033 | #endif |
|
|
1034 | |
1013 | void |
1035 | void |
1014 | ev_signal_start (struct ev_signal *w) |
1036 | ev_signal_start (struct ev_signal *w) |
1015 | { |
1037 | { |
1016 | if (ev_is_active (w)) |
1038 | if (ev_is_active (w)) |
1017 | return; |
1039 | return; |
… | |
… | |
1025 | if (!w->next) |
1047 | if (!w->next) |
1026 | { |
1048 | { |
1027 | struct sigaction sa; |
1049 | struct sigaction sa; |
1028 | sa.sa_handler = sighandler; |
1050 | sa.sa_handler = sighandler; |
1029 | sigfillset (&sa.sa_mask); |
1051 | sigfillset (&sa.sa_mask); |
1030 | sa.sa_flags = 0; |
1052 | sa.sa_flags = SA_RESTART; /* if restarting works we save one iteration */ |
1031 | sigaction (w->signum, &sa, 0); |
1053 | sigaction (w->signum, &sa, 0); |
1032 | } |
1054 | } |
1033 | } |
1055 | } |
1034 | |
1056 | |
1035 | void |
1057 | void |