| 881 | } |
| 882 | |
| 883 | struct subd *subd_shutdown(struct subd *sd, unsigned int seconds) |
| 884 | { |
| 885 | struct sigaction sa, old; |
| 886 | |
| 887 | log_debug(sd->log, "Shutting down"); |
| 888 | |
| 889 | tal_del_destructor(sd, destroy_subd); |
| 890 | |
| 891 | /* This should make it exit; steal so it stays around. */ |
| 892 | tal_steal(sd->ld, sd); |
| 893 | sd->conn = tal_free(sd->conn); |
| 894 | |
| 895 | /* Set up alarm to wake us up if child doesn't exit. */ |
| 896 | sa.sa_handler = discard_alarm; |
| 897 | sigemptyset(&sa.sa_mask); |
| 898 | sa.sa_flags = 0; |
| 899 | sigaction(SIGALRM, &sa, &old); |
| 900 | alarm(seconds); |
| 901 | |
| 902 | if (waitpid(sd->pid, NULL, 0) > 0) { |
| 903 | alarm(0); |
| 904 | sigaction(SIGALRM, &old, NULL); |
| 905 | list_del_from(&sd->ld->subds, &sd->list); |
| 906 | return tal_free(sd); |
| 907 | } |
| 908 | |
| 909 | sigaction(SIGALRM, &old, NULL); |
| 910 | /* Didn't die? This will kill it harder */ |
| 911 | sd->must_not_exit = false; |
| 912 | destroy_subd(sd); |
| 913 | return tal_free(sd); |
| 914 | } |
| 915 | |
| 916 | void subd_shutdown_nonglobals(struct lightningd *ld) |
| 917 | { |
no test coverage detected