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