#define UNIX_CLI_DEFAULT_HISTORY 50
char *vlib_default_runtime_dir __attribute__ ((weak));
-char *vlib_default_runtime_dir = "/run/vlib";
+char *vlib_default_runtime_dir = "vlib";
unix_main_t unix_main;
+clib_file_main_t file_main;
static clib_error_t *
unix_main_init (vlib_main_t * vm)
static void
unix_signal_handler (int signum, siginfo_t * si, ucontext_t * uc)
{
- uword fatal;
+ uword fatal = 0;
u8 *msg = 0;
msg = format (msg, "received signal %U, PC %U",
if (unix_main.vlib_main->main_loop_exit_set)
{
syslog (LOG_ERR | LOG_DAEMON, "received SIGTERM, exiting...");
-
- clib_longjmp (&unix_main.vlib_main->main_loop_exit,
- VLIB_MAIN_LOOP_EXIT_CLI);
+ unix_main.vlib_main->main_loop_exit_now = 1;
}
+ break;
/* fall through */
case SIGQUIT:
case SIGINT:
unix_main_t *um = &unix_main;
clib_error_t *error = 0;
gid_t gid;
+ int pidfd = -1;
/* Defaults */
um->cli_pager_buffer_limit = UNIX_CLI_DEFAULT_PAGER_LIMIT;
if (setegid (gid) == -1)
return clib_error_return_unix (0, "setegid");
}
+ else if (unformat (input, "pidfile %s", &um->pidfile))
+ ;
else
return clib_error_return (0, "unknown input `%U'",
format_unformat_error, input);
}
+ if (um->runtime_dir == 0)
+ {
+ uid_t uid = geteuid ();
+ if (uid == 00)
+ um->runtime_dir = format (0, "/run/%s%c",
+ vlib_default_runtime_dir, 0);
+ else
+ um->runtime_dir = format (0, "/run/user/%u/%s%c", uid,
+ vlib_default_runtime_dir, 0);
+ }
+
error = setup_signal_handlers (um);
if (error)
return error;
+ if (um->pidfile)
+ {
+ if ((error = vlib_unix_validate_runtime_file (um,
+ (char *) um->pidfile,
+ &um->pidfile)))
+ return error;
+
+ if (((pidfd = open ((char *) um->pidfile,
+ O_CREAT | O_WRONLY | O_TRUNC, 0644)) < 0))
+ {
+ return clib_error_return_unix (0, "open");
+ }
+ }
+
if (!(um->flags & UNIX_FLAG_INTERACTIVE))
{
openlog (vm->name, LOG_CONS | LOG_PERROR | LOG_PID, LOG_DAEMON);
0) < 0)
clib_error_return (0, "daemon () fails");
}
- um->unix_config_complete = 1;
- if (um->runtime_dir == 0)
- um->runtime_dir = format (0, "%s%c", vlib_default_runtime_dir, 0);
+ if (pidfd >= 0)
+ {
+ u8 *lv = format (0, "%d", getpid ());
+ if (write (pidfd, (char *) lv, vec_len (lv)) != vec_len (lv))
+ {
+ vec_free (lv);
+ close (pidfd);
+ return clib_error_return_unix (0, "write");
+ }
+ vec_free (lv);
+ close (pidfd);
+ }
+
+ um->unix_config_complete = 1;
return 0;
}
* Very useful in situations where folks don't remember or can't be bothered
* to include CLI commands in bug reports.
*
+ * @cfgcmd{pidfile, <filename>}
+ * Writes the pid of the main thread in @c filename.
+ *
* @cfgcmd{full-coredump}
* Ask the Linux kernel to dump all memory-mapped address regions, instead
* of just text+data+bss.
vlib_thread_stack_init (0);
__os_thread_index = 0;
+ vm->thread_index = 0;
i = clib_calljmp (thread0, (uword) vm,
(void *) (vlib_thread_stacks[0] +