@@ -56,6 +56,20 @@ static void sdbus_recover (struct sdbus_ctx *ctx, const char *reason);
5656static const double retry_min = 2 ;
5757static const double retry_max = 60 ;
5858
59+ static bool sdbus_debug = false;
60+
61+ static __attribute__ ((format (printf , 2 , 3 )))
62+ void sdbus_log_debug (flux_t * h , const char * fmt , ...)
63+ {
64+ if (sdbus_debug ) {
65+ va_list ap ;
66+
67+ va_start (ap , fmt );
68+ flux_vlog (h , LOG_DEBUG , fmt , ap );
69+ va_end (ap );
70+ }
71+ }
72+
5973static int authorize_request (const flux_msg_t * msg ,
6074 uint32_t rank ,
6175 flux_error_t * error )
@@ -173,13 +187,12 @@ static void log_msg_signal (flux_t *h,
173187
174188 if (path )
175189 (void )sd_bus_path_decode (path , prefix , & s );
176- flux_log (h ,
177- LOG_DEBUG ,
178- "bus %s %s %s %s" ,
179- disposition ,
180- sdmsg_typestr (m ),
181- s ? s : path ,
182- sd_bus_message_get_member (m ));
190+ sdbus_log_debug (h ,
191+ "bus %s %s %s %s" ,
192+ disposition ,
193+ sdmsg_typestr (m ),
194+ s ? s : path ,
195+ sd_bus_message_get_member (m ));
183196 free (s );
184197}
185198
@@ -189,12 +202,11 @@ static void log_msg_method_reply (flux_t *h,
189202 sd_bus_message * m ,
190203 struct call_info * info )
191204{
192- flux_log (h ,
193- LOG_DEBUG ,
194- "bus recv %s cookie=%ju %s" ,
195- sdmsg_typestr (m ),
196- (uintmax_t )info -> cookie ,
197- info -> member );
205+ sdbus_log_debug (h ,
206+ "bus recv %s cookie=%ju %s" ,
207+ sdmsg_typestr (m ),
208+ (uintmax_t )info -> cookie ,
209+ info -> member );
198210}
199211
200212static void sdbus_recv (struct sdbus_ctx * ctx , sd_bus_message * m )
@@ -287,7 +299,7 @@ static void sdbus_recv (struct sdbus_ctx *ctx, sd_bus_message *m)
287299out :
288300 return ;
289301log_drop :
290- flux_log (ctx -> h , LOG_DEBUG , "bus drop %s" , sdmsg_typestr (m ));
302+ sdbus_log_debug (ctx -> h , "bus drop %s" , sdmsg_typestr (m ));
291303}
292304
293305static void call_info_destroy (struct call_info * info )
@@ -352,12 +364,11 @@ static int handle_call_request (struct sdbus_ctx *ctx,
352364 goto error ;
353365 }
354366
355- flux_log (ctx -> h ,
356- LOG_DEBUG ,
357- "bus send %s cookie=%ju %s" ,
358- sdmsg_typestr (m ),
359- (uintmax_t )cookie ,
360- sd_bus_message_get_member (m ));
367+ sdbus_log_debug (ctx -> h ,
368+ "bus send %s cookie=%ju %s" ,
369+ sdmsg_typestr (m ),
370+ (uintmax_t )cookie ,
371+ sd_bus_message_get_member (m ));
361372
362373 if (!(info = call_info_create (m , cookie ))
363374 || flux_msg_aux_set (msg ,
@@ -500,6 +511,53 @@ static void reconnect_cb (flux_t *h,
500511 flux_log_error (h , "error responding to sdbus.reconnect request" );
501512}
502513
514+ static int sdbus_configure (struct sdbus_ctx * ctx ,
515+ const flux_conf_t * conf ,
516+ flux_error_t * error )
517+ {
518+ flux_error_t conf_error ;
519+ int debug = 0 ;
520+
521+ if (flux_conf_unpack (conf ,
522+ & conf_error ,
523+ "{s?{s?b}}" ,
524+ "systemd" ,
525+ "sdbus-debug" , & debug ) < 0 ) {
526+ errprintf (error ,
527+ "error reading [systemd] config table: %s" ,
528+ conf_error .text );
529+ return -1 ;
530+ }
531+ sdbus_debug = (debug ? true : false);
532+ return 0 ;
533+ }
534+
535+ static void reload_cb (flux_t * h ,
536+ flux_msg_handler_t * mh ,
537+ const flux_msg_t * msg ,
538+ void * arg )
539+ {
540+ struct sdbus_ctx * ctx = arg ;
541+ const flux_conf_t * conf ;
542+ flux_error_t error ;
543+ const char * errstr = NULL ;
544+
545+ if (flux_conf_reload_decode (msg , & conf ) < 0 ) {
546+ errstr = "Failed to parse config-reload request" ;
547+ goto error ;
548+ }
549+ if (sdbus_configure (ctx , conf , & error ) < 0 ) {
550+ errstr = error .text ;
551+ goto error ;
552+ }
553+ if (flux_respond (h , msg , NULL ) < 0 )
554+ flux_log_error (h , "error responding to config-reload request" );
555+ return ;
556+ error :
557+ if (flux_respond_error (h , msg , errno , errstr ) < 0 )
558+ flux_log_error (h , "error responding to config-reload request" );
559+ }
560+
503561static struct flux_msg_handler_spec htab [] = {
504562 { FLUX_MSGTYPE_REQUEST ,
505563 "sdbus.disconnect" ,
@@ -526,6 +584,11 @@ static struct flux_msg_handler_spec htab[] = {
526584 reconnect_cb ,
527585 0
528586 },
587+ { FLUX_MSGTYPE_REQUEST ,
588+ "sdbus.config-reload" ,
589+ reload_cb ,
590+ 0
591+ },
529592 FLUX_MSGHANDLER_TABLE_END ,
530593};
531594
@@ -696,18 +759,22 @@ struct sdbus_ctx *sdbus_ctx_create (flux_t *h, flux_error_t *error)
696759{
697760 struct sdbus_ctx * ctx ;
698761
699- if (!(ctx = calloc (1 , sizeof (* ctx )))
700- || !(ctx -> f_conn = sdbus_connect (h , true, retry_min , retry_max ))
762+ if (!(ctx = calloc (1 , sizeof (* ctx ))))
763+ goto error_create ;
764+ if (sdbus_configure (ctx , flux_get_conf (h ), error ) < 0 )
765+ goto error ;
766+ if (!(ctx -> f_conn = sdbus_connect (h , true, retry_min , retry_max ))
701767 || flux_future_then (ctx -> f_conn , -1 , connect_continuation , ctx ) < 0
702768 || flux_msg_handler_addvec (h , htab , ctx , & ctx -> handlers ) < 0
703769 || !(ctx -> requests = flux_msglist_create ())
704770 || !(ctx -> subscribers = flux_msglist_create ())
705771 || flux_get_rank (h , & ctx -> rank ) < 0 )
706- goto error ;
772+ goto error_create ;
707773 ctx -> h = h ;
708774 return ctx ;
709- error :
775+ error_create :
710776 errprintf (error , "error creating sdbus context: %s" , strerror (errno ));
777+ error :
711778 sdbus_ctx_destroy (ctx );
712779 return NULL ;
713780}
0 commit comments