Add -q flag.

If specified Kore will run quietly and only log important messages.
This commit is contained in:
Joris Vink 2018-11-15 16:01:37 +01:00
parent cb482d8e8f
commit baafa4897e
5 changed files with 56 additions and 24 deletions

View File

@ -506,6 +506,7 @@ extern char *config_file;
extern pid_t kore_pid;
extern int foreground;
extern int kore_quiet;
extern int kore_debug;
extern int skip_chroot;
extern int skip_runas;

View File

@ -238,8 +238,11 @@ kore_parse_config(void)
if (getcwd(path, sizeof(path)) == NULL)
fatal("getcwd: %s", errno_s);
kore_root_path = kore_strdup(path);
kore_log(LOG_NOTICE,
"privsep: no root path set, using working directory");
if (!kore_quiet) {
kore_log(LOG_NOTICE, "privsep: no root path set, "
"using working directory");
}
}
if (getuid() != 0 && skip_chroot == 0) {
@ -255,12 +258,15 @@ kore_parse_config(void)
}
if (skip_runas) {
kore_log(LOG_WARNING, "privsep: will not change user");
if (!kore_quiet)
kore_log(LOG_WARNING, "privsep: will not change user");
} else {
#if !defined(KORE_NO_TLS)
if (keymgr_runas_user == NULL) {
kore_log(LOG_NOTICE,
"privsep: no keymgr_runas set, using 'runas` user");
if (!kore_quiet) {
kore_log(LOG_NOTICE, "privsep: no keymgr_runas "
"set, using 'runas` user");
}
keymgr_runas_user = kore_strdup(kore_runas_user);
}
#endif
@ -268,13 +274,15 @@ kore_parse_config(void)
#if !defined(KORE_NO_TLS)
if (keymgr_root_path == NULL) {
kore_log(LOG_NOTICE,
"privsep: no keymgr_root set, using 'root` directory");
if (!kore_quiet) {
kore_log(LOG_NOTICE, "privsep: no keymgr_root set, "
"using 'root` directory");
}
keymgr_root_path = kore_strdup(kore_root_path);
}
#endif
if (skip_chroot)
if (skip_chroot && !kore_quiet)
kore_log(LOG_WARNING, "privsep: will not chroot");
}

View File

