diff --git a/src/necronda-server.c b/src/necronda-server.c index 5543037..8b6c644 100644 --- a/src/necronda-server.c +++ b/src/necronda-server.c @@ -172,9 +172,6 @@ int main(int argc, const char *argv[]) { struct timeval timeout; - parent_stdout = stdout; - parent_stderr = stderr; - const struct sockaddr_in6 addresses[2] = { {.sin6_family = AF_INET6, .sin6_addr = IN6ADDR_ANY_INIT, .sin6_port = htons(80)}, {.sin6_family = AF_INET6, .sin6_addr = IN6ADDR_ANY_INIT, .sin6_port = htons(443)} @@ -190,6 +187,7 @@ int main(int argc, const char *argv[]) { "\n" "Options:\n" " -c, --cert path to the full chain certificate file\n" + " -g, --geoip path to a Maxmind GeoIP Database file\n" " -h, --help print this dialogue\n" " -p, --privkey path to the private key file\n" " -w, --webroot path to the web root directory\n"); @@ -212,6 +210,12 @@ int main(int argc, const char *argv[]) { return 1; } key_file = argv[++i]; + } else if ((len == 2 && strncmp(arg, "-g", 2) == 0) || (len == 7 && strncmp(arg, "--geoip", 7) == 0)) { + if (i == argc - 1) { + fprintf(stderr, ERR_STR "Unable to parse argument %s, usage: --geoip " CLR_STR "\n", arg); + return 1; + } + geoip_file = argv[++i]; } else { fprintf(stderr, ERR_STR "Unable to parse argument '%s'" CLR_STR "\n", arg); return 1; @@ -312,7 +316,7 @@ int main(int argc, const char *argv[]) { if (FD_ISSET(sockets[i], &read_socket_fds)) { client_fd = accept(sockets[i], (struct sockaddr *) &client_addr, &client_addr_len); if (client_fd == -1) { - fprintf(parent_stderr, ERR_STR "Unable to accept connection: %s" CLR_STR "\n", strerror(errno)); + fprintf(stderr, ERR_STR "Unable to accept connection: %s" CLR_STR "\n", strerror(errno)); continue; } diff --git a/src/necronda-server.h b/src/necronda-server.h index f8c2906..101c65b 100644 --- a/src/necronda-server.h +++ b/src/necronda-server.h @@ -59,9 +59,7 @@ int sockets[NUM_SOCKETS]; pid_t children[MAX_CHILDREN]; -FILE *parent_stdout, *parent_stderr; - -const char *cert_file, *key_file, *webroot_base; +const char *cert_file, *key_file, *webroot_base, *geoip_file; typedef struct { unsigned int enc:1; diff --git a/src/utils.h b/src/utils.h index f7547c9..375ae04 100644 --- a/src/utils.h +++ b/src/utils.h @@ -10,8 +10,8 @@ char *log_prefix; -#define out_1(fmt) fprintf(parent_stdout, "%s" fmt "\n", log_prefix) -#define out_2(fmt, args...) fprintf(parent_stdout, "%s" fmt "\n", log_prefix, args) +#define out_1(fmt) fprintf(stdout, "%s" fmt "\n", log_prefix) +#define out_2(fmt, args...) fprintf(stdout, "%s" fmt "\n", log_prefix, args) #define out_x(x, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, FUNC, ...) FUNC