mirror of
https://dev.iopsys.eu/bbf/bbfdm.git
synced 2025-12-10 07:44:39 +01:00
B#14541: micro-services not getting re-registered if bbfdmd restarts
This commit is contained in:
parent
46bafc541d
commit
0d16ce491a
2 changed files with 21 additions and 12 deletions
|
|
@ -1786,6 +1786,8 @@ static int daemon_load_datamodel(struct bbfdm_context *daemon_ctx)
|
|||
return err;
|
||||
}
|
||||
|
||||
static struct ubus_event_handler add_event = { .cb = lookup_event_cb };
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
struct bbfdm_context bbfdm_ctx;
|
||||
|
|
@ -1869,20 +1871,19 @@ int main(int argc, char **argv)
|
|||
if (is_micro_service == true) { // It's a micro-service instance
|
||||
char proc_name[32] = {0};
|
||||
|
||||
// Create process name using service name and prefix "dm_"
|
||||
snprintf(proc_name, sizeof(proc_name), "dm_%s", bbfdm_ctx.config.service_name);
|
||||
// Set process name based on microservice
|
||||
|
||||
// Set process name for the current process
|
||||
prctl(PR_SET_NAME, proc_name, NULL, NULL, NULL);
|
||||
|
||||
bool is_registred = register_service(&bbfdm_ctx.ubus_ctx);
|
||||
if (is_registred == false) {
|
||||
// register for add event
|
||||
struct ubus_event_handler add_event;
|
||||
// Register the micro-service
|
||||
register_service(&bbfdm_ctx.ubus_ctx);
|
||||
|
||||
memset(&add_event, 0, sizeof(struct ubus_event_handler));
|
||||
add_event.cb = lookup_event_cb;
|
||||
// If the micro-service is not registered, listen for "ubus.object.add" event
|
||||
// and register the micro-service using event handler for it
|
||||
ubus_register_event_handler(&bbfdm_ctx.ubus_ctx, &add_event, "ubus.object.add");
|
||||
}
|
||||
}
|
||||
|
||||
INFO("Waiting on uloop....");
|
||||
uloop_run();
|
||||
|
|
|
|||
|
|
@ -101,14 +101,22 @@ void free_services_from_list(struct list_head *clist)
|
|||
|
||||
bool load_service(DMOBJ *main_dm, struct list_head *srv_list, char *srv_name, char *srv_parent_dm, char *srv_obj)
|
||||
{
|
||||
if (!main_dm || !srv_list || !srv_name || !srv_parent_dm || !srv_obj)
|
||||
if (!main_dm || !srv_list || !srv_name || !srv_parent_dm || !srv_obj) {
|
||||
BBF_ERR("Invalid arguments: main_dm, srv_list, srv_name, srv_parent_dm, and srv_obj must not be NULL.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (is_service_registered(srv_list, srv_name, srv_parent_dm, srv_obj))
|
||||
if (is_service_registered(srv_list, srv_name, srv_parent_dm, srv_obj)) {
|
||||
BBF_ERR("Service registration failed: Service '%s' with parent DM '%s' and object '%s' is already registered.",
|
||||
srv_name, srv_parent_dm, srv_obj);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!add_service_to_main_tree(main_dm, srv_name, srv_parent_dm, srv_obj))
|
||||
if (!add_service_to_main_tree(main_dm, srv_name, srv_parent_dm, srv_obj)) {
|
||||
BBF_ERR("Failed to add service '%s' to main tree with parent DM '%s' and object '%s'.",
|
||||
srv_name, srv_parent_dm, srv_obj);
|
||||
return false;
|
||||
}
|
||||
|
||||
add_service_to_list(srv_list, srv_name, srv_parent_dm, srv_obj);
|
||||
return true;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue