diff --git a/main.c b/main.c index e94468f1cdd86a34cd21984d35c75cbd84b0fc3c..8635d7eeecba65bc3351bc0a127fd620f0dbde92 100644 --- a/main.c +++ b/main.c @@ -23,8 +23,7 @@ #define UCI_CONFIG_DIR "/etc/config/" #endif - -static int log_level = LOG_INFO; +int log_level = LOG_INFO; static int audio_rx_fd; static int audio_tx_fd; static int event_fd; @@ -269,7 +268,6 @@ int main(int argc, char **argv) { const char *hw_board_voice_names; openlog(argv[0], LOG_PID, LOG_DAEMON); - setlogmask(LOG_UPTO(log_level)); // Load the UCI package context = uci_alloc_context(); @@ -288,6 +286,10 @@ int main(int argc, char **argv) { return EXIT_FAILURE; } + config_syslog(context, package); + ENDPT_INFO("syslog level is set to %d\n", log_level); + setlogmask(LOG_UPTO(log_level)); + // Unbuffered stdout if(isatty(STDOUT_FILENO)) setbuf(stdout, NULL); @@ -328,7 +330,6 @@ int main(int argc, char **argv) { if(voice_line_init(has_dect)) goto __error_ret; if(line_dect_init()) goto __error_ret; if(voice_connection_init()) goto __error_ret; - if(perhaps_erase_unused_lines(context)) goto __error_ret; // Enable UBUS when all initializations have finished if(ubus_enable_receive()) goto __error_ret; diff --git a/ubus.c b/ubus.c index 14128392f58fc8f1fe0062fbe6e047ea911474bc..ce4f3cf3e5723a73e8cb2bda53745f66458f0d1e 100644 --- a/ubus.c +++ b/ubus.c @@ -16,6 +16,8 @@ #include "line-dect.h" #include "main.h" +extern int log_level; + enum { STATUS_LINE, }; @@ -134,7 +136,7 @@ static const char broadcast_path[] = "voice.endpoint"; // UBUS path name for b static const char uciStrComSect[] = "tel_options"; // Common endpoint section name static const char uciStrLineSect[] = "extension"; // Line specific section name static const char uciStrCountry[] = "country"; // Endpoint country -static const char uciStrLoglevel[] = "vmloglevel"; // syslog level of voicemngr +static const char uciStrLoglevel[] = "vmloglevel"; // syslog level of voicemngr static const char ubusStrObjAdd[] = "ubus.object.add"; // UBUS objects added to global context static const char ubusStrObjRm[] = "ubus.object.remove"; // UBUS objects added removed from global context @@ -1242,60 +1244,25 @@ __return: return res; } -// Runtime erase of lines from UCI if they are not populated -// in HW. This prevents them from showing up in the web GUI. -int perhaps_erase_unused_lines(struct uci_context *context) +void config_syslog(struct uci_context *context, struct uci_package *package) { - char uciSection[strlen(uciStrConfig) + strlen(uciStrLineSect) + 12]; - char uciSection2[sizeof(uciSection)]; - int line, didErase = 0; - struct uci_ptr ptr; + struct uci_section *section = NULL; char *error; + const char *loglevel; - for(line = 0; line < terminal_info.num_voice_ports; line++) { - if(!lines[line].simulated_busy) - continue; - if(!lines[line].line_conf.config_loaded) - continue; // Erase only if exist in UCI - - snprintf(uciSection, sizeof(uciSection), "%s.%s%d", uciStrConfig, uciStrLineSect, line); - strncpy(uciSection2, uciSection, sizeof(uciSection2)); // uci_lookup_ptr() can modify uciSection - if (uci_lookup_ptr(context, &ptr, uciSection, true) == UCI_OK) { - if(uci_delete(context, &ptr) == 0) { - ENDPT_INFO("Remove voice line %s, since DECT is not supported\n", uciSection2); - didErase++; - } else { - uci_get_errorstr(context, &error, ""); - ENDPT_ERR("Failed to remove the uci section %s, %s\n", uciSection2, error); - free(error); - return -1; - } - } else { - uci_get_errorstr(context, &error, ""); - ENDPT_ERR("Failed to look up the uci section %s, %s\n", uciSection2, error); - free(error); - return -1; - } + section = uci_lookup_section(context, package, uciStrComSect); + if (!section) { + uci_get_errorstr(context, &error, ""); + ENDPT_ERR("Failed to look up section %s.%s, %s\n", uciStrConfig, uciStrComSect, error); + free(error); + return; } - if(didErase) { - strncpy(uciSection, uciStrConfig, sizeof(uciSection)); // uci_lookup_ptr() can modify uciSection - if (uci_lookup_ptr(context, &ptr, uciSection, true) == UCI_OK) { - if(uci_commit(context, &ptr.p, false) != UCI_OK) { - uci_get_errorstr(context, &error, ""); - ENDPT_ERR("Failed to commit uci package %s, %s\n", uciStrConfig, error); - free(error); - return -1; - } - } else { - uci_get_errorstr(context, &error, ""); - ENDPT_ERR("Failed to look up package %s, %s\n", uciStrConfig, error); - free(error); - return -1; - } + // configure the syslog level for voicemngr + loglevel = uci_lookup_option_string(context, section, uciStrLoglevel); + if (loglevel && *loglevel) { + log_level = atoi(loglevel); } - - return 0; } // Read settings from UCI for this application. @@ -1304,7 +1271,6 @@ int config_init(struct uci_context *context, struct uci_package *package) struct uci_section *section = NULL; char *error; const char *country; - const char *loglevel; char uciSection[sizeof(uciStrLineSect) + 10]; int line; @@ -1328,13 +1294,6 @@ int config_init(struct uci_context *context, struct uci_package *package) return -1; } - // configure the syslog level for voicemngr - loglevel = uci_lookup_option_string(context, section, uciStrLoglevel); - if (loglevel && *loglevel) { - ENDPT_INFO("syslog level is set to %s\n", loglevel); - setlogmask(LOG_UPTO(atoi(loglevel) & LOG_PRIMASK)); - } - // Configure the voice lines for (line = 0; line < terminal_info.num_voice_ports; line++) { snprintf(uciSection, sizeof(uciSection), "%s%d", uciStrLineSect, line); diff --git a/ubus.h b/ubus.h index c7673487c37c576833e135bf0e98238e1c790482..145a2ea364e9eae4054b89a430a55611125834bf 100644 --- a/ubus.h +++ b/ubus.h @@ -17,8 +17,8 @@ int send_reply_asterisk(struct voice_ubus_req_t *req, enum ubus_msg_status ubusR int send_reply_dectmngr(struct voice_ubus_req_t *req, int terminal, int pcmId, enum ubus_msg_status ubusRet); int ubus_call_dectmngr(int terminal, int add, int release, const char *cid, const char *caller_name, int pcmId, struct line_req_t *lineReq); int ubus_dectmngr_rpc(const struct dectmngr_rpc_t *dectmngr_rpc, const struct line_req_t *line_req); -int perhaps_erase_unused_lines(struct uci_context *context); int config_init(struct uci_context *context, struct uci_package *package); +void config_syslog(struct uci_context *context, struct uci_package *package); int ubus_disable_receive(void); int ubus_enable_receive(void); int ubus_init(void);