log: add ability to override syslog parameters
[dpdk.git] / lib / librte_eal / linuxapp / eal / eal.c
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)