| 128 | } |
| 129 | |
| 130 | static void reckless_conn_finish(struct io_conn *conn, |
| 131 | struct reckless *reckless) |
| 132 | { |
| 133 | /* FIXME: avoid EBADFD - leave stdin fd open? */ |
| 134 | if (errno && errno != 9) |
| 135 | plugin_log(plugin, LOG_DBG, "err: %s", strerror(errno)); |
| 136 | if (reckless->pid > 0) { |
| 137 | int status = 0; |
| 138 | pid_t p; |
| 139 | p = waitpid(reckless->pid, &status, WNOHANG); |
| 140 | /* Did the reckless process exit? */ |
| 141 | if (p != reckless->pid && reckless->pid) { |
| 142 | plugin_log(plugin, LOG_DBG, "reckless failed to exit, " |
| 143 | "killing now."); |
| 144 | kill(reckless->pid, SIGKILL); |
| 145 | reckless_fail(reckless, "reckless process hung"); |
| 146 | /* Reckless process exited and with normal status? */ |
| 147 | } else if (WIFEXITED(status) && !WEXITSTATUS(status)) { |
| 148 | plugin_log(plugin, LOG_DBG, |
| 149 | "Reckless subprocess complete: %s", |
| 150 | reckless->stdoutbuf); |
| 151 | reckless_result(conn, reckless); |
| 152 | /* Don't try to process json if python raised an error. */ |
| 153 | } else { |
| 154 | plugin_log(plugin, LOG_DBG, |
| 155 | "Reckless process has crashed (%i).", |
| 156 | WEXITSTATUS(status)); |
| 157 | char * err; |
| 158 | if (reckless->process_failed) |
| 159 | err = reckless->process_failed; |
| 160 | else |
| 161 | err = tal_strdup(tmpctx, "the reckless process " |
| 162 | "has crashed"); |
| 163 | reckless_fail(reckless, err); |
| 164 | plugin_log(plugin, LOG_UNUSUAL, |
| 165 | "The reckless subprocess has failed."); |
| 166 | } |
| 167 | } |
| 168 | io_close(conn); |
| 169 | tal_free(reckless); |
| 170 | } |
| 171 | |
| 172 | static struct io_plan *conn_init(struct io_conn *conn, struct reckless *rkls) |
| 173 | { |
nothing calls this directly
no test coverage detected