Code Review
/
vpp.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
review
|
tree
raw
|
inline
| side by side
vlib: fix startup-config-process stack overflow
[vpp.git]
/
src
/
vlib
/
unix
/
main.c
diff --git
a/src/vlib/unix/main.c
b/src/vlib/unix/main.c
index
4d6519e
..
08e5937
100755
(executable)
--- a/
src/vlib/unix/main.c
+++ b/
src/vlib/unix/main.c
@@
-67,10
+67,15
@@
unix_main_init (vlib_main_t * vm)
{
unix_main_t *um = &unix_main;
um->vlib_main = vm;
{
unix_main_t *um = &unix_main;
um->vlib_main = vm;
- return
vlib_call_init_function (vm, unix_input_init)
;
+ return
0
;
}
}
-VLIB_INIT_FUNCTION (unix_main_init);
+/* *INDENT-OFF* */
+VLIB_INIT_FUNCTION (unix_main_init) =
+{
+ .runs_before = VLIB_INITS ("unix_input_init"),
+};
+/* *INDENT-ON* */
static int
unsetup_signal_handlers (int sig)
static int
unsetup_signal_handlers (int sig)
@@
-86,14
+91,20
@@
unsetup_signal_handlers (int sig)
/* allocate this buffer from mheap when setting up the signal handler.
dangerous to vec_resize it when crashing, mheap itself might have been
/* allocate this buffer from mheap when setting up the signal handler.
dangerous to vec_resize it when crashing, mheap itself might have been
- corrupt
t
ed already */
+ corrupted already */
static u8 *syslog_msg = 0;
static u8 *syslog_msg = 0;
+static int last_signum = 0;
+static uword last_faulting_address = 0;
static void
unix_signal_handler (int signum, siginfo_t * si, ucontext_t * uc)
{
uword fatal = 0;
static void
unix_signal_handler (int signum, siginfo_t * si, ucontext_t * uc)
{
uword fatal = 0;
+ /* These come in handy when looking at core files from optimized images */
+ last_signum = signum;
+ last_faulting_address = (uword) si->si_addr;
+
syslog_msg = format (syslog_msg, "received signal %U, PC %U",
format_signal, signum, format_ucontext_pc, uc);
syslog_msg = format (syslog_msg, "received signal %U, PC %U",
format_signal, signum, format_ucontext_pc, uc);
@@
-104,11
+115,16
@@
unix_signal_handler (int signum, siginfo_t * si, ucontext_t * uc)
{
/* these (caught) signals cause the application to exit */
case SIGTERM:
{
/* these (caught) signals cause the application to exit */
case SIGTERM:
- if (unix_main.vlib_main->main_loop_exit_set)
+ /*
+ * Ignore SIGTERM if it's sent before we're ready.
+ */
+ if (unix_main.vlib_main && unix_main.vlib_main->main_loop_exit_set)
{
syslog (LOG_ERR | LOG_DAEMON, "received SIGTERM, exiting...");
unix_main.vlib_main->main_loop_exit_now = 1;
}
{
syslog (LOG_ERR | LOG_DAEMON, "received SIGTERM, exiting...");
unix_main.vlib_main->main_loop_exit_now = 1;
}
+ else
+ syslog (LOG_ERR | LOG_DAEMON, "IGNORE early SIGTERM...");
break;
/* fall through */
case SIGQUIT:
break;
/* fall through */
case SIGQUIT:
@@
-128,6
+144,17
@@
unix_signal_handler (int signum, siginfo_t * si, ucontext_t * uc)
break;
}
break;
}
+#ifdef CLIB_GCOV
+ /*
+ * Test framework sends SIGTERM, so we need to flush the
+ * code coverage stats here.
+ */
+ {
+ void __gcov_flush (void);
+ __gcov_flush ();
+ }
+#endif
+
/* Null terminate. */
vec_add1 (syslog_msg, 0);
/* Null terminate. */
vec_add1 (syslog_msg, 0);
@@
-150,7
+177,7
@@
unix_signal_handler (int signum, siginfo_t * si, ucontext_t * uc)
syslog (LOG_ERR | LOG_DAEMON, "%s", syslog_msg);
}
syslog (LOG_ERR | LOG_DAEMON, "%s", syslog_msg);
}
- /* have to remove SIGABRT to avoid recusive - os_exit calling abort() */
+ /* have to remove SIGABRT to avoid recu
r
sive - os_exit calling abort() */
unsetup_signal_handlers (SIGABRT);
os_exit (1);
unsetup_signal_handlers (SIGABRT);
os_exit (1);
@@
-345,6
+372,7
@@
VLIB_REGISTER_NODE (startup_config_node,static) = {
.function = startup_config_process,
.type = VLIB_NODE_TYPE_PROCESS,
.name = "startup-config-process",
.function = startup_config_process,
.type = VLIB_NODE_TYPE_PROCESS,
.name = "startup-config-process",
+ .process_log2_n_stack_bytes = 18,
};
/* *INDENT-ON* */
};
/* *INDENT-ON* */
@@
-473,6
+501,11
@@
unix_config (vlib_main_t * vm, unformat_input_t * input)
vlib_default_runtime_dir, 0);
}
vlib_default_runtime_dir, 0);
}
+ /* Ensure the runtime directory is created */
+ error = vlib_unix_recursive_mkdir ((char *) um->runtime_dir);
+ if (error)
+ return error;
+
error = setup_signal_handlers (um);
if (error)
return error;
error = setup_signal_handlers (um);
if (error)
return error;
@@
-553,10
+586,11
@@
unix_config (vlib_main_t * vm, unformat_input_t * input)
*
* @cfgcmd{runtime-dir}
* Define directory where VPP is going to store all runtime files.
*
* @cfgcmd{runtime-dir}
* Define directory where VPP is going to store all runtime files.
- * Default is /run/vpp.
+ * Default is /run/vpp when running as root, /run/user/<UID>/vpp if running as
+ * an unprivileged user.
*
* @cfgcmd{cli-listen, <address:port>}
*
* @cfgcmd{cli-listen, <address:port>}
- * Bind the CLI to listen at the address and port given. @clocalhost
+ * Bind the CLI to listen at the address and port given. @c
localhost
* on TCP port @c 5002, given as <tt>cli-listen localhost:5002</tt>,
* is typical.
*
* on TCP port @c 5002, given as <tt>cli-listen localhost:5002</tt>,
* is typical.
*
@@
-568,7
+602,7
@@
unix_config (vlib_main_t * vm, unformat_input_t * input)
* Configure the CLI prompt to be @c string.
*
* @cfgcmd{cli-history-limit, <nn>}
* Configure the CLI prompt to be @c string.
*
* @cfgcmd{cli-history-limit, <nn>}
- * Limit comm
m
and history to @c nn lines. A value of @c 0
+ * Limit command history to @c nn lines. A value of @c 0
* disables command history. Default value: @c 50
*
* @cfgcmd{cli-no-banner}
* disables command history. Default value: @c 50
*
* @cfgcmd{cli-no-banner}
@@
-580,6
+614,12
@@
unix_config (vlib_main_t * vm, unformat_input_t * input)
* @cfgcmd{cli-pager-buffer-limit, <nn>}
* Limit pager buffer to @c nn lines of output.
* A value of @c 0 disables the pager. Default value: @c 100000
* @cfgcmd{cli-pager-buffer-limit, <nn>}
* Limit pager buffer to @c nn lines of output.
* A value of @c 0 disables the pager. Default value: @c 100000
+ *
+ * @cfgcmd{gid, <nn>}
+ * Set the effective gid under which the vpp process is to run.
+ *
+ * @cfgcmd{poll-sleep-usec, <nn>}
+ * Set a fixed poll sleep interval between main loop polls.
?*/
VLIB_EARLY_CONFIG_FUNCTION (unix_config, "unix");
?*/
VLIB_EARLY_CONFIG_FUNCTION (unix_config, "unix");
@@
-612,9
+652,9
@@
thread0 (uword arg)
u8 *
vlib_thread_stack_init (uword thread_index)
{
u8 *
vlib_thread_stack_init (uword thread_index)
{
-
vec_validate (vlib_thread_stacks, thread_index
);
+
ASSERT (thread_index < vec_len (vlib_thread_stacks)
);
vlib_thread_stacks[thread_index] = clib_mem_alloc_aligned
vlib_thread_stacks[thread_index] = clib_mem_alloc_aligned
- (VLIB_THREAD_STACK_SIZE,
VLIB_THREAD_STACK_SIZE
);
+ (VLIB_THREAD_STACK_SIZE,
clib_mem_get_page_size ()
);
/*
* Disallow writes to the bottom page of the stack, to
/*
* Disallow writes to the bottom page of the stack, to
@@
-667,12
+707,11
@@
vlib_unix_main (int argc, char *argv[])
/* always load symbols, for signal handler and mheap memory get/put backtrace */
clib_elf_main_init (vm->name);
/* always load symbols, for signal handler and mheap memory get/put backtrace */
clib_elf_main_init (vm->name);
+ vec_validate (vlib_thread_stacks, 0);
vlib_thread_stack_init (0);
__os_thread_index = 0;
vm->thread_index = 0;
vlib_thread_stack_init (0);
__os_thread_index = 0;
vm->thread_index = 0;
- vm->cpu_index = clib_get_current_cpu_index ();
- vm->numa_node = clib_get_current_numa_node ();
i = clib_calljmp (thread0, (uword) vm,
(void *) (vlib_thread_stacks[0] +
i = clib_calljmp (thread0, (uword) vm,
(void *) (vlib_thread_stacks[0] +