kore

Kore is a web application platform for writing scalable, concurrent web based processes in C or Python.
Commits | Files | Refs | README | LICENSE | git clone https://git.kore.io/kore.git

commit 67cf3e872b4d09a98b6aec7eff145ad1af607c79
parent 4313c0eab52a54c1f1f6355a95211cbb3a3a4b02
Author: Joris Vink <joris@coders.se>
Date:   Thu,  8 Oct 2020 13:51:50 +0200

Add kore_default_getopt().

This handles the default option parsing in Kore and should be called
by single_binary=yes builds in kore_parent_configure() unless they
want to handle their own argument parsing.

Diffstat:
include/kore/kore.h | 1+
src/kore.c | 91+++++++++++++++++++++++++++++++++++++++++++------------------------------------
2 files changed, 51 insertions(+), 41 deletions(-)

diff --git a/include/kore/kore.h b/include/kore/kore.h @@ -718,6 +718,7 @@ void kore_signal(int); void kore_shutdown(void); void kore_signal_setup(void); void kore_proctitle(const char *); +void kore_default_getopt(int, char **); void kore_worker_reap(void); void kore_worker_init(void); diff --git a/src/kore.c b/src/kore.c @@ -73,10 +73,8 @@ extern char **environ; extern char *__progname; static size_t proctitle_maxlen = 0; -#if !defined(KORE_SINGLE_BINARY) static void usage(void); static void version(void); -#endif static void kore_write_kore_pid(void); static void kore_proctitle_setup(void); @@ -95,7 +93,6 @@ static const char *parent_daemonized_hook = KORE_DAEMONIZED_HOOK; #endif #endif -#if !defined(KORE_SINGLE_BINARY) static void usage(void) { @@ -107,7 +104,9 @@ usage(void) printf("\n"); printf("Available options:\n"); +#if !defined(KORE_SINGLE_BINARY) printf("\t-c\tconfiguration to use\n"); +#endif #if defined(KORE_DEBUG) printf("\t-d\trun with debug on\n"); #endif @@ -151,15 +150,11 @@ version(void) printf("\n"); exit(0); } -#endif int main(int argc, char *argv[]) { struct kore_runtime_call *rcall; -#if !defined(KORE_SINGLE_BINARY) - int ch; -#endif #if !defined(KORE_SINGLE_BINARY) && defined(KORE_USE_PYTHON) struct stat st; #endif @@ -168,40 +163,7 @@ main(int argc, char *argv[]) kore_argv = argv; #if !defined(KORE_SINGLE_BINARY) - while ((ch = getopt(argc, argv, "c:dfhnqrv")) != -1) { - switch (ch) { - case 'c': - free(config_file); - if ((config_file = strdup(optarg)) == NULL) - fatal("strdup"); - break; -#if defined(KORE_DEBUG) - case 'd': - kore_debug = 1; - break; -#endif - case 'f': - foreground = 1; - break; - case 'h': - usage(); - break; - case 'n': - skip_chroot = 1; - break; - case 'q': - kore_quiet = 1; - break; - case 'r': - skip_runas = 1; - break; - case 'v': - version(); - break; - default: - usage(); - } - } + kore_default_getopt(argc, argv); #endif kore_mem_init(); @@ -340,6 +302,53 @@ main(int argc, char *argv[]) return (0); } +void +kore_default_getopt(int argc, char **argv) +{ + int ch; + +#if !defined(KORE_SINGLE_BINARY) + while ((ch = getopt(argc, argv, "c:dfhnqrv")) != -1) { +#else + while ((ch = getopt(argc, argv, "dfhnqrv")) != -1) { +#endif + switch (ch) { +#if !defined(KORE_SINGLE_BINARY) + case 'c': + free(config_file); + if ((config_file = strdup(optarg)) == NULL) + fatal("strdup"); + break; +#endif +#if defined(KORE_DEBUG) + case 'd': + kore_debug = 1; + break; +#endif + case 'f': + foreground = 1; + break; + case 'h': + usage(); + break; + case 'n': + skip_chroot = 1; + break; + case 'q': + kore_quiet = 1; + break; + case 'r': + skip_runas = 1; + break; + case 'v': + version(); + break; + default: + usage(); + } + } +} + int kore_tls_sni_cb(SSL *ssl, int *ad, void *arg) {