mirror of https://git.kore.io/kore.git
use syslog() for informative messages from all parts of kore.
This commit is contained in:
parent
49b77d3b0e
commit
90e1b3a7da
|
@ -138,6 +138,7 @@ extern char *kore_pidfile;
|
||||||
extern u_int8_t worker_count;
|
extern u_int8_t worker_count;
|
||||||
extern pid_t mypid;
|
extern pid_t mypid;
|
||||||
|
|
||||||
|
void kore_log_init(void);
|
||||||
void *kore_malloc(size_t);
|
void *kore_malloc(size_t);
|
||||||
void *kore_calloc(size_t, size_t);
|
void *kore_calloc(size_t, size_t);
|
||||||
void *kore_realloc(void *, 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_time_to_date(time_t);
|
||||||
char *kore_strdup(const char *);
|
char *kore_strdup(const char *);
|
||||||
void kore_parse_config(const char *);
|
void kore_parse_config(const char *);
|
||||||
|
void kore_log(int, const char *, ...);
|
||||||
void kore_strlcpy(char *, const char *, size_t);
|
void kore_strlcpy(char *, const char *, size_t);
|
||||||
void kore_server_disconnect(struct connection *);
|
void kore_server_disconnect(struct connection *);
|
||||||
int kore_split_string(char *, char *, char **, size_t);
|
int kore_split_string(char *, char *, char **, size_t);
|
||||||
|
|
11
src/kore.c
11
src/kore.c
|
@ -37,6 +37,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sched.h>
|
#include <sched.h>
|
||||||
|
#include <syslog.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <regex.h>
|
#include <regex.h>
|
||||||
|
@ -90,6 +91,7 @@ main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
struct kore_worker *kw, *next;
|
struct kore_worker *kw, *next;
|
||||||
|
|
||||||
|
kore_log_init();
|
||||||
mypid = getpid();
|
mypid = getpid();
|
||||||
|
|
||||||
if (argc != 2)
|
if (argc != 2)
|
||||||
|
@ -127,7 +129,9 @@ main(int argc, char *argv[])
|
||||||
if (chdir("/") == -1)
|
if (chdir("/") == -1)
|
||||||
fatal("cannot chdir(): %s", errno_s);
|
fatal("cannot chdir(): %s", errno_s);
|
||||||
|
|
||||||
|
kore_log(LOG_NOTICE, "kore is starting up");
|
||||||
kore_worker_init();
|
kore_worker_init();
|
||||||
|
|
||||||
if (prctl(PR_SET_NAME, "kore [main]"))
|
if (prctl(PR_SET_NAME, "kore [main]"))
|
||||||
kore_debug("cannot set process title");
|
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("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))
|
while (!TAILQ_EMPTY(&kore_workers))
|
||||||
kore_worker_wait(1);
|
kore_worker_wait(1);
|
||||||
|
|
||||||
kore_debug("server shutting down");
|
kore_log(LOG_NOTICE, "server shutting down");
|
||||||
unlink(kore_pidfile);
|
unlink(kore_pidfile);
|
||||||
close(server.fd);
|
close(server.fd);
|
||||||
|
|
||||||
|
@ -576,6 +580,9 @@ kore_worker_entry(struct kore_worker *kw)
|
||||||
quit = 0;
|
quit = 0;
|
||||||
kore_event(server.fd, EPOLLIN, &server);
|
kore_event(server.fd, EPOLLIN, &server);
|
||||||
events = kore_calloc(EPOLL_EVENTS, sizeof(struct epoll_event));
|
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 (;;) {
|
for (;;) {
|
||||||
if (sig_recv != 0) {
|
if (sig_recv != 0) {
|
||||||
if (sig_recv == SIGHUP)
|
if (sig_recv == SIGHUP)
|
||||||
|
|
22
src/utils.c
22
src/utils.c
|
@ -31,6 +31,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <syslog.h>
|
||||||
#include <regex.h>
|
#include <regex.h>
|
||||||
#include <zlib.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);
|
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
|
void
|
||||||
kore_strlcpy(char *dst, const char *src, size_t len)
|
kore_strlcpy(char *dst, const char *src, size_t len)
|
||||||
{
|
{
|
||||||
|
@ -288,6 +308,6 @@ fatal(const char *fmt, ...)
|
||||||
vsnprintf(buf, sizeof(buf), fmt, args);
|
vsnprintf(buf, sizeof(buf), fmt, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
|
|
||||||
printf("error: %s\n", buf);
|
printf("%s\n", buf);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue