diff --git a/bbfdmd/ubus/bbfdmd.c b/bbfdmd/ubus/bbfdmd.c index a5d9e095..d7ce3ce5 100644 --- a/bbfdmd/ubus/bbfdmd.c +++ b/bbfdmd/ubus/bbfdmd.c @@ -56,7 +56,7 @@ static void service_request_timeout(struct uloop_timeout *timeout) return; } - BBFDM_ERR("Timeout occurred for request: '%s get'", tracker->service ? tracker->service->name : "unknown"); + BBFDM_WARNING("Timeout occurred for request: '%s get'", tracker->service ? tracker->service->name : "unknown"); ubus_abort_request(tracker->ubus_ctx, &tracker->async_request); BBFDM_FREE(tracker); } @@ -89,12 +89,12 @@ static void verify_service(struct ubus_context *ubus_ctx, service_entry_t *servi uint32_t id = 0; if (!ubus_ctx || !service || !service->name) { - BBFDM_ERR("Invalid arguments"); + BBFDM_WARNING("Invalid arguments"); return; } if (ubus_lookup_id(ubus_ctx, service->name, &id)) { - BBFDM_ERR("Failed to lookup object: %s", service->name); + BBFDM_INFO("Failed to lookup object: %s", service->name); return; } @@ -116,7 +116,7 @@ static void verify_service(struct ubus_context *ubus_ctx, service_entry_t *servi blobmsg_add_string(&req_buf, "path", BBFDM_ROOT_OBJECT); if (ubus_invoke_async(ubus_ctx, id, "get", req_buf.head, &tracker->async_request)) { - BBFDM_ERR("Failed to invoke async method for object: '%s get'", service->name); + BBFDM_WARNING("Failed to invoke async method for object: '%s get'", service->name); uloop_timeout_cancel(&tracker->timeout); BBFDM_FREE(tracker); } else { @@ -169,7 +169,7 @@ static void bbfdm_ubus_add_event_cb(struct ubus_context *ctx, struct ubus_event_ if (path && strncmp(path, BBFDM_UBUS_OBJECT".", strlen(BBFDM_UBUS_OBJECT) + 1) == 0) { - BBFDM_ERR("Detected new service registration: '%s'", path); + BBFDM_INFO("Detected new service registration: '%s'", path); list_for_each_entry(service, ®istered_services, list) { // Check if the service is present in the registred services list @@ -178,13 +178,13 @@ static void bbfdm_ubus_add_event_cb(struct ubus_context *ctx, struct ubus_event_ service->consecutive_timeouts = 0; service_found = true; fill_service_schema(ctx, 5000, service->name, &service->dm_schema); - BBFDM_ERR("Service '%s' found in registry. Resetting blacklist and timeout counters.", path); + BBFDM_INFO("Service '%s' found in registry. Resetting blacklist and timeout counters.", path); break; } } if (!service_found) { - BBFDM_ERR("Newly registered service '%s' is not recognized in the registry." + BBFDM_WARNING("Newly registered service '%s' is not recognized in the registry." " Possible missing configuration JSON file under '%s'.", path, BBFDM_MICROSERVICE_INPUT_PATH); } @@ -261,12 +261,12 @@ static int bbfdm_handler_async(struct ubus_context *ctx, struct ubus_object *obj bool raw_format = false; if (blobmsg_parse(bbfdm_policy, __BBFDM_MAX, tb, blob_data(msg), blob_len(msg))) { - BBFDM_ERR("Failed to parse input message"); + BBFDM_WARNING("Failed to parse input message"); return UBUS_STATUS_UNKNOWN_ERROR; } if (!tb[BBFDM_PATH]) { - BBFDM_ERR("%s: path must be defined", method); + BBFDM_WARNING("%s: path must be defined", method); return UBUS_STATUS_INVALID_ARGUMENT; } @@ -282,7 +282,7 @@ static int bbfdm_handler_async(struct ubus_context *ctx, struct ubus_object *obj struct async_request_context *context = (struct async_request_context *)calloc(1, sizeof(struct async_request_context)); if (!context) { - BBFDM_ERR("Failed to allocate memory"); + BBFDM_WARNING("Failed to allocate memory"); return UBUS_STATUS_UNKNOWN_ERROR; } @@ -331,12 +331,12 @@ static int bbfdm_handler_sync(struct ubus_context *ctx, struct ubus_object *obj, struct blob_buf bb = {0}; if (blobmsg_parse(bbfdm_policy, __BBFDM_MAX, tb, blob_data(msg), blob_len(msg))) { - BBFDM_ERR("Failed to parse input message"); + BBFDM_WARNING("Failed to parse input message"); return UBUS_STATUS_UNKNOWN_ERROR; } if (!tb[BBFDM_PATH]) { - BBFDM_ERR("%s: path must be defined", method); + BBFDM_WARNING("%s: path must be defined", method); return UBUS_STATUS_INVALID_ARGUMENT; } diff --git a/bbfdmd/ubus/get.c b/bbfdmd/ubus/get.c index b09f41fb..12b66340 100644 --- a/bbfdmd/ubus/get.c +++ b/bbfdmd/ubus/get.c @@ -76,7 +76,7 @@ static void append_response_data(struct ubus_request_tracker *tracker, struct bl static void handle_request_timeout(struct uloop_timeout *timeout) { struct ubus_request_tracker *tracker = container_of(timeout, struct ubus_request_tracker, timeout); - BBFDM_ERR("Timeout occurred for request: '%s %s'", tracker->request_name, tracker->ctx->requested_path); + BBFDM_WARNING("Timeout occurred for request: '%s %s'", tracker->request_name, tracker->ctx->requested_path); ubus_abort_request(tracker->ctx->ubus_ctx, &tracker->async_request); tracker->ctx->pending_requests--; @@ -92,7 +92,7 @@ static void handle_request_timeout(struct uloop_timeout *timeout) } if (tracker->ctx->pending_requests == 0 && tracker->ctx->service_list_processed) { - BBFDM_ERR("All requests completed after timeout"); + BBFDM_WARNING("All requests completed after timeout"); send_response(tracker->ctx); } @@ -141,7 +141,7 @@ void run_async_call(struct async_request_context *ctx, service_entry_t *service, } if (ubus_lookup_id(ctx->ubus_ctx, service->name, &id)) { - BBFDM_ERR("Failed to lookup object: %s", service->name); + BBFDM_INFO("Failed to lookup object: %s", service->name); return; } @@ -175,7 +175,7 @@ void run_async_call(struct async_request_context *ctx, service_entry_t *service, } if (ubus_invoke_async(ctx->ubus_ctx, id, ctx->ubus_method, req_buf.head, &tracker->async_request)) { - BBFDM_ERR("Failed to invoke async method for object: %s", tracker->request_name); + BBFDM_WARNING("Failed to invoke async method for object: %s", tracker->request_name); uloop_timeout_cancel(&tracker->timeout); BBFDM_FREE(tracker); } else { diff --git a/bbfdmd/ubus/service.c b/bbfdmd/ubus/service.c index cc3b47e7..a914b654 100644 --- a/bbfdmd/ubus/service.c +++ b/bbfdmd/ubus/service.c @@ -123,13 +123,13 @@ static int load_service_from_file(struct ubus_context *ubus_ctx, const char *fil return -1; } - json_object *json_root = json_object_from_file(file_path); - if (!json_root) { - BBFDM_ERR("Failed to read JSON file: %s", file_path); - return -1; - } + json_object *json_root = json_object_from_file(file_path); + if (!json_root) { + BBFDM_ERR("Failed to read JSON file: %s", file_path); + return -1; + } - json_object *daemon_config = NULL; + json_object *daemon_config = NULL; json_object_object_get_ex(json_root, "daemon", &daemon_config); if (!daemon_config) { BBFDM_ERR("Failed to find daemon object"); @@ -137,7 +137,7 @@ static int load_service_from_file(struct ubus_context *ubus_ctx, const char *fil return -1; } - json_object *enable_jobj = NULL; + json_object *enable_jobj = NULL; json_object_object_get_ex(daemon_config, "enable", &enable_jobj); bool enable = enable_jobj ? json_object_get_boolean(enable_jobj) : false; if (!enable) { @@ -172,7 +172,7 @@ static int load_service_from_file(struct ubus_context *ubus_ctx, const char *fil size_t service_count = json_object_array_length(services_array); if (service_count == 0) { - BBFDM_ERR("Skipping service '%s' due to no objects defined", service_name); + BBFDM_WARNING("Skipping service '%s' due to no objects defined", service_name); json_object_put(json_root); return -1; } @@ -196,7 +196,7 @@ static int load_service_from_file(struct ubus_context *ubus_ctx, const char *fil snprintf(objects[num_objs].object_name, sizeof(objects[num_objs].object_name), "%s", object ? json_object_get_string(object) : ""); if (strlen(objects[num_objs].parent_path) == 0 || strlen(objects[num_objs].object_name) == 0) { - BBFDM_ERR("Skip empty registration parent_dm[%s] or object[%s]", objects[num_objs].parent_path, objects[num_objs].object_name); + BBFDM_WARNING("Skip empty registration parent_dm[%s] or object[%s]", objects[num_objs].parent_path, objects[num_objs].object_name); continue; } diff --git a/dm-service/dm_service.c b/dm-service/dm_service.c index 84b85267..e1d3b8fb 100644 --- a/dm-service/dm_service.c +++ b/dm-service/dm_service.c @@ -66,11 +66,11 @@ int main(int argc, char **argv) int res = bbfdm_print_data_model_schema(&bbfdm_ctx, dm_type); exit(res); } + openlog(bbfdm_ctx.config.service_name, LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1); bbfdm_ubus_set_log_level(log_level); bbfdm_ubus_load_data_model(NULL); - openlog(bbfdm_ctx.config.service_name, LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1); err = bbfdm_ubus_regiter_init(&bbfdm_ctx); if (err != 0) diff --git a/libbbfdm-ubus/bbfdm-ubus.c b/libbbfdm-ubus/bbfdm-ubus.c index 65198e7f..d8343e4e 100644 --- a/libbbfdm-ubus/bbfdm-ubus.c +++ b/libbbfdm-ubus/bbfdm-ubus.c @@ -779,7 +779,7 @@ int bbfdm_print_data_model_schema(struct bbfdm_context *bbfdm_ctx, const enum bb int bbfdm_ubus_regiter_init(struct bbfdm_context *bbfdm_ctx) { - int err = 0; + int err = 0, cur_log_mask=0; err = ubus_connect_ctx(&bbfdm_ctx->ubus_ctx, NULL); if (err != UBUS_STATUS_OK) { @@ -787,6 +787,13 @@ int bbfdm_ubus_regiter_init(struct bbfdm_context *bbfdm_ctx) return -5; // Error code -5 indicating that ubus_ctx is not connected } + // Set the logmask with default, if not already set by api + cur_log_mask = setlogmask(0); + if (cur_log_mask == 0xff) { + BBF_INFO("Log level not set, setting default value %d", LOG_ERR); + bbfdm_ubus_set_log_level(LOG_ERR); + } + uloop_init(); ubus_add_uloop(&bbfdm_ctx->ubus_ctx);