kore

An easy to use, scalable and secure web application framework for writing web APIs in C.
Commits | Files | Refs | README | LICENSE | git clone https://git.kore.io/kore.git

commit 90e1b3a7da03ff40949a07448a58834c7672aec0
parent 49b77d3b0e0726f3be51078f519d3f57c8ff6d25
Author: Joris Vink <joris@coders.se>
Date:   Tue,  4 Jun 2013 23:24:47 +0200

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

Diffstat:
includes/kore.h | 2++
src/kore.c | 11+++++++++--
src/utils.c | 22+++++++++++++++++++++-
3 files changed, 32 insertions(+), 3 deletions(-)

diff --git a/includes/kore.h b/includes/kore.h @@ -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); diff --git a/src/kore.c b/src/kore.c @@ -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) diff --git a/src/utils.c b/src/utils.c @@ -31,6 +31,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <syslog.h> #include <regex.h> #include <zlib.h> @@ -116,6 +117,25 @@ kore_debug_internal(char *file, int line, const char *fmt, ...) } 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) { char *d = dst; @@ -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); }