From cfef57f31aba00aa2bfa147b6d491aa16a2a37e8 Mon Sep 17 00:00:00 2001 From: Rozhuk Ivan Date: Fri, 15 Mar 2024 22:17:44 +0200 Subject: [PATCH] Migrate to syslog. --- CMakeLists.txt | 6 +- conf/msd_lite.conf | 4 +- msd_lite.project | 8 +-- src/CMakeLists.txt | 1 - src/liblcb | 2 +- src/msd_lite.c | 86 +++++++++++-------------- src/msd_lite_stat_text.c | 3 +- src/stream_sys.c | 134 ++++++++++++++++----------------------- 8 files changed, 101 insertions(+), 143 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1bf8b14..e68276f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,13 +3,13 @@ # ############################# INITIAL SECTION ########################## -cmake_minimum_required(VERSION 3.10) +cmake_minimum_required(VERSION 3.20) project(msd_lite C) set(PACKAGE_VERSION_MAJOR 1) -set(PACKAGE_VERSION_MINOR 10) -set(PACKAGE_VERSION_PATCH 1) +set(PACKAGE_VERSION_MINOR 11) +set(PACKAGE_VERSION_PATCH 0) set(PACKAGE_NAME "${PROJECT_NAME}") set(PACKAGE_VERSION "${PACKAGE_VERSION_MAJOR}.${PACKAGE_VERSION_MINOR}.${PACKAGE_VERSION_PATCH}") diff --git a/conf/msd_lite.conf b/conf/msd_lite.conf index 8712a22..5656cae 100644 --- a/conf/msd_lite.conf +++ b/conf/msd_lite.conf @@ -17,14 +17,12 @@ available. - /root/msd_lite/msd_lite.log + 6 1 yes - yes - 100 diff --git a/msd_lite.project b/msd_lite.project index aefecbb..73b5485 100644 --- a/msd_lite.project +++ b/msd_lite.project @@ -57,7 +57,6 @@ - @@ -89,7 +88,6 @@ - @@ -126,7 +124,7 @@ - + @@ -190,12 +188,12 @@ make mkdir $(ProjectPath)/$(ConfigurationName) && cd $(ProjectPath)/$(ConfigurationName) && -cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_VERBOSE_MAKEFILE=true -DENABLE_ALSA=true .. +cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_VERBOSE_MAKEFILE=true .. rm -rf $(ProjectPath)/$(ConfigurationName) && mkdir $(ProjectPath)/$(ConfigurationName) && cd $(ProjectPath)/$(ConfigurationName) && -cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_VERBOSE_MAKEFILE=true -DENABLE_ALSA=true .. && +cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_VERBOSE_MAKEFILE=true .. && make -C $(ProjectPath)/$(ConfigurationName) -j`getconf NPROCESSORS_ONLN` rm -rf $(ProjectPath)/$(ConfigurationName) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d8a30f7..e05650e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -17,7 +17,6 @@ set(MSD_LITE_BIN msd_lite.c liblcb/src/utils/buf_str.c liblcb/src/utils/info.c liblcb/src/utils/ring_buffer.c - liblcb/src/utils/log.c liblcb/src/utils/xml.c) add_executable(msd_lite ${MSD_LITE_BIN}) diff --git a/src/liblcb b/src/liblcb index bbd23a1..a9d53c0 160000 --- a/src/liblcb +++ b/src/liblcb @@ -1 +1 @@ -Subproject commit bbd23a182474750f6c2410e3d1d33144ac028372 +Subproject commit a9d53c0401af5c28d64a67fd327f4ce27f379e2d diff --git a/src/msd_lite.c b/src/msd_lite.c index 24a8d1d..4a9dfdc 100644 --- a/src/msd_lite.c +++ b/src/msd_lite.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2012-2023 Rozhuk Ivan + * Copyright (c) 2012-2024 Rozhuk Ivan * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -50,6 +50,7 @@ #include /* close, write, sysconf */ #include /* open, fcntl */ #include /* SIGNAL constants. */ +#include #include "utils/mem_utils.h" @@ -65,7 +66,6 @@ #include "threadpool/threadpool_task.h" #include "utils/buf_str.h" #include "utils/sys.h" -#include "utils/log.h" #include "proto/http_server.h" #include "utils/info.h" #include "utils/cmd_line_daemon.h" @@ -277,7 +277,6 @@ msd_src_conn_profile_load(const uint8_t *data, size_t data_size, void *conn) { int main(int argc, char *argv[]) { int error = 0; - int log_fd = -1; uint8_t *cfg_file_buf = NULL; size_t tm, cfg_file_buf_size = 0; tp_p tp; @@ -293,60 +292,49 @@ main(int argc, char *argv[]) { } if (0 != cmd_line_data.daemon) { make_daemon(); + openlog(PACKAGE_NAME, + (LOG_NDELAY | LOG_PID | ((0 != cmd_line_data.verbose) ? LOG_PERROR : 0)), + LOG_DAEMON); + } else { + openlog(PACKAGE_NAME, + (LOG_NDELAY | LOG_PID | LOG_PERROR), LOG_USER); } + setlogmask(LOG_UPTO(cmd_line_data.log_level)); - { // process config file + { /* Process config file. */ const uint8_t *data; - char strbuf[1024]; size_t data_size; tp_settings_t tp_s; http_srv_cli_ccb_t ccb; http_srv_settings_t http_s; - g_log_fd = (uintptr_t)open("/dev/stderr", (O_WRONLY | O_APPEND)); error = read_file(cmd_line_data.cfg_file_name, 0, 0, 0, CFG_FILE_MAX_SIZE, &cfg_file_buf, &cfg_file_buf_size); if (0 != error) { - LOG_ERR(error, "config read_file()"); + SYSLOG_ERR(LOG_CRIT, error, "config read_file()."); goto err_out; } if (0 != xml_get_val_args(cfg_file_buf, cfg_file_buf_size, NULL, NULL, NULL, NULL, NULL, (const uint8_t*)"msd", NULL)) { - LOG_INFO("Config file XML format invalid."); + syslog(LOG_CRIT, "Config file XML format invalid."); goto err_out; } - /* Log file */ - if (0 == cmd_line_data.verbose && - 0 == MSD_CFG_GET_VAL_DATA(NULL, &data, &data_size, - "log", "file", NULL)) { - if (sizeof(strbuf) > data_size) { - memcpy(strbuf, data, data_size); - strbuf[data_size] = 0; - log_fd = open(strbuf, - (O_WRONLY | O_APPEND | O_CREAT), 0644); - if (-1 == log_fd) { - LOG_ERR(errno, "Fail to open log file."); - } - } else { - LOG_ERR(EINVAL, "Log file name too long."); - } - } else if (0 != cmd_line_data.verbose) { - log_fd = open("/dev/stdout", (O_WRONLY | O_APPEND)); - } - close((int)g_log_fd); - g_log_fd = (uintptr_t)log_fd; - fd_set_nonblocking(g_log_fd, 1); - log_write("\n\n\n\n", 4); - LOG_INFO(PACKAGE_STRING": started"); + /* Log level. */ + if (0 == MSD_CFG_GET_VAL_UINT(NULL, (uint32_t*)&cmd_line_data.log_level, + "log", "level", NULL)) { + setlogmask(LOG_UPTO(cmd_line_data.log_level)); + } + syslog(LOG_NOTICE, PACKAGE_STRING": started!"); #ifdef DEBUG - LOG_INFO("Build: "__DATE__" "__TIME__", DEBUG"); + syslog(LOG_INFO, "Build: "__DATE__" "__TIME__", DEBUG."); #else - LOG_INFO("Build: "__DATE__" "__TIME__", Release"); + syslog(LOG_INFO, "Build: "__DATE__" "__TIME__", Release."); #endif - LOG_INFO_FMT("CPU count: %d", get_cpu_count()); - LOG_INFO_FMT("descriptor table size: %d (max files)", getdtablesize()); + syslog(LOG_INFO, "CPU count: %d.", get_cpu_count()); + syslog(LOG_INFO, "Descriptor table size: %d (max files).", getdtablesize()); + /* System resource limits. */ if (0 == MSD_CFG_GET_VAL_DATA(NULL, &data, &data_size, @@ -362,16 +350,16 @@ main(int argc, char *argv[]) { } error = tp_create(&tp_s, &tp); if (0 != error) { - LOG_ERR(error, "tp_create()"); + SYSLOG_ERR(LOG_CRIT, error, "tp_create()."); goto err_out; } - tp_threads_create(tp, 1);// XXX exit rewrite + tp_threads_create(tp, 1); /* XXX exit rewrite. */ /* HTTP server settings. */ /* Read from config. */ if (0 != MSD_CFG_GET_VAL_DATA(NULL, &data, &data_size, "HTTP", NULL)) { - LOG_INFO("No HTTP server settings, nothink to do..."); + syslog(LOG_NOTICE, "No HTTP server settings, nothink to do..."); goto err_out; } http_srv_def_settings(1, PACKAGE_NAME"/"PACKAGE_VERSION, 1, &http_s); @@ -385,7 +373,7 @@ main(int argc, char *argv[]) { NULL, &ccb, &http_s, &g_data, &g_data.http_srv); if (0 != error) { - LOG_ERR(error, "http_srv_xml_load_start()"); + SYSLOG_ERR(LOG_CRIT, error, "http_srv_xml_load_start()."); goto err_out; } @@ -411,9 +399,10 @@ main(int argc, char *argv[]) { error = str_hubs_bckt_create(tp, PACKAGE_NAME"/"PACKAGE_VERSION, &g_data.hub_params, &g_data.src_params, &g_data.shbskt); if (0 != error) { - LOG_ERR(error, "str_hubs_bckt_create()"); + SYSLOG_ERR(LOG_CRIT, error, "str_hubs_bckt_create()."); goto err_out; } + free(cfg_file_buf); } /* Done with config. */ @@ -446,9 +435,8 @@ main(int argc, char *argv[]) { } tp_destroy(tp); - LOG_INFO("exiting."); - close((int)g_data.log_fd); - free(cfg_file_buf); + syslog(LOG_NOTICE, "Exiting."); + closelog(); err_out: return (error); @@ -469,7 +457,7 @@ msd_http_srv_hub_attach(http_srv_cli_p cli, uint8_t *hub_name, size_t hub_name_s tp_task_p tptask; uintptr_t skt; - LOGD_EV("..."); + SYSLOGD_EX(LOG_DEBUG, "..."); if (NULL == cli || NULL == hub_name) return (EINVAL); @@ -491,7 +479,7 @@ msd_http_srv_hub_attach(http_srv_cli_p cli, uint8_t *hub_name, size_t hub_name_s } strh_cli = str_hub_cli_alloc(skt, (const char*)ptm, tm); if (NULL == strh_cli) { - LOG_ERR(ENOMEM, "str_hub_cli_alloc()"); + syslog(LOG_ERR, "str_hub_cli_alloc()."); return (ENOMEM); } /* @@ -508,14 +496,14 @@ msd_http_srv_hub_attach(http_srv_cli_p cli, uint8_t *hub_name, size_t hub_name_s sa_copy(&strh_cli->remonte_addr, &strh_cli->xreal_addr); } - LOGD_INFO_FMT("%s - : attach...", hub_name); + SYSLOGD_EX(LOG_DEBUG, "%s - : attach...", hub_name); error = str_hub_cli_attach(g_data.shbskt, strh_cli, hub_name, hub_name_size, src_conn_params); /* Do not read/write to stream hub client, stream hub is new owner! */ if (0 != error) { strh_cli->skt = (uintptr_t)-1; str_hub_cli_destroy(NULL, strh_cli); - LOG_ERR(error, "str_hub_cli_attach()"); + SYSLOG_ERR(LOG_ERR, error, "str_hub_cli_attach()."); } else { tp_task_flags_del(tptask, TP_TASK_F_CLOSE_ON_DESTROY); http_srv_cli_free(cli); @@ -533,7 +521,7 @@ msd_http_req_url_parse(http_srv_req_p req, struct sockaddr_storage *ssaddr, char straddr[STR_ADDR_LEN], ifname[(IFNAMSIZ + 1)]; struct sockaddr_storage ss; - LOGD_EV("..."); + SYSLOGD_EX(LOG_DEBUG, "..."); if (NULL == req || NULL == hub_name || 0 == hub_name_size) return (500); @@ -613,7 +601,7 @@ msd_http_srv_on_req_rcv_cb(http_srv_cli_p cli, void *udata __unused, static const char *cttype = "Content-Type: text/plain\r\n" "Pragma: no-cache"; - LOGD_EV("..."); + SYSLOGD_EX(LOG_DEBUG, "..."); if (HTTP_REQ_METHOD_GET != req->line.method_code && HTTP_REQ_METHOD_HEAD != req->line.method_code) { diff --git a/src/msd_lite_stat_text.c b/src/msd_lite_stat_text.c index a603804..1993d7d 100644 --- a/src/msd_lite_stat_text.c +++ b/src/msd_lite_stat_text.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2012 - 2021 Rozhuk Ivan + * Copyright (c) 2012-2024 Rozhuk Ivan * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -57,7 +57,6 @@ #include "proto/http_server.h" #include "stream_sys.h" #include "utils/info.h" -#include "utils/log.h" #include "msd_lite_stat_text.h" diff --git a/src/stream_sys.c b/src/stream_sys.c index 761ef7a..bd65036 100644 --- a/src/stream_sys.c +++ b/src/stream_sys.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2012-2023 Rozhuk Ivan + * Copyright (c) 2012-2024 Rozhuk Ivan * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -43,6 +43,7 @@ #include /* bcopy, bzero, memcpy, memmove, memset, strerror... */ #include #include +#include #include "utils/macro.h" #include "utils/sys.h" @@ -54,7 +55,6 @@ #include "net/utils.h" #include "utils/info.h" #include "utils/buf_str.h" -#include "utils/log.h" #include "proto/rtp.h" #include "proto/mpeg2ts.h" #include "crypto/hash/md5.h" @@ -257,7 +257,7 @@ str_hubs_bckt_create(tp_p tp, const char *app_ver, str_hub_settings_p hub_params error = tpt_ev_add_args(tp_thread_get_rr(shbskt->tp), TP_EV_TIMER, 0, 0, 1000 /* 1 sec. */, &shbskt->service_tmr); if (0 != error) { - LOGD_ERR(error, "tpt_ev_add_args()"); + SYSLOG_ERR(LOG_ERR, error, "tpt_ev_add_args()."); goto err_out; } @@ -294,7 +294,7 @@ str_hubs_bckt_destroy_msg_cb(tpt_p tpt, void *udata) { str_hub_p str_hub, str_hub_temp; size_t thread_num; - //LOGD_EV("..."); + //SYSLOGD_EX(LOG_DEBUG, "..."); thread_num = tp_thread_get_num(tpt); TAILQ_FOREACH_SAFE(str_hub, &shbskt->thr_data[thread_num].hub_head, next, @@ -336,7 +336,7 @@ str_hubs_bckt_enum_msg_cb(tpt_p tpt, void *udata) { str_hub_p str_hub, str_hub_temp; size_t thread_num; - //LOGD_EV("..."); + //SYSLOGD_EX(LOG_DEBUG, "..."); thread_num = tp_thread_get_num(tpt); TAILQ_FOREACH_SAFE(str_hub, &shbskt->thr_data[thread_num].hub_head, next, @@ -403,7 +403,8 @@ str_hubs_bckt_timer_service(str_hubs_bckt_p shbskt, str_hub_p str_hub, /* Check hub. */ if (0 == str_hub->cli_count) { - LOG_EV_FMT("%s: No more clients, selfdestroy.", str_hub->name); + syslog(LOG_INFO, "%s: No more clients, selfdestroy.", + str_hub->name); str_hub_destroy_int(str_hub); return; } @@ -424,7 +425,7 @@ str_hubs_bckt_timer_service(str_hubs_bckt_p shbskt, str_hub_p str_hub, error = skt_mc_join(tp_task_ident_get(str_hub->tptask), join, str_hub->src_conn_params.mc.if_index, &str_hub->src_conn_params.mc.udp.addr); - LOG_ERR(error, "skt_mc_join()"); + SYSLOG_ERR(LOG_ERR, error, "skt_mc_join()."); } } } @@ -435,7 +436,7 @@ str_hubs_bckt_timer_msg_cb(tpt_p tpt, void *udata) { str_hubs_stat_t stat; size_t thread_num; - //LOGD_EV("..."); + //SYSLOGD_EX(LOG_DEBUG, "..."); thread_num = tp_thread_get_num(tpt); mem_bzero(&stat, sizeof(str_hubs_stat_t)); @@ -451,7 +452,7 @@ static void str_hubs_bckt_timer_cb(tp_event_p ev __unused, tp_udata_p tp_udata) { str_hubs_bckt_p shbskt = (str_hubs_bckt_p)tp_udata->ident; - //LOGD_EV("..."); + //SYSLOGD_EX(LOG_DEBUG, "..."); if (NULL == shbskt) return; memcpy(&shbskt->tp_last_tmr, &shbskt->tp_last_tmr_next, sizeof(struct timespec)); @@ -471,7 +472,7 @@ str_hub_create_int(str_hubs_bckt_p shbskt, tpt_p tpt, uint8_t *name, size_t name str_src_settings_p src_params; str_src_conn_udp_p conn_udp; - LOGD_EV("..."); + SYSLOGD_EX(LOG_DEBUG, "..."); if (NULL == shbskt || NULL == name || 0 == name_size || NULL == str_hub_ret) return (EINVAL); @@ -502,20 +503,20 @@ str_hub_create_int(str_hubs_bckt_p shbskt, tpt_p tpt, uint8_t *name, size_t name &skt); if (0 != error) { skt = (uintptr_t)-1; - LOG_ERR(error, "skt_mc_bind()"); + SYSLOG_ERR(LOG_ERR, error, "skt_bind_ap()."); goto err_out; } /* Join to multicast group. */ error = skt_mc_join(skt, 1, src_conn_params->mc.if_index, &conn_udp->addr); if (0 != error) { - LOG_ERR(error, "skt_mc_join()"); + SYSLOG_ERR(LOG_ERR, error, "skt_mc_join()."); goto err_out; } /* Tune socket. */ error = skt_rcv_tune(skt, src_params->skt_rcv_buf, src_params->skt_rcv_lowat); if (0 != error) { - LOG_ERR(error, "skt_rcv_tune()"); + SYSLOG_ERR(LOG_ERR, error, "skt_rcv_tune()."); goto err_out; } /* Create IO task for socket. */ @@ -523,14 +524,14 @@ str_hub_create_int(str_hubs_bckt_p shbskt, tpt_p tpt, uint8_t *name, size_t name TP_TASK_F_CLOSE_ON_DESTROY, TP_EV_READ, 0, str_src_recv_mc_cb, str_hub, &str_hub->tptask); if (0 != error) { - LOG_ERR(error, "tp_task_notify_create()"); + SYSLOG_ERR(LOG_ERR, error, "tp_task_notify_create()."); goto err_out; } TAILQ_INSERT_HEAD(&shbskt->thr_data[tp_thread_get_num(tpt)].hub_head, str_hub, next); - LOG_INFO_FMT("%s: Created. (fd: %zu)", str_hub->name, skt); + syslog(LOG_INFO, "%s: Created. (fd: %zu)", str_hub->name, skt); (*str_hub_ret) = str_hub; return (0); @@ -540,7 +541,7 @@ str_hub_create_int(str_hubs_bckt_p shbskt, tpt_p tpt, uint8_t *name, size_t name close((int)skt); free(str_hub); (*str_hub_ret) = NULL; - LOG_ERR(error, "..."); + SYSLOG_ERR_EX(LOG_ERR, error, "..."); return (error); } @@ -548,7 +549,7 @@ void str_hub_destroy_int(str_hub_p str_hub) { str_hub_cli_p strh_cli, strh_cli_temp; - LOGD_EV("..."); + SYSLOGD_EX(LOG_DEBUG, "..."); if (NULL == str_hub) return; @@ -564,7 +565,7 @@ str_hub_destroy_int(str_hub_p str_hub) { str_hub_cli_destroy(str_hub, strh_cli); } - LOG_INFO_FMT("%s: Destroyed.", str_hub->name); + syslog(LOG_INFO, "%s: Destroyed.", str_hub->name); str_src_r_buf_free(str_hub); free(str_hub); @@ -575,7 +576,7 @@ str_hub_cli_p str_hub_cli_alloc(uintptr_t skt, const char *ua, size_t ua_size) { str_hub_cli_p strh_cli; - LOGD_EV("..."); + SYSLOGD_EX(LOG_DEBUG, "..."); if (STR_HUB_CLI_USER_AGENT_MAX_SIZE < ua_size) ua_size = STR_HUB_CLI_USER_AGENT_MAX_SIZE; @@ -600,17 +601,15 @@ str_hub_cli_destroy(str_hub_p str_hub, str_hub_cli_p strh_cli) { struct msghdr mhdr; struct iovec iov[4]; - LOGD_EV("..."); + SYSLOGD_EX(LOG_DEBUG, "..."); if (NULL == strh_cli) return; if (NULL != str_hub) { - if (0 != LOG_IS_ENABLED()) { - sa_addr_port_to_str(&strh_cli->remonte_addr, straddr, - sizeof(straddr), NULL); - LOG_INFO_FMT("%s - %s: deattached, cli_count = %zu", - str_hub->name, straddr, (str_hub->cli_count - 1)); - } + sa_addr_port_to_str(&strh_cli->remonte_addr, straddr, + sizeof(straddr), NULL); + syslog(LOG_INFO, "%s - %s: deattached, cli_count = %zu", + str_hub->name, straddr, (str_hub->cli_count - 1)); /* Remove from stream hub. */ TAILQ_REMOVE(&str_hub->cli_head, strh_cli, next); str_hub->cli_count --; @@ -681,7 +680,7 @@ str_hub_cli_attach_msg_cb(tpt_p tpt, void *udata) { size_t thread_num; int error = -1; - LOGD_EV("..."); + SYSLOGD_EX(LOG_DEBUG, "..."); thread_num = tp_thread_get_num(tpt); TAILQ_FOREACH_SAFE(str_hub, &cli_data->shbskt->thr_data[thread_num].hub_head, @@ -701,69 +700,48 @@ str_hub_cli_attach_msg_cb(tpt_p tpt, void *udata) { str_hub_cli_destroy(NULL, cli_data->strh_cli); close((int)cli_data->strh_cli->skt); free(cli_data); - LOG_ERR(error, "str_hub_create()"); + SYSLOG_ERR(LOG_ERR, error, "str_hub_create()."); return; } } strh_cli = cli_data->strh_cli; hub_params = &cli_data->shbskt->hub_params; + + sa_addr_port_to_str(&strh_cli->remonte_addr, straddr, sizeof(straddr), NULL); + /* Set. */ strh_cli->conn_time = gettime_monotonic(); /* Tune socket. */ /* Reduce kernel memory usage. */ error = skt_rcv_tune(strh_cli->skt, STR_HUB_CLI_RECV_BUF, STR_HUB_CLI_RECV_LOWAT); - if (0 != error) { - if (0 != LOG_IS_ENABLED()) { - sa_addr_port_to_str(&strh_cli->remonte_addr, straddr, sizeof(straddr), NULL); - LOG_ERR_FMT(error, "%s - %s: skt_rcv_tune()", - str_hub->name, straddr); - } - } + SYSLOG_ERR(LOG_NOTICE, error, "%s - %s: skt_rcv_tune().", + str_hub->name, straddr); error = skt_snd_tune(strh_cli->skt, hub_params->skt_snd_buf, 1); - if (0 != error) { - if (0 != LOG_IS_ENABLED()) { - sa_addr_port_to_str(&strh_cli->remonte_addr, straddr, sizeof(straddr), NULL); - LOG_ERR_FMT(error, "%s - %s: skt_snd_tune()", - str_hub->name, straddr); - } - } + SYSLOG_ERR(LOG_NOTICE, error, "%s - %s: skt_snd_tune().", + str_hub->name, straddr); if (0 != (STR_HUB_S_F_SKT_HALFCLOSED & hub_params->flags)) { - if (0 != shutdown((int)strh_cli->skt, SHUT_RD) && - 0 != LOG_IS_ENABLED()) { + if (0 != shutdown((int)strh_cli->skt, SHUT_RD)) { error = errno; - sa_addr_port_to_str(&strh_cli->remonte_addr, straddr, sizeof(straddr), NULL); - LOG_ERR_FMT(error, "%s - %s: shutdown(..., SHUT_RD)", + SYSLOG_ERR(LOG_NOTICE, error, "%s - %s: shutdown(..., SHUT_RD).", str_hub->name, straddr); } } error = skt_set_tcp_nodelay(strh_cli->skt, (STR_HUB_S_F_SKT_TCP_NODELAY & hub_params->flags)); - if (0 != error && 0 != LOG_IS_ENABLED()) { - sa_addr_port_to_str(&strh_cli->remonte_addr, straddr, sizeof(straddr), NULL); - LOG_ERR_FMT(error, "%s - %s: skt_set_tcp_nodelay()", - str_hub->name, straddr); - } + SYSLOG_ERR(LOG_NOTICE, error, "%s - %s: skt_set_tcp_nodelay().", + str_hub->name, straddr); error = skt_set_tcp_nopush(strh_cli->skt, (STR_HUB_S_F_SKT_TCP_NOPUSH & hub_params->flags)); - if (0 != error && 0 != LOG_IS_ENABLED()) { - sa_addr_port_to_str(&strh_cli->remonte_addr, straddr, sizeof(straddr), NULL); - LOG_ERR_FMT(error, "%s - %s: skt_set_tcp_nopush()", - str_hub->name, straddr); - } + SYSLOG_ERR(LOG_NOTICE, error, "%s - %s: skt_set_tcp_nopush().", + str_hub->name, straddr); if (0 != hub_params->cc_name_size) { error = skt_set_tcp_cc(strh_cli->skt, hub_params->cc_name, hub_params->cc_name_size); - if (0 != error && 0 != LOG_IS_ENABLED()) { - sa_addr_port_to_str(&strh_cli->remonte_addr, straddr, sizeof(straddr), NULL); - LOG_ERR_FMT(error, "%s - %s: skt_set_tcp_cc()", - str_hub->name, straddr); - } + SYSLOG_ERR(LOG_NOTICE, error, "%s - %s: skt_set_tcp_cc().", + str_hub->name, straddr); } - if (0 != LOG_IS_ENABLED()) { - sa_addr_port_to_str(&strh_cli->remonte_addr, straddr, sizeof(straddr), NULL); - LOG_INFO_FMT("%s - %s: attached, cli_count = %zu", - str_hub->name, straddr, (str_hub->cli_count + 1)); - } + syslog(LOG_INFO, "%s - %s: attached, cli_count = %zu", + str_hub->name, straddr, (str_hub->cli_count + 1)); TAILQ_INSERT_HEAD(&str_hub->cli_head, strh_cli, next); str_hub->cli_count ++; @@ -848,7 +826,7 @@ str_hub_send_to_clients(str_hub_p str_hub) { error = SKT_ERR_FILTER(errno); goto error_on_send; } - LOGD_EV_FMT("HTTP hdr: %zu", ios); + SYSLOGD_EX(LOG_DEBUG, "HTTP hdr: %zu", ios); strh_cli->offset += (size_t)ios; if (iovec_calc_size(mhdr.msg_iov, (size_t)mhdr.msg_iovlen) > (size_t)ios) /* Not all HTTP headers sended. */ @@ -865,11 +843,9 @@ str_hub_send_to_clients(str_hub_p str_hub) { error = str_hub_send_to_client(str_hub, strh_cli, &transfered_size); error_on_send: if (0 != error) { - if (0 != LOG_IS_ENABLED()) { - sa_addr_port_to_str(&strh_cli->remonte_addr, straddr, sizeof(straddr), NULL); - LOG_ERR_FMT(error, "%s - %s: disconnected.", - str_hub->name, straddr); - } + sa_addr_port_to_str(&strh_cli->remonte_addr, straddr, sizeof(straddr), NULL); + SYSLOG_ERR(LOG_ERR, error, "%s - %s: disconnected.", + str_hub->name, straddr); if (-1 != error || 0 != (STR_HUB_S_F_DROP_SLOW_CLI & str_hub->shbskt->hub_params.flags)) str_hub_cli_destroy(str_hub, strh_cli); @@ -897,7 +873,7 @@ str_src_recv_mc_cb(tp_task_p tptask, int error, uint32_t eof __unused, if (0 != error) { err_out: - LOG_ERR(error, "on receive"); + SYSLOG_ERR(LOG_DEBUG, error, "On receive."); str_hub_destroy_int(str_hub); return (TP_TASK_CB_NONE); /* Receiver destroyed. */ } @@ -947,7 +923,7 @@ str_src_recv_mc_cb(tp_task_p tptask, int error, uint32_t eof __unused, r_buf_wbuf_set2(str_hub->r_buf, buf, buf_size, NULL); } /* end recv while */ if (0 != error) { - LOG_ERR(error, "recv()"); + SYSLOG_ERR(LOG_NOTICE, error, "recv()."); if (0 == transfered_size) goto rcv_next; } @@ -983,24 +959,24 @@ str_src_r_buf_alloc(str_hub_p str_hub) { str_hub->r_buf_fd = (uintptr_t)open(filename, (O_CREAT | O_EXCL | O_RDWR), 0600); if ((uintptr_t)-1 == str_hub->r_buf_fd) { error = errno; - LOG_ERR_FMT(error, "open(): %s", filename); + SYSLOG_ERR(LOG_ERR, error, "open(%s).", filename); goto err_out; } if (0 != flock((int)str_hub->r_buf_fd, LOCK_EX)) { - LOG_ERR_FMT(errno, "flock(): %s", filename); + SYSLOG_ERR(LOG_NOTICE, errno, "flock(%s).", filename); } /* Truncate it to the correct size */ if (0 != ftruncate((int)str_hub->r_buf_fd, (off_t)str_hub->shbskt->hub_params.ring_buf_size)) { error = errno; - LOG_ERR_FMT(error, "ftruncate(): %s", filename); + SYSLOG_ERR(LOG_ERR, error, "ftruncate(%s).", filename); goto err_out; } str_hub->r_buf = r_buf_alloc(str_hub->r_buf_fd, str_hub->shbskt->hub_params.ring_buf_size, MPEG2_TS_PKT_SIZE_188); if (NULL == str_hub->r_buf) { error = errno; - LOGD_ERR(error, "r_buf_alloc()"); + SYSLOG_ERR(LOG_ERR, error, "r_buf_alloc()."); goto err_out; } unlink(filename); @@ -1012,7 +988,7 @@ str_src_r_buf_alloc(str_hub_p str_hub) { flock((int)str_hub->r_buf_fd, LOCK_UN); close((int)str_hub->r_buf_fd); unlink(filename); - LOG_ERR(error, "..."); + SYSLOG_ERR_EX(LOG_ERR, error, "..."); return (error); }