@ -43,6 +43,7 @@ pid_t kore_pid = -1;
u_int16_t cpu_count = 1;
int foreground = 0;
int kore_debug = 0;
int kore_quiet = 0;
int skip_runas = 0;
int skip_chroot = 0;
u_int8_t worker_count = 0;
@ -76,6 +77,7 @@ usage(void)
fprintf(stderr, "\t-f\tstart in foreground\n");
fprintf(stderr, "\t-h\tthis help text\n");
fprintf(stderr, "\t-n\tdo not chroot\n");
fprintf(stderr, "\t-q\tonly log errors\n");
fprintf(stderr, "\t-r\tdo not drop privileges\n");
fprintf(stderr, "\t-v\tdisplay %s build information\n", __progname);
@ -126,9 +128,9 @@ main(int argc, char *argv[])
flags = 0;
#if !defined(KORE_SINGLE_BINARY)
while ((ch = getopt(argc, argv, "c:dfhnrv")) != -1) {
while ((ch = getopt(argc, argv, "c:dfhnqrv")) != -1) {
#else
while ((ch = getopt(argc, argv, "dfhnrv")) != -1) {
while ((ch = getopt(argc, argv, "dfhnqrv")) != -1) {
#endif
flags++;
switch (ch) {
@ -151,6 +153,9 @@ main(int argc, char *argv[])
case 'n':
skip_chroot = 1;
break;
case 'q':
kore_quiet = 1;
break;
case 'r':
skip_runas = 1;
break;
@ -223,7 +228,9 @@ main(int argc, char *argv[])
kore_signal_setup();
kore_server_start(argc, argv);
kore_log(LOG_NOTICE, "server shutting down");
if (!kore_quiet)
kore_log(LOG_NOTICE, "server shutting down");
kore_worker_shutdown();
rcall = kore_runtime_getcall("kore_parent_teardown");
@ -236,7 +243,9 @@ main(int argc, char *argv[])
kore_log(LOG_NOTICE, "failed to remove pidfile (%s)", errno_s);
kore_listener_cleanup();
kore_log(LOG_NOTICE, "goodbye");
if (!kore_quiet)
kore_log(LOG_NOTICE, "goodbye");
#if defined(KORE_USE_PYTHON)
kore_python_cleanup();
@ -337,7 +346,7 @@ kore_server_bind(const char *ip, const char *port, const char *ccb)
return (KORE_RESULT_ERROR);
}
if (foreground) {
if (foreground && !kore_quiet) {
#if !defined(KORE_NO_TLS)
kore_log(LOG_NOTICE, "running on https://%s:%s", ip, port);
#else
@ -387,7 +396,7 @@ kore_server_bind_unix(const char *path, const char *ccb)
return (KORE_RESULT_ERROR);
}
if (foreground)
if (foreground && !kore_quiet)
kore_log(LOG_NOTICE, "running on %s", path);
return (KORE_RESULT_OK);
@ -606,19 +615,22 @@ kore_server_start(int argc, char *argv[])
kore_pid = getpid();
kore_write_kore_pid();
kore_log(LOG_NOTICE, "%s is starting up", __progname);
if (!kore_quiet) {
kore_log(LOG_NOTICE, "%s is starting up", __progname);
#if defined(KORE_USE_PGSQL)
kore_log(LOG_NOTICE, "pgsql built-in enabled");
kore_log(LOG_NOTICE, "pgsql built-in enabled");
#endif
#if defined(KORE_USE_TASKS)
kore_log(LOG_NOTICE, "tasks built-in enabled");
kore_log(LOG_NOTICE, "tasks built-in enabled");
#endif
#if defined(KORE_USE_JSONRPC)
kore_log(LOG_NOTICE, "jsonrpc built-in enabled");
kore_log(LOG_NOTICE, "jsonrpc built-in enabled");
#endif
#if defined(KORE_USE_PYTHON)
kore_log(LOG_NOTICE, "python built-in enabled");
kore_log(LOG_NOTICE, "python built-in enabled");
#endif
}
#if !defined(KORE_SINGLE_BINARY)
rcall = kore_runtime_getcall("kore_parent_configure");
if (rcall != NULL) {

View File

@ -207,7 +207,9 @@ msg_recv_data(struct netbuf *nb)
static void
msg_disconnected_parent(struct connection *c)
{
kore_log(LOG_ERR, "parent gone, shutting down");
if (!kore_quiet)
kore_log(LOG_ERR, "parent gone, shutting down");
if (kill(worker->pid, SIGQUIT) == -1)
kore_log(LOG_ERR, "failed to send SIGQUIT: %s", errno_s);
}

View File

@ -185,7 +185,11 @@ kore_worker_shutdown(void)
struct kore_worker *kw;
u_int16_t id, done;
kore_log(LOG_NOTICE, "waiting for workers to drain and shutdown");
if (!kore_quiet) {
kore_log(LOG_NOTICE,
"waiting for workers to drain and shutdown");
}
for (;;) {
done = 0;
for (id = 0; id < worker_count; id++) {
@ -367,7 +371,10 @@ kore_worker_entry(struct kore_worker *kw)
if (nlisteners == 0)
worker_no_lock = 1;
kore_log(LOG_NOTICE, "worker %d started (cpu#%d)", kw->id, kw->cpu);
if (!kore_quiet) {
kore_log(LOG_NOTICE,
"worker %d started (cpu#%d)", kw->id, kw->cpu);
}
rcall = kore_runtime_getcall("kore_worker_configure");
if (rcall != NULL) {
@ -524,8 +531,10 @@ kore_worker_wait(int final)
if (kw->pid != pid)
continue;
kore_log(LOG_NOTICE, "worker %d (%d)-> status %d",
kw->id, pid, status);
if (final == 0 || (final == 1 && !kore_quiet)) {
kore_log(LOG_NOTICE, "worker %d (%d)-> status %d",
kw->id, pid, status);
}
if (final) {
kw->pid = 0;