@ -10,7 +10,6 @@
# include <common/gen_status_wire.h>
# include <common/gen_status_wire.h>
# include <errno.h>
# include <errno.h>
# include <fcntl.h>
# include <fcntl.h>
# include <lightningd/channel.h>
# include <lightningd/lightningd.h>
# include <lightningd/lightningd.h>
# include <lightningd/log.h>
# include <lightningd/log.h>
# include <lightningd/log_status.h>
# include <lightningd/log_status.h>
@ -389,7 +388,7 @@ static bool log_status_fail(struct subd *sd, const u8 *msg)
static bool handle_received_errmsg ( struct subd * sd , const u8 * msg )
static bool handle_received_errmsg ( struct subd * sd , const u8 * msg )
{
{
struct channel * channel = sd - > channel ;
void * channel = sd - > channel ;
struct channel_id channel_id ;
struct channel_id channel_id ;
char * desc ;
char * desc ;
@ -401,14 +400,14 @@ static bool handle_received_errmsg(struct subd *sd, const u8 *msg)
/* Don't free sd; we're may be about to free channel. */
/* Don't free sd; we're may be about to free channel. */
sd - > channel = NULL ;
sd - > channel = NULL ;
channel_fail_permanent ( channel ,
if ( sd - > errcb )
" %s: received ERROR %s " , sd - > name , desc ) ;
sd - > errcb ( channel , REMOTE , & channel_id , desc , NULL ) ;
return true ;
return true ;
}
}
static bool handle_sent_errmsg ( struct subd * sd , const u8 * msg )
static bool handle_sent_errmsg ( struct subd * sd , const u8 * msg )
{
{
struct channel * channel = sd - > channel ;
void * channel = sd - > channel ;
struct channel_id channel_id ;
struct channel_id channel_id ;
char * desc ;
char * desc ;
u8 * errmsg ;
u8 * errmsg ;
@ -418,13 +417,11 @@ static bool handle_sent_errmsg(struct subd *sd, const u8 *msg)
return false ;
return false ;
/* FIXME: if not all channels failed, hand back to gossipd! */
/* FIXME: if not all channels failed, hand back to gossipd! */
if ( ! channel - > error )
channel - > error = tal_steal ( channel , errmsg ) ;
/* Don't free sd; we're may be about to free channel. */
/* Don't free sd; we're may be about to free channel. */
sd - > channel = NULL ;
sd - > channel = NULL ;
channel_fail_permanent ( channel ,
if ( sd - > errcb )
" %s: sent ERROR %s " , sd - > name , desc ) ;
sd - > errcb ( channel , LOCAL , & channel_id , desc , errmsg ) ;
return true ;
return true ;
}
}
@ -573,7 +570,7 @@ static void destroy_subd(struct subd *sd)
/* Peer still attached? */
/* Peer still attached? */
if ( sd - > channel ) {
if ( sd - > channel ) {
/* Don't loop back when we fail it. */
/* Don't loop back when we fail it. */
struct channel * channel = sd - > channel ;
void * channel = sd - > channel ;
struct db * db = sd - > ld - > wallet - > db ;
struct db * db = sd - > ld - > wallet - > db ;
bool outer_transaction ;
bool outer_transaction ;
@ -583,9 +580,11 @@ static void destroy_subd(struct subd *sd)
outer_transaction = db - > in_transaction ;
outer_transaction = db - > in_transaction ;
if ( ! outer_transaction )
if ( ! outer_transaction )
db_begin_transaction ( db ) ;
db_begin_transaction ( db ) ;
channel_fail_transient ( channel ,
if ( sd - > errcb )
" Owning subdaemon %s died (%i) " ,
sd - > errcb ( channel , LOCAL , NULL ,
sd - > name , status ) ;
tal_fmt ( sd , " Owning subdaemon %s died (%i) " ,
sd - > name , status ) ,
NULL ) ;
if ( ! outer_transaction )
if ( ! outer_transaction )
db_commit_transaction ( db ) ;
db_commit_transaction ( db ) ;
}
}
@ -625,10 +624,16 @@ static struct io_plan *msg_setup(struct io_conn *conn, struct subd *sd)
static struct subd * new_subd ( struct lightningd * ld ,
static struct subd * new_subd ( struct lightningd * ld ,
const char * name ,
const char * name ,
struct channel * channel ,
void * channel ,
struct log * base_log ,
const char * ( * msgname ) ( int msgtype ) ,
const char * ( * msgname ) ( int msgtype ) ,
unsigned int ( * msgcb ) ( struct subd * ,
unsigned int ( * msgcb ) ( struct subd * ,
const u8 * , const int * fds ) ,
const u8 * , const int * fds ) ,
void ( * errcb ) ( void * channel ,
enum side sender ,
const struct channel_id * channel_id ,
const char * desc ,
const u8 * errmsg ) ,
va_list * ap )
va_list * ap )
{
{
struct subd * sd = tal ( ld , struct subd ) ;
struct subd * sd = tal ( ld , struct subd ) ;
@ -649,9 +654,9 @@ static struct subd *new_subd(struct lightningd *ld,
return tal_free ( sd ) ;
return tal_free ( sd ) ;
}
}
sd - > ld = ld ;
sd - > ld = ld ;
if ( channel ) {
if ( base_log ) {
sd - > log = new_log ( sd , channel - > peer - > log_book , " %s-%s " , name ,
sd - > log = new_log ( sd , get_log_book ( base_log ) , " %s-%s " , name ,
log_prefix ( channel - > log ) ) ;
log_prefix ( base_ log) ) ;
} else {
} else {
sd - > log = new_log ( sd , ld - > log_book , " %s(%u): " , name , sd - > pid ) ;
sd - > log = new_log ( sd , ld - > log_book , " %s(%u): " , name , sd - > pid ) ;
}
}
@ -660,6 +665,7 @@ static struct subd *new_subd(struct lightningd *ld,
sd - > must_not_exit = false ;
sd - > must_not_exit = false ;
sd - > msgname = msgname ;
sd - > msgname = msgname ;
sd - > msgcb = msgcb ;
sd - > msgcb = msgcb ;
sd - > errcb = errcb ;
sd - > fds_in = NULL ;
sd - > fds_in = NULL ;
msg_queue_init ( & sd - > outq , sd ) ;
msg_queue_init ( & sd - > outq , sd ) ;
tal_add_destructor ( sd , destroy_subd ) ;
tal_add_destructor ( sd , destroy_subd ) ;
@ -686,25 +692,32 @@ struct subd *new_global_subd(struct lightningd *ld,
struct subd * sd ;
struct subd * sd ;
va_start ( ap , msgcb ) ;
va_start ( ap , msgcb ) ;
sd = new_subd ( ld , name , NULL , msgname , msgcb , & ap ) ;
sd = new_subd ( ld , name , NULL , NULL , msgname , msgcb , NULL , & ap ) ;
va_end ( ap ) ;
va_end ( ap ) ;
sd - > must_not_exit = true ;
sd - > must_not_exit = true ;
return sd ;
return sd ;
}
}
struct subd * new_channel_subd ( struct lightningd * ld ,
struct subd * new_channel_subd_ ( struct lightningd * ld ,
const char * name ,
const char * name ,
struct channel * channel ,
void * channel ,
const char * ( * msgname ) ( int msgtype ) ,
struct log * base_log ,
unsigned int ( * msgcb ) ( struct subd * , const u8 * ,
const char * ( * msgname ) ( int msgtype ) ,
const int * fds ) , . . . )
unsigned int ( * msgcb ) ( struct subd * , const u8 * ,
const int * fds ) ,
void ( * errcb ) ( void * channel ,
enum side sender ,
const struct channel_id * channel_id ,
const char * desc ,
const u8 * errmsg ) ,
. . . )
{
{
va_list ap ;
va_list ap ;
struct subd * sd ;
struct subd * sd ;
va_start ( ap , msgcb ) ;
va_start ( ap , err cb) ;
sd = new_subd ( ld , name , channel , msgname , msgcb , & ap ) ;
sd = new_subd ( ld , name , channel , base_log , msgname , msgcb , err cb , & ap ) ;
va_end ( ap ) ;
va_end ( ap ) ;
return sd ;
return sd ;
}
}
@ -764,7 +777,7 @@ void subd_shutdown(struct subd *sd, unsigned int seconds)
tal_free ( sd ) ;
tal_free ( sd ) ;
}
}
void subd_release_channel ( struct subd * owner , struct channel * channel )
void subd_release_channel ( struct subd * owner , void * channel )
{
{
/* If owner is a per-peer-daemon, and not already freeing itself... */
/* If owner is a per-peer-daemon, and not already freeing itself... */
if ( owner - > channel ) {
if ( owner - > channel ) {