@@ -120,26 +120,52 @@ static struct command_result *reckless_result(struct io_conn *conn,
120120 return command_finished (reckless -> cmd , response );
121121}
122122
123+ static struct command_result * reckless_fail (struct reckless * reckless ,
124+ char * err )
125+ {
126+ struct json_stream * resp ;
127+ resp = jsonrpc_stream_fail (reckless -> cmd , PLUGIN_ERROR , err );
128+ return command_finished (reckless -> cmd , resp );
129+ }
130+
123131static void reckless_conn_finish (struct io_conn * conn ,
124132 struct reckless * reckless )
125133{
126134 /* FIXME: avoid EBADFD - leave stdin fd open? */
127135 if (errno && errno != 9 )
128136 plugin_log (plugin , LOG_DBG , "err: %s" , strerror (errno ));
129- reckless_result (conn , reckless );
130137 if (reckless -> pid > 0 ) {
131- int status ;
138+ int status = 0 ;
132139 pid_t p ;
133140 p = waitpid (reckless -> pid , & status , WNOHANG );
134141 /* Did the reckless process exit? */
135142 if (p != reckless -> pid && reckless -> pid ) {
136- plugin_log (plugin , LOG_DBG , "reckless failed to exit "
137- "(%i), killing now." , status );
143+ plugin_log (plugin , LOG_DBG , "reckless failed to exit, "
144+ "killing now." );
138145 kill (reckless -> pid , SIGKILL );
146+ reckless_fail (reckless , "reckless process hung" );
147+ /* Reckless process exited and with normal status? */
148+ } else if (WIFEXITED (status ) && !WEXITSTATUS (status )) {
149+ plugin_log (plugin , LOG_DBG ,
150+ "Reckless subprocess complete: %s" ,
151+ reckless -> stdoutbuf );
152+ reckless_result (conn , reckless );
153+ /* Don't try to process json if python raised an error. */
154+ } else {
155+ plugin_log (plugin , LOG_DBG ,
156+ "Reckless process has crashed (%i)." ,
157+ WEXITSTATUS (status ));
158+ char * err ;
159+ if (reckless -> process_failed )
160+ err = reckless -> process_failed ;
161+ else
162+ err = tal_strdup (tmpctx , "the reckless process "
163+ "has crashed" );
164+ reckless_fail (reckless , err );
165+ plugin_log (plugin , LOG_UNUSUAL ,
166+ "The reckless subprocess has failed." );
139167 }
140168 }
141- plugin_log (plugin , LOG_DBG , "Reckless subprocess complete." );
142- plugin_log (plugin , LOG_DBG , "output: %s" , reckless -> stdoutbuf );
143169 io_close (conn );
144170 tal_free (reckless );
145171}
0 commit comments