-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
libflux: clean up bulk message handler registration functions #1277
Changes from all commits
a3bfc4a
46310aa
09c86ab
02ce8d6
26a7ba7
6cb5349
43fa0c8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -157,7 +157,8 @@ static void signal_cb (flux_reactor_t *r, flux_watcher_t *w, | |
static void broker_handle_signals (broker_ctx_t *ctx, zlist_t *sigwatchers); | ||
static void broker_unhandle_signals (zlist_t *sigwatchers); | ||
|
||
static void broker_add_services (broker_ctx_t *ctx); | ||
static flux_msg_handler_t **broker_add_services (broker_ctx_t *ctx); | ||
static void broker_remove_services (flux_msg_handler_t *handlers[]); | ||
|
||
static int load_module_byname (broker_ctx_t *ctx, const char *name, | ||
const char *argz, size_t argz_len, | ||
|
@@ -310,6 +311,7 @@ int main (int argc, char *argv[]) | |
sigset_t old_sigmask; | ||
struct sigaction old_sigact_int; | ||
struct sigaction old_sigact_term; | ||
flux_msg_handler_t **handlers; | ||
|
||
memset (&ctx, 0, sizeof (ctx)); | ||
log_init (argv[0]); | ||
|
@@ -579,7 +581,7 @@ int main (int argc, char *argv[]) | |
if (rusage_initialize (ctx.h, "cmb") < 0) | ||
log_err_exit ("rusage_initialize"); | ||
|
||
broker_add_services (&ctx); | ||
handlers = broker_add_services (&ctx); | ||
|
||
/* Initialize comms module infrastructure. | ||
*/ | ||
|
@@ -651,7 +653,7 @@ int main (int argc, char *argv[]) | |
|
||
/* Unregister builtin services | ||
*/ | ||
attr_unregister_handlers (); | ||
attr_unregister_handlers (ctx.attrs); | ||
content_cache_destroy (ctx.cache); | ||
|
||
broker_unhandle_signals (sigwatchers); | ||
|
@@ -668,6 +670,8 @@ int main (int argc, char *argv[]) | |
service_switch_destroy (ctx.services); | ||
hello_destroy (ctx.hello); | ||
attr_destroy (ctx.attrs); | ||
shutdown_destroy (ctx.shutdown); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like a good improvement, but unrelated to this commit's logical topic. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed, will split out. |
||
broker_remove_services (handlers); | ||
flux_close (ctx.h); | ||
flux_reactor_destroy (ctx.reactor); | ||
if (ctx.subscriptions) { | ||
|
@@ -1694,16 +1698,16 @@ static int route_to_handle (const flux_msg_t *msg, void *arg) | |
return 0; | ||
} | ||
|
||
static struct flux_msg_handler_spec handlers[] = { | ||
{ FLUX_MSGTYPE_REQUEST, "cmb.rmmod", cmb_rmmod_cb, 0, NULL }, | ||
{ FLUX_MSGTYPE_REQUEST, "cmb.insmod", cmb_insmod_cb, 0, NULL }, | ||
{ FLUX_MSGTYPE_REQUEST, "cmb.lsmod", cmb_lsmod_cb, 0, NULL }, | ||
{ FLUX_MSGTYPE_REQUEST, "cmb.lspeer", cmb_lspeer_cb, 0, NULL }, | ||
{ FLUX_MSGTYPE_REQUEST, "cmb.panic", cmb_panic_cb, 0, NULL }, | ||
{ FLUX_MSGTYPE_REQUEST, "cmb.event-mute", cmb_event_mute_cb, 0, NULL }, | ||
{ FLUX_MSGTYPE_REQUEST, "cmb.disconnect", cmb_disconnect_cb, 0, NULL }, | ||
{ FLUX_MSGTYPE_REQUEST, "cmb.sub", cmb_sub_cb, 0, NULL }, | ||
{ FLUX_MSGTYPE_REQUEST, "cmb.unsub", cmb_unsub_cb, 0, NULL }, | ||
static const struct flux_msg_handler_spec htab[] = { | ||
{ FLUX_MSGTYPE_REQUEST, "cmb.rmmod", cmb_rmmod_cb, 0 }, | ||
{ FLUX_MSGTYPE_REQUEST, "cmb.insmod", cmb_insmod_cb, 0 }, | ||
{ FLUX_MSGTYPE_REQUEST, "cmb.lsmod", cmb_lsmod_cb, 0 }, | ||
{ FLUX_MSGTYPE_REQUEST, "cmb.lspeer", cmb_lspeer_cb, 0 }, | ||
{ FLUX_MSGTYPE_REQUEST, "cmb.panic", cmb_panic_cb, 0 }, | ||
{ FLUX_MSGTYPE_REQUEST, "cmb.event-mute", cmb_event_mute_cb, 0 }, | ||
{ FLUX_MSGTYPE_REQUEST, "cmb.disconnect", cmb_disconnect_cb, 0 }, | ||
{ FLUX_MSGTYPE_REQUEST, "cmb.sub", cmb_sub_cb, 0 }, | ||
{ FLUX_MSGTYPE_REQUEST, "cmb.unsub", cmb_unsub_cb, 0 }, | ||
FLUX_MSGHANDLER_TABLE_END, | ||
}; | ||
|
||
|
@@ -1727,8 +1731,9 @@ static struct internal_service services[] = { | |
* Register message handlers for some cmb services. Others are registered | ||
* in their own initialization functions. | ||
*/ | ||
static void broker_add_services (broker_ctx_t *ctx) | ||
static flux_msg_handler_t **broker_add_services (broker_ctx_t *ctx) | ||
{ | ||
flux_msg_handler_t **handlers; | ||
struct internal_service *svc; | ||
for (svc = &services[0]; svc->name != NULL; svc++) { | ||
if (!nodeset_member (svc->nodeset, overlay_get_rank(ctx->overlay))) | ||
|
@@ -1738,8 +1743,16 @@ static void broker_add_services (broker_ctx_t *ctx) | |
log_err_exit ("error registering service for %s", svc->name); | ||
} | ||
|
||
if (flux_msg_handler_addvec (ctx->h, handlers, ctx) < 0) | ||
if (flux_msg_handler_addvec (ctx->h, htab, ctx, &handlers) < 0) | ||
log_err_exit ("error registering message handlers"); | ||
return handlers; | ||
} | ||
|
||
/* Unregister message handlers | ||
*/ | ||
static void broker_remove_services (flux_msg_handler_t *handlers[]) | ||
{ | ||
flux_msg_handler_delvec (handlers); | ||
} | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,8 @@ | |
#include <flux/core.h> | ||
#include "heaptrace.h" | ||
|
||
static flux_msg_handler_t **handlers = NULL; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In C, file scope variables are already initialized to 0 so the "= NULL" is redundant. Not a big deal. |
||
|
||
static void start_cb (flux_t *h, flux_msg_handler_t *mh, | ||
const flux_msg_t *msg, void *arg) | ||
{ | ||
|
@@ -111,10 +113,10 @@ static void stop_cb (flux_t *h, flux_msg_handler_t *mh, | |
FLUX_LOG_ERROR (h); | ||
} | ||
|
||
static struct flux_msg_handler_spec handlers[] = { | ||
{ FLUX_MSGTYPE_REQUEST, "heaptrace.start", start_cb, 0, NULL }, | ||
{ FLUX_MSGTYPE_REQUEST, "heaptrace.dump", dump_cb, 0, NULL }, | ||
{ FLUX_MSGTYPE_REQUEST, "heaptrace.stop", stop_cb, 0, NULL }, | ||
static const struct flux_msg_handler_spec htab[] = { | ||
{ FLUX_MSGTYPE_REQUEST, "heaptrace.start", start_cb, 0 }, | ||
{ FLUX_MSGTYPE_REQUEST, "heaptrace.dump", dump_cb, 0 }, | ||
{ FLUX_MSGTYPE_REQUEST, "heaptrace.stop", stop_cb, 0 }, | ||
FLUX_MSGHANDLER_TABLE_END, | ||
}; | ||
|
||
|
@@ -126,7 +128,7 @@ static void heaptrace_finalize (void *arg) | |
int heaptrace_initialize (flux_t *h) | ||
{ | ||
char *dummy = "hello"; | ||
if (flux_msg_handler_addvec (h, handlers, NULL) < 0) | ||
if (flux_msg_handler_addvec (h, htab, NULL, &handlers) < 0) | ||
return -1; | ||
flux_aux_set (h, "flux::heaptrace", dummy, heaptrace_finalize); | ||
return 0; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change from 0 (FLUX_ROLE_NONE) to FLUX_ROLE_ALL looks like something that should be broken out into a separate commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a hard one to split out. The code was setting the rolemask to 0, then changing it with code like
Since
w
is gone, I thought it best to change the initial setting rather than walk thehandlers
list or whatever.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused about why that is hard. Doesn't
just change into
No walking seems to be required.
But again, I perfectly fine with changing the place the rolemask is set. You could even make that rolemask location change in a commit before this one. It is just a change that isn't really pertinent to this commit.
This is minor enough though that I am willing to let it slide.