use syslog() for informative messages from all parts of kore.

This commit is contained in:
Joris Vink 2013-06-04 23:24:47 +02:00
parent 49b77d3b0e
commit 90e1b3a7da
3 changed files with 32 additions and 3 deletions

View File

@ -138,6 +138,7 @@ extern char *kore_pidfile;
extern u_int8_t worker_count;
extern pid_t mypid;
void kore_log_init(void);
void *kore_malloc(size_t);
void *kore_calloc(size_t, size_t);
void *kore_realloc(void *, size_t);
@ -145,6 +146,7 @@ time_t kore_date_to_time(char *);
char *kore_time_to_date(time_t);
char *kore_strdup(const char *);
void kore_parse_config(const char *);
void kore_log(int, const char *, ...);
void kore_strlcpy(char *, const char *, size_t);
void kore_server_disconnect(struct connection *);
int kore_split_string(char *, char *, char **, size_t);

View File

@ -37,6 +37,7 @@
#include <stdlib.h>
#include <string.h>
#include <sched.h>
#include <syslog.h>
#include <unistd.h>
#include <time.h>
#include <regex.h>
@ -90,6 +91,7 @@ main(int argc, char *argv[])
{
struct kore_worker *kw, *next;
kore_log_init();
mypid = getpid();
if (argc != 2)
@ -127,7 +129,9 @@ main(int argc, char *argv[])
if (chdir("/") == -1)
fatal("cannot chdir(): %s", errno_s);
kore_log(LOG_NOTICE, "kore is starting up");
kore_worker_init();
if (prctl(PR_SET_NAME, "kore [main]"))
kore_debug("cannot set process title");
@ -160,11 +164,11 @@ main(int argc, char *argv[])
kore_debug("kill(%d, SIGINT): %s", kw->pid, errno_s);
}
kore_debug("waiting for workers to drain and finish");
kore_log(LOG_NOTICE, "waiting for workers to drain and finish");
while (!TAILQ_EMPTY(&kore_workers))
kore_worker_wait(1);
kore_debug("server shutting down");
kore_log(LOG_NOTICE, "server shutting down");
unlink(kore_pidfile);
close(server.fd);
@ -576,6 +580,9 @@ kore_worker_entry(struct kore_worker *kw)
quit = 0;
kore_event(server.fd, EPOLLIN, &server);
events = kore_calloc(EPOLL_EVENTS, sizeof(struct epoll_event));
kore_log(LOG_NOTICE, "worker %d going to work (CPU: %d)",
kw->id, kw->cpu);
for (;;) {
if (sig_recv != 0) {
if (sig_recv == SIGHUP)

View File

@ -31,6 +31,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
#include <regex.h>
#include <zlib.h>
@ -115,6 +116,25 @@ kore_debug_internal(char *file, int line, const char *fmt, ...)
printf("[%d] %s:%d - %s\n", mypid, file, line, buf);
}
void
kore_log_init(void)
{
openlog("kore", LOG_NDELAY | LOG_PID, LOG_DAEMON);
}
void
kore_log(int prio, const char *fmt, ...)
{
va_list args;
char buf[2048];
va_start(args, fmt);
vsnprintf(buf, sizeof(buf), fmt, args);
va_end(args);
syslog(prio, "%s", buf);
}
void
kore_strlcpy(char *dst, const char *src, size_t len)
{
@ -288,6 +308,6 @@ fatal(const char *fmt, ...)
vsnprintf(buf, sizeof(buf), fmt, args);
va_end(args);
printf("error: %s\n", buf);
printf("%s\n", buf);
exit(1);
}