@@ -18,3 +18,30 @@ FreeBSD-specific EAL parameters
-------------------------------
There are currently no FreeBSD-specific EAL command-line parameters available.
+
+Other options
+~~~~~~~~~~~~~
+
+* ``--syslog <syslog facility>``
+
+ Set syslog facility. Valid syslog facilities are::
+
+ auth
+ cron
+ daemon
+ ftp
+ kern
+ lpr
+ mail
+ news
+ syslog
+ user
+ uucp
+ local0
+ local1
+ local2
+ local3
+ local4
+ local5
+ local6
+ local7
@@ -2,6 +2,7 @@
* Copyright(c) 2010-2014 Intel Corporation
*/
+#include <getopt.h>
#include <stdio.h>
#include <stdint.h>
#include <stdarg.h>
@@ -16,6 +17,8 @@
#include <rte_per_lcore.h>
#include "eal_log.h"
+#include "eal_internal_cfg.h"
+#include "eal_options.h"
#include "eal_private.h"
struct rte_log_dynamic_type {
@@ -223,6 +226,52 @@ log_save_level(uint32_t priority, const char *regex, const char *pattern)
return -1;
}
+
+/* Parse the all arguments looking for --log-level */
+int
+eal_log_level_parse(int argc, char * const argv[])
+{
+ struct internal_config *internal_conf = eal_get_internal_configuration();
+ int option_index, opt;
+ const int old_optind = optind;
+ const int old_optopt = optopt;
+ const int old_opterr = opterr;
+ char *old_optarg = optarg;
+#ifdef RTE_EXEC_ENV_FREEBSD
+ const int old_optreset = optreset;
+ optreset = 1;
+#endif
+
+ optind = 1;
+ opterr = 0;
+
+ while ((opt = getopt_long(argc, argv, eal_short_options,
+ eal_long_options, &option_index)) != EOF) {
+
+ switch (opt) {
+ case OPT_LOG_LEVEL_NUM:
+ if (eal_parse_common_option(opt, optarg, internal_conf) < 0)
+ return -1;
+ break;
+ case '?':
+ /* getopt is not happy, stop right now */
+ goto out;
+ default:
+ continue;
+ }
+ }
+out:
+ /* restore getopt lib */
+ optind = old_optind;
+ optopt = old_optopt;
+ optarg = old_optarg;
+ opterr = old_opterr;
+#ifdef RTE_EXEC_ENV_FREEBSD
+ optreset = old_optreset;
+#endif
+ return 0;
+}
+
int
eal_log_save_regexp(const char *regex, uint32_t level)
{
@@ -13,6 +13,11 @@
*/
int eal_log_init(const char *id, int facility);
+/*
+ * Scan command line args for log settings.
+ */
+int eal_log_level_parse(int argc, char * const argv[]);
+
/*
* Determine where log data is written when no call to rte_openlog_stream.
*/
@@ -52,6 +52,7 @@
#include "eal_hugepages.h"
#include "eal_options.h"
#include "eal_memcfg.h"
+#include "eal_log.h"
#include "eal_trace.h"
#define MEMSIZE_IF_NO_HUGE_PAGE (64ULL * 1024ULL * 1024ULL)
@@ -363,48 +364,6 @@ eal_get_hugepage_mem_size(void)
return (size < SIZE_MAX) ? (size_t)(size) : SIZE_MAX;
}
-/* Parse the arguments for --log-level only */
-static void
-eal_log_level_parse(int argc, char **argv)
-{
- int opt;
- char **argvopt;
- int option_index;
- const int old_optind = optind;
- const int old_optopt = optopt;
- const int old_optreset = optreset;
- char * const old_optarg = optarg;
- struct internal_config *internal_conf =
- eal_get_internal_configuration();
-
- argvopt = argv;
- optind = 1;
- optreset = 1;
-
- while ((opt = getopt_long(argc, argvopt, eal_short_options,
- eal_long_options, &option_index)) != EOF) {
-
- int ret;
-
- /* getopt is not happy, stop right now */
- if (opt == '?')
- break;
-
- ret = (opt == OPT_LOG_LEVEL_NUM) ?
- eal_parse_common_option(opt, optarg, internal_conf) : 0;
-
- /* common parser is not happy */
- if (ret < 0)
- break;
- }
-
- /* restore getopt lib */
- optind = old_optind;
- optopt = old_optopt;
- optreset = old_optreset;
- optarg = old_optarg;
-}
-
/* Parse the argument given in the command line of the application */
static int
eal_parse_args(int argc, char **argv)
@@ -610,7 +569,11 @@ rte_eal_init(int argc, char **argv)
eal_save_args(argc, argv);
/* set log level as early as possible */
- eal_log_level_parse(argc, argv);
+ if (eal_log_level_parse(argc, argv) < 0) {
+ rte_eal_init_alert("invalid log option.");
+ rte_errno = EINVAL;
+ return -1;
+ }
if (rte_eal_cpu_init() < 0) {
rte_eal_init_alert("Cannot detect lcores.");
@@ -759,6 +722,12 @@ rte_eal_init(int argc, char **argv)
#endif
}
+ if (eal_log_init(getprogname(), internal_conf->syslog_facility) < 0) {
+ rte_eal_init_alert("Cannot init logging.");
+ rte_errno = ENOMEM;
+ return -1;
+ }
+
/* in secondary processes, memory init may allocate additional fbarrays
* not present in primary processes, so to avoid any potential issues,
* initialize memzones first.
@@ -546,45 +546,6 @@ eal_parse_vfio_vf_token(const char *vf_token)
return -1;
}
-/* Parse the arguments for --log-level only */
-static void
-eal_log_level_parse(int argc, char **argv)
-{
- int opt;
- char **argvopt;
- int option_index;
- const int old_optind = optind;
- const int old_optopt = optopt;
- char * const old_optarg = optarg;
- struct internal_config *internal_conf =
- eal_get_internal_configuration();
-
- argvopt = argv;
- optind = 1;
-
- while ((opt = getopt_long(argc, argvopt, eal_short_options,
- eal_long_options, &option_index)) != EOF) {
-
- int ret;
-
- /* getopt is not happy, stop right now */
- if (opt == '?')
- break;
-
- ret = (opt == OPT_LOG_LEVEL_NUM) ?
- eal_parse_common_option(opt, optarg, internal_conf) : 0;
-
- /* common parser is not happy */
- if (ret < 0)
- break;
- }
-
- /* restore getopt lib */
- optind = old_optind;
- optopt = old_optopt;
- optarg = old_optarg;
-}
-
static int
eal_parse_huge_worker_stack(const char *arg)
{
@@ -993,7 +954,12 @@ rte_eal_init(int argc, char **argv)
eal_reset_internal_config(internal_conf);
/* set log level as early as possible */
- eal_log_level_parse(argc, argv);
+ if (eal_log_level_parse(argc, argv) < 0) {
+ rte_eal_init_alert("invalid log option.");
+ rte_errno = EINVAL;
+ __atomic_store_n(&run_once, 0, __ATOMIC_RELAXED);
+ return -1;
+ }
/* clone argv to report out later in telemetry */
eal_save_args(argc, argv);
@@ -11,7 +11,6 @@ sources += files(
'eal_hugepage_info.c',
'eal_interrupts.c',
'eal_lcore.c',
- 'eal_log.c',
'eal_memalloc.c',
'eal_memory.c',
'eal_thread.c',
similarity index 76%
rename from lib/eal/linux/eal_log.c
rename to lib/eal/unix/eal_log.c
@@ -9,6 +9,8 @@
#include <rte_log.h>
#include "eal_log.h"
+#include "eal_internal_cfg.h"
+#include "eal_private.h"
/*
* default log function
@@ -25,6 +27,15 @@ console_log_write(__rte_unused void *c, const char *buf, size_t size)
/* Syslog error levels are from 0 to 7, so subtract 1 to convert */
syslog(rte_log_cur_msg_loglevel() - 1, "%.*s", (int)size, buf);
+#ifdef RTE_EXEC_ENV_LINUX
+ /* Handle glibc quirk: write function should return the number of bytes
+ * copied from buf, or 0 on error. (The function must not return a negative value.)
+ * FreeBSD expects that write function behaves like write(2).
+ */
+ if (ret < 0)
+ ret = 0;
+#endif
+
return ret;
}
@@ -6,6 +6,7 @@ sources += files(
'eal_file.c',
'eal_filesystem.c',
'eal_firmware.c',
+ 'eal_log.c',
'eal_unix_memory.c',
'eal_unix_thread.c',
'eal_unix_timer.c',
@@ -96,41 +96,6 @@ eal_usage(const char *prgname)
}
}
-/* Parse the arguments for --log-level only */
-static void
-eal_log_level_parse(int argc, char **argv)
-{
- int opt;
- char **argvopt;
- int option_index;
- struct internal_config *internal_conf =
- eal_get_internal_configuration();
-
- argvopt = argv;
-
- eal_reset_internal_config(internal_conf);
-
- while ((opt = getopt_long(argc, argvopt, eal_short_options,
- eal_long_options, &option_index)) != EOF) {
-
- int ret;
-
- /* getopt is not happy, stop right now */
- if (opt == '?')
- break;
-
- ret = (opt == OPT_LOG_LEVEL_NUM) ?
- eal_parse_common_option(opt, optarg,
- internal_conf) : 0;
-
- /* common parser is not happy */
- if (ret < 0)
- break;
- }
-
- optind = 0; /* reset getopt lib */
-}
-
/* Parse the argument given in the command line of the application */
static int
eal_parse_args(int argc, char **argv)
@@ -143,6 +108,7 @@ eal_parse_args(int argc, char **argv)
eal_get_internal_configuration();
argvopt = argv;
+ opterr = 1;
while ((opt = getopt_long(argc, argvopt, eal_short_options,
eal_long_options, &option_index)) != EOF) {