log: add ability to override syslog parameters
authorStephen Hemminger <shemminger@vyatta.com>
Thu, 30 May 2013 17:12:41 +0000 (10:12 -0700)
committerThomas Monjalon <thomas.monjalon@6wind.com>
Mon, 16 Sep 2013 13:34:52 +0000 (15:34 +0200)
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 <shemminger@vyatta.com>
Reviewed-by: Vincent Jardin <vincent.jardin@6wind.com>
lib/librte_eal/common/include/eal_private.h
lib/librte_eal/linuxapp/eal/eal.c
lib/librte_eal/linuxapp/eal/eal_log.c
lib/librte_eal/linuxapp/eal/include/eal_internal_cfg.h

index d8c7498..314ee30 100644 (file)
@@ -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
index afa0cce..c0e50f9 100644 (file)
@@ -39,6 +39,7 @@
 #include <stdarg.h>
 #include <unistd.h>
 #include <pthread.h>
+#include <syslog.h>
 #include <getopt.h>
 #include <sys/file.h>
 #include <stddef.h>
@@ -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)
index 7a79659..afdc66b 100644 (file)
@@ -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;
index 6e92df8..0e5fc06 100644 (file)
@@ -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 */