diff --git a/log.c b/log.c index 7a0f1e1..407efdd 100644 --- a/log.c +++ b/log.c @@ -163,6 +163,10 @@ void puts_log_xmlmsg(int severity, char *msg, int msgtype) char buf[1024]; char *description, *separator; + if (msg == NULL) { + return; + } + pthread_mutex_lock(&mutex_log); if (severity > log_severity) { diff --git a/ubus_utils.c b/ubus_utils.c index c21576c..41f8346 100644 --- a/ubus_utils.c +++ b/ubus_utils.c @@ -397,16 +397,33 @@ int icwmp_ubus_invoke(const char *obj, const char *method, struct blob_attr *msg { uint32_t id; int rc = 0; + int retry = 0; struct ubus_context *ubus_ctx = NULL; ubus_ctx = ubus_connect(NULL); + while (ubus_ctx == NULL && retry < 5) { + retry ++; + CWMP_LOG(DEBUG, "Failed to connect ubus retry after 1 sec"); + sleep(1); + ubus_ctx = ubus_connect(NULL); + } + if (ubus_ctx == NULL) { - CWMP_LOG(ERROR, "Failed to connect with ubus"); + CWMP_LOG(ERROR, "Failed to connect with ubus err: %d", errno); return -1; } - if (!ubus_lookup_id(ubus_ctx, obj, &id)) { + retry = 0; + rc = ubus_lookup_id(ubus_ctx, obj, &id); + while (rc != 0 && retry < 5) { + retry ++; + CWMP_LOG(DEBUG, "Failed to ubus lookup %s, retry after 1 sec", obj); + sleep(1); + rc = ubus_lookup_id(ubus_ctx, obj, &id); + } + + if (!rc) { rc = ubus_invoke(ubus_ctx, id, method, msg, icwmp_callback, callback_arg, 60000); } else { CWMP_LOG(ERROR, "Failed to ubus lookup %s", obj); diff --git a/xml.c b/xml.c index 084a239..3d5e223 100644 --- a/xml.c +++ b/xml.c @@ -140,9 +140,19 @@ int xml_send_message(struct cwmp *cwmp, struct session *session, struct rpc *rpc mxml_node_t *b; int compression = global_int_param_read(&cwmp->conf.compression); + if (session == NULL) { + CWMP_LOG(ERROR, "Received session is NULL"); + return -1; + } + if (session->tree_out) { unsigned char *zmsg_out; msg_out = mxmlSaveAllocString(session->tree_out, whitespace_cb); + if (msg_out == NULL) { + CWMP_LOG(ERROR, "Received tree_out is empty"); + return -1; + } + CWMP_LOG_XML_MSG(DEBUG, msg_out, XML_MSG_OUT); if (compression != COMP_NONE) { if (zlib_compress(msg_out, &zmsg_out, &msg_out_len, compression)) {