44 #include <sys/ucontext.h> 46 #include <sys/types.h> 50 #include <sys/resource.h> 54 #define UNIX_CLI_DEFAULT_PAGER_LIMIT 100000 57 #define UNIX_CLI_DEFAULT_HISTORY 50 59 char *vlib_default_runtime_dir __attribute__ ((weak));
60 char *vlib_default_runtime_dir =
"vlib";
80 sa.sa_handler = SIG_DFL;
82 sigemptyset (&sa.sa_mask);
83 return sigaction (sig, &sa, 0);
90 static u8 *syslog_msg = 0;
91 static int last_signum = 0;
92 static uword last_faulting_address = 0;
100 last_signum = signum;
101 last_faulting_address = (
uword) si->si_addr;
103 syslog_msg =
format (syslog_msg,
"received signal %U, PC %U",
106 if (signum == SIGSEGV)
107 syslog_msg =
format (syslog_msg,
", faulting address %p", si->si_addr);
118 syslog (LOG_ERR | LOG_DAEMON,
"received SIGTERM, exiting...");
122 syslog (LOG_ERR | LOG_DAEMON,
"IGNORE early SIGTERM...");
147 syslog (LOG_ERR | LOG_DAEMON,
"%s", syslog_msg);
153 for (i = 0; i < n_callers; i++)
158 format (syslog_msg,
"#%-2d 0x%016lx %U%c", i, callers[i],
161 syslog (LOG_ERR | LOG_DAEMON,
"%s", syslog_msg);
183 for (i = 1; i < 32; i++)
187 sa.sa_flags = SA_SIGINFO;
201 sa.sa_sigaction = (
void *) SIG_IGN;
209 if (sigaction (i, &sa, 0) < 0)
228 char save = msg[msg_len - 1];
231 msg[msg_len - 1] = 0;
233 syslog (LOG_ERR | LOG_DAEMON,
"%s", msg);
235 msg[msg_len - 1] = save;
256 save = msg[msg_len - 1];
257 msg[msg_len - 1] = 0;
259 syslog (LOG_ERR | LOG_DAEMON,
"%s", msg);
261 msg[msg_len - 1] = save;
285 fd = open (fn, O_RDONLY);
292 if (fstat (fd, &s) < 0)
300 if (!(S_ISREG (s.st_mode) || S_ISLNK (s.st_mode)))
310 n = read (fd, buf + l, 4096);
313 _vec_len (buf) = l + n;
323 lv =
format (lv,
"%U: ***** Startup Config *****\n%v",
328 int rv __attribute__ ((unused)) =
332 lv =
format (lv,
"%U: ***** End Startup Config *****\n",
336 int rv __attribute__ ((unused)) =
358 .name =
"startup-config-process",
377 if (
unformat (input,
"interactive"))
379 else if (
unformat (input,
"nodaemon"))
381 else if (
unformat (input,
"cli-prompt %s", &cli_prompt))
388 else if (
unformat (input,
"cli-line-mode"))
390 else if (
unformat (input,
"cli-no-banner"))
392 else if (
unformat (input,
"cli-no-pager"))
396 else if (
unformat (input,
"cli-pager-buffer-limit %d",
402 else if (
unformat (input,
"coredump-size"))
404 uword coredump_size = 0;
407 coredump_size = RLIM_INFINITY;
413 "invalid coredump-size parameter `%U'",
416 const struct rlimit new_limit = { coredump_size, coredump_size };
417 if (0 != setrlimit (RLIMIT_CORE, &new_limit))
422 else if (
unformat (input,
"full-coredump"))
426 fd = open (
"/proc/self/coredump_filter", O_WRONLY);
429 if (write (fd,
"0x6f\n", 5) != 5)
436 else if (
unformat (input,
"startup-config %s",
444 O_CREAT | O_WRONLY | O_APPEND, 0644);
453 lv =
format (0,
"%U: ***** Start: PID %d *****\n",
458 int rv __attribute__ ((unused)) =
466 if (setegid (gid) == -1)
478 uid_t uid = geteuid ();
481 vlib_default_runtime_dir, 0);
484 vlib_default_runtime_dir, 0);
498 if (((pidfd = open ((
char *) um->
pidfile,
499 O_CREAT | O_WRONLY | O_TRUNC, 0644)) < 0))
507 openlog (vm->
name, LOG_CONS | LOG_PERROR | LOG_PID, LOG_DAEMON);
518 u8 *lv =
format (0,
"%d", getpid ());
634 if (mprotect (vlib_thread_stacks[thread_index],
637 return vlib_thread_stacks[thread_index];
683 __os_thread_index = 0;
687 (
void *) (vlib_thread_stacks[0] +
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
int vlib_unix_main(int argc, char *argv[])
vlib_main_t vlib_global_main
void vlib_cli_input(vlib_main_t *vm, unformat_input_t *input, vlib_cli_output_function_t *function, uword function_arg)
volatile int unix_config_complete
u32 cli_pager_buffer_limit
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
void vlib_unix_cli_set_prompt(char *prompt)
Set the CLI prompt.
uword clib_backtrace(uword *callers, uword max_callers, uword n_frames_to_skip)
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
static clib_error_t * unix_main_init(vlib_main_t *vm)
clib_error_t * vlib_plugin_config(vlib_main_t *vm, unformat_input_t *input)
static clib_error_t * unix_exit(vlib_main_t *vm)
static void unix_signal_handler(int signum, siginfo_t *si, ucontext_t *uc)
void clib_error_register_handler(clib_error_handler_func_t func, void *arg)
clib_socket_t cli_listen_socket
static void unix_error_handler(void *arg, u8 *msg, int msg_len)
#define vec_alloc(V, N)
Allocate space for N more elements (no header, unspecified alignment)
#define UNIX_FLAG_NODAEMON
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
static uword vlib_process_suspend(vlib_main_t *vm, f64 dt)
Suspend a vlib cooperative multi-tasking thread for a period of time.
static int unsetup_signal_handlers(int sig)
#define VLIB_INIT_FUNCTION(x)
#define clib_error_return(e, args...)
clib_file_main_t file_main
#define vec_resize(V, N)
Resize a vector (no header, unspecified alignment) Add N elements to end of given vector V...
#define vlib_call_init_function(vm, x)
int vlib_plugin_early_init(vlib_main_t *vm)
uword clib_mem_get_page_size(void)
#define clib_error_return_unix(e, args...)
u8 * startup_config_filename
uword * init_functions_called
#define VLIB_EARLY_CONFIG_FUNCTION(x, n,...)
#define VLIB_REGISTER_NODE(x,...)
void vlib_unix_error_report(vlib_main_t *vm, clib_error_t *error)
#define vec_free(V)
Free vector's memory (no header).
#define VLIB_MAIN_LOOP_EXIT_FUNCTION(x)
#define clib_warning(format, args...)
void clib_elf_main_init(char *exec_path)
#define UNIX_CLI_DEFAULT_PAGER_LIMIT
Default CLI pager limit is not configured in startup.conf.
static void * clib_mem_get_heap(void)
#define hash_create(elts, value_bytes)
static uword thread0(uword arg)
#define UNIX_FLAG_INTERACTIVE
#define clib_error_report(e)
int vlib_main(vlib_main_t *volatile vm, unformat_input_t *input)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
#define UNIX_CLI_DEFAULT_HISTORY
Default CLI history depth if not configured in startup.conf.
clib_error_t * vlib_call_all_config_functions(vlib_main_t *vm, unformat_input_t *input, int is_early)
#define clib_unix_warning(format, args...)
#define VLIB_THREAD_STACK_SIZE
format_function_t format_clib_elf_symbol_with_address
static clib_error_t * unix_config(vlib_main_t *vm, unformat_input_t *input)
clib_error_t * vlib_unix_validate_runtime_file(unix_main_t *um, const char *path, u8 **full_path)
static void * clib_mem_alloc_aligned(uword size, uword align)
uword clib_calljmp(uword(*func)(uword func_arg), uword func_arg, void *stack)
volatile u32 main_loop_exit_now
static uword startup_config_process(vlib_main_t *vm, vlib_node_runtime_t *rt, vlib_frame_t *f)
static clib_error_t * setup_signal_handlers(unix_main_t *um)
u8 * vlib_thread_stack_init(uword thread_index)