From 04210699eeeb4f06b58940b593f1fa6ab265ac02 Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Thu, 30 May 2013 10:12:41 -0700 Subject: [PATCH] log: add ability to override syslog parameters By default, DPDK based applications would only allow logging to syslog as "rte", DAEMON; but for any production application more control is desired to allow using actual application name and overriding the facility. Signed-off-by: Stephen Hemminger Reviewed-by: Vincent Jardin --- lib/librte_eal/common/include/eal_private.h | 2 +- lib/librte_eal/linuxapp/eal/eal.c | 58 ++++++++++++++++++- lib/librte_eal/linuxapp/eal/eal_log.c | 4 +- .../linuxapp/eal/include/eal_internal_cfg.h | 1 + 4 files changed, 61 insertions(+), 4 deletions(-) diff --git a/lib/librte_eal/common/include/eal_private.h b/lib/librte_eal/common/include/eal_private.h index d8c7498150..314ee3091e 100644 --- a/lib/librte_eal/common/include/eal_private.h +++ b/lib/librte_eal/common/include/eal_private.h @@ -114,7 +114,7 @@ int rte_eal_log_early_init(void); * @return * 0 on success, negative on error */ -int rte_eal_log_init(void); +int rte_eal_log_init(const char *id, int facility); /** * Init the default log stream diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c index afa0cce929..c0e50f9b78 100644 --- a/lib/librte_eal/linuxapp/eal/eal.c +++ b/lib/librte_eal/linuxapp/eal/eal.c @@ -39,6 +39,7 @@ #include #include #include +#include #include #include #include @@ -84,6 +85,7 @@ #define OPT_NO_HUGE "no-huge" #define OPT_FILE_PREFIX "file-prefix" #define OPT_SOCKET_MEM "socket-mem" +#define OPT_SYSLOG "syslog" #define RTE_EAL_BLACKLIST_SIZE 0x100 @@ -320,6 +322,7 @@ eal_usage(const char *prgname) " (multiple -b options are allowed)\n" " -m MB : memory to allocate (see also --"OPT_SOCKET_MEM")\n" " -r NUM : force number of memory ranks (don't detect)\n" + " --"OPT_SYSLOG" : set syslog facility\n" " --"OPT_SOCKET_MEM" : memory to allocate on specific \n" " sockets (use comma separated values)\n" " --"OPT_HUGE_DIR" : directory where hugetlbfs is mounted\n" @@ -386,6 +389,45 @@ eal_parse_coremask(const char *coremask) return 0; } +static int +eal_parse_syslog(const char *facility) +{ + int i; + static struct { + const char *name; + int value; + } map[] = { + { "auth", LOG_AUTH }, + { "cron", LOG_CRON }, + { "daemon", LOG_DAEMON }, + { "ftp", LOG_FTP }, + { "kern", LOG_KERN }, + { "lpr", LOG_LPR }, + { "mail", LOG_MAIL }, + { "news", LOG_NEWS }, + { "syslog", LOG_SYSLOG }, + { "user", LOG_USER }, + { "uucp", LOG_UUCP }, + { "local0", LOG_LOCAL0 }, + { "local1", LOG_LOCAL1 }, + { "local2", LOG_LOCAL2 }, + { "local3", LOG_LOCAL3 }, + { "local4", LOG_LOCAL4 }, + { "local5", LOG_LOCAL5 }, + { "local6", LOG_LOCAL6 }, + { "local7", LOG_LOCAL7 }, + { NULL, 0 } + }; + + for (i = 0; map[i].name; i++) { + if (!strcmp(facility, map[i].name)) { + internal_config.syslog_facility = map[i].value; + return 0; + } + } + return -1; +} + static int eal_parse_socket_mem(char *socket_mem) { @@ -516,6 +558,7 @@ eal_parse_args(int argc, char **argv) {OPT_PROC_TYPE, 1, 0, 0}, {OPT_FILE_PREFIX, 1, 0, 0}, {OPT_SOCKET_MEM, 1, 0, 0}, + {OPT_SYSLOG, 1, NULL, 0}, {0, 0, 0, 0} }; @@ -527,6 +570,7 @@ eal_parse_args(int argc, char **argv) internal_config.hugefile_prefix = HUGEFILE_PREFIX_DEFAULT; internal_config.hugepage_dir = NULL; internal_config.force_sockets = 0; + internal_config.syslog_facility = LOG_DAEMON; #ifdef RTE_LIBEAL_USE_HPET internal_config.no_hpet = 0; #else @@ -625,6 +669,14 @@ eal_parse_args(int argc, char **argv) return -1; } } + else if (!strcmp(lgopts[option_index].name, OPT_SYSLOG)) { + if (eal_parse_syslog(optarg) < 0) { + RTE_LOG(ERR, EAL, "invalid parameters for --" + OPT_SYSLOG "\n"); + eal_usage(prgname); + return -1; + } + } break; default: @@ -730,10 +782,14 @@ rte_eal_init(int argc, char **argv) int i, fctret, ret; pthread_t thread_id; static rte_atomic32_t run_once = RTE_ATOMIC32_INIT(0); + const char *logid; if (!rte_atomic32_test_and_set(&run_once)) return -1; + logid = strrchr(argv[0], '/'); + logid = strdup(logid ? logid + 1: argv[0]); + thread_id = pthread_self(); if (rte_eal_log_early_init() < 0) @@ -774,7 +830,7 @@ rte_eal_init(int argc, char **argv) if (rte_eal_tailqs_init() < 0) rte_panic("Cannot init tail queues for objects\n"); - if (rte_eal_log_init() < 0) + if (rte_eal_log_init(logid, internal_config.syslog_facility) < 0) rte_panic("Cannot init logs\n"); if (rte_eal_alarm_init() < 0) diff --git a/lib/librte_eal/linuxapp/eal/eal_log.c b/lib/librte_eal/linuxapp/eal/eal_log.c index 7a79659d4f..afdc66b050 100644 --- a/lib/librte_eal/linuxapp/eal/eal_log.c +++ b/lib/librte_eal/linuxapp/eal/eal_log.c @@ -118,7 +118,7 @@ static cookie_io_functions_t console_log_func = { * once memzones are available. */ int -rte_eal_log_init(void) +rte_eal_log_init(const char *id, int facility) { FILE *log_stream; @@ -126,7 +126,7 @@ rte_eal_log_init(void) if (log_stream == NULL) return -1; - openlog("rte", LOG_NDELAY | LOG_PID, LOG_DAEMON); + openlog(id, LOG_NDELAY | LOG_PID, facility); if (rte_eal_common_log_init(log_stream) < 0) return -1; diff --git a/lib/librte_eal/linuxapp/eal/include/eal_internal_cfg.h b/lib/librte_eal/linuxapp/eal/include/eal_internal_cfg.h index 6e92df8b0a..0e5fc06077 100644 --- a/lib/librte_eal/linuxapp/eal/include/eal_internal_cfg.h +++ b/lib/librte_eal/linuxapp/eal/include/eal_internal_cfg.h @@ -71,6 +71,7 @@ struct internal_config { /* true to try allocating memory on specific sockets */ volatile unsigned force_sockets; volatile uint64_t socket_mem[RTE_MAX_NUMA_NODES]; /**< amount of memory per socket*/ + volatile int syslog_facility; /**< facility passed to openlog() */ const char *hugefile_prefix; /**< the base filename of hugetlbfs files */ const char *hugepage_dir; /**< specific hugetlbfs directory to use */ -- 2.20.1