… | |
… | |
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 | |
423 | static void |
425 | static void |
424 | sigcb (struct ev_io *iow, int revents) |
426 | sigcb (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 | |
480 | static void |
482 | static void |
|
|
483 | child_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 | |
|
|
498 | static void |
481 | childcb (struct ev_signal *sw, int revents) |
499 | childcb (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->rpid = pid; |
|
|
491 | w->rstatus = status; |
|
|
492 | event ((W)w, EV_CHILD); |
507 | event ((W)sw, EV_SIGNAL); |
493 | } |
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 | } |
494 | } |
512 | } |
495 | |
513 | |
496 | #endif |
514 | #endif |
497 | |
515 | |
498 | /*****************************************************************************/ |
516 | /*****************************************************************************/ |
… | |
… | |
520 | ev_version_minor (void) |
538 | ev_version_minor (void) |
521 | { |
539 | { |
522 | return EV_VERSION_MINOR; |
540 | return EV_VERSION_MINOR; |
523 | } |
541 | } |
524 | |
542 | |
525 | /* return true if we are running with elevated privileges and ignore env variables */ |
543 | /* return true if we are running with elevated privileges and should ignore env variables */ |
526 | static int |
544 | static int |
527 | enable_secure () |
545 | enable_secure () |
528 | { |
546 | { |
|
|
547 | #ifdef WIN32 |
|
|
548 | return 0; |
|
|
549 | #else |
529 | return getuid () != geteuid () |
550 | return getuid () != geteuid () |
530 | || getgid () != getegid (); |
551 | || getgid () != getegid (); |
|
|
552 | #endif |
531 | } |
553 | } |
532 | |
554 | |
533 | int ev_init (int methods) |
555 | int ev_init (int methods) |
534 | { |
556 | { |
535 | if (!ev_method) |
557 | if (!ev_method) |
… | |
… | |
571 | #endif |
593 | #endif |
572 | |
594 | |
573 | if (ev_method) |
595 | if (ev_method) |
574 | { |
596 | { |
575 | ev_watcher_init (&sigev, sigcb); |
597 | ev_watcher_init (&sigev, sigcb); |
|
|
598 | ev_set_priority (&sigev, EV_MAXPRI); |
576 | siginit (); |
599 | siginit (); |
577 | |
600 | |
578 | #ifndef WIN32 |
601 | #ifndef WIN32 |
579 | ev_signal_init (&childev, childcb, SIGCHLD); |
602 | ev_signal_init (&childev, childcb, SIGCHLD); |
|
|
603 | ev_set_priority (&childev, EV_MAXPRI); |
580 | ev_signal_start (&childev); |
604 | ev_signal_start (&childev); |
581 | #endif |
605 | #endif |
582 | } |
606 | } |
583 | } |
607 | } |
584 | |
608 | |
… | |
… | |
1008 | } |
1032 | } |
1009 | |
1033 | |
1010 | ev_stop ((W)w); |
1034 | ev_stop ((W)w); |
1011 | } |
1035 | } |
1012 | |
1036 | |
|
|
1037 | #ifndef SA_RESTART |
|
|
1038 | # define SA_RESTART 0 |
|
|
1039 | #endif |
|
|
1040 | |
1013 | void |
1041 | void |
1014 | ev_signal_start (struct ev_signal *w) |
1042 | ev_signal_start (struct ev_signal *w) |
1015 | { |
1043 | { |
1016 | if (ev_is_active (w)) |
1044 | if (ev_is_active (w)) |
1017 | return; |
1045 | return; |
… | |
… | |
1025 | if (!w->next) |
1053 | if (!w->next) |
1026 | { |
1054 | { |
1027 | struct sigaction sa; |
1055 | struct sigaction sa; |
1028 | sa.sa_handler = sighandler; |
1056 | sa.sa_handler = sighandler; |
1029 | sigfillset (&sa.sa_mask); |
1057 | sigfillset (&sa.sa_mask); |
1030 | sa.sa_flags = 0; |
1058 | sa.sa_flags = SA_RESTART; /* if restarting works we save one iteration */ |
1031 | sigaction (w->signum, &sa, 0); |
1059 | sigaction (w->signum, &sa, 0); |
1032 | } |
1060 | } |
1033 | } |
1061 | } |
1034 | |
1062 | |
1035 | void |
1063 | void |