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 b9f47b0f8634c98d85c6b5f8e406b9b098b68f01
parent ade34a26c1c9dbddd806e1999aff248793fbf7ad
Author: Joris Vink <joris@coders.se>
Date:   Wed,  5 Jun 2013 08:55:07 +0200

configuration files are now passed using the -c option.
allow debug output when the -d flag is specified.

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

diff --git a/includes/kore.h b/includes/kore.h @@ -26,13 +26,9 @@ #define KORE_PIDFILE_DEFAULT "/var/run/kore.pid" -//#define KORE_DEBUG 1 -#if defined(KORE_DEBUG) #define kore_debug(fmt, ...) \ - kore_debug_internal(__FILE__, __LINE__, fmt, ##__VA_ARGS__) -#else -#define kore_debug(fmt, ...) -#endif + if (kore_debug) \ + kore_debug_internal(__FILE__, __LINE__, fmt, ##__VA_ARGS__) #define NETBUF_RECV 0 #define NETBUF_SEND 1 @@ -129,6 +125,7 @@ struct buf_vec { u_int32_t length; }; +extern int kore_debug; extern int server_port; extern char *server_ip; extern char *chroot_path; diff --git a/src/kore.c b/src/kore.c @@ -63,6 +63,7 @@ static u_int16_t workerid = 0; static u_int16_t cpu_count = 1; pid_t mypid = -1; +int kore_debug = 0; int server_port = 0; u_int8_t worker_count = 0; char *server_ip = NULL; @@ -70,6 +71,7 @@ char *chroot_path = NULL; char *runas_user = NULL; char *kore_pidfile = KORE_PIDFILE_DEFAULT; +static void usage(void); static void kore_signal(int); static void kore_worker_wait(int); static void kore_worker_init(void); @@ -86,20 +88,48 @@ static void kore_server_final_disconnect(struct connection *); static int kore_server_bind(struct listener *, const char *, int); static int kore_ssl_npn_cb(SSL *, const u_char **, unsigned int *, void *); +static void +usage(void) +{ + fprintf(stderr, "Usage: kore [-c config] [-d]\n"); + exit(1); +} + int main(int argc, char *argv[]) { + int ch; struct kore_worker *kw, *next; + char *config_file; kore_log_init(); mypid = getpid(); - if (argc != 2) - fatal("Usage: kore [config file]"); if (getuid() != 0) fatal("kore must be started as root"); - kore_parse_config(argv[1]); + kore_debug = 0; + config_file = NULL; + while ((ch = getopt(argc, argv, "c:d")) != -1) { + switch (ch) { + case 'c': + config_file = optarg; + break; + case 'd': + kore_debug = 1; + break; + default: + usage(); + } + } + + argc -= optind; + argv += optind; + + if (config_file == NULL) + fatal("please specify a configuration file to use (-c)"); + + kore_parse_config(config_file); if (!kore_module_loaded()) fatal("no site module was loaded"); @@ -110,7 +140,7 @@ main(int argc, char *argv[]) if (runas_user == NULL) fatal("missing a username to run as"); if ((pw = getpwnam(runas_user)) == NULL) - fatal("user '%s' does not exist"); + fatal("user '%s' does not exist", runas_user); if ((cpu_count = sysconf(_SC_NPROCESSORS_ONLN)) == -1) { kore_debug("could not get number of cpu's falling back to 1"); cpu_count = 1; diff --git a/src/utils.c b/src/utils.c @@ -308,6 +308,6 @@ fatal(const char *fmt, ...) vsnprintf(buf, sizeof(buf), fmt, args); va_end(args); - printf("%s\n", buf); + printf("kore: %s\n", buf); exit(1); }