Skip to content

Commit

Permalink
Logging to syslog even when set to syslog = off? #187
Browse files Browse the repository at this point in the history
 * Not turning on syslog when daemonizing (bugfix)
 * Making log-filename, recv-bufsize and send-bufsize parameters available
though command line and mentioning them in the help (finishing incomplete
feature)
  • Loading branch information
dmatetelki committed Oct 12, 2017
1 parent 99ef536 commit ab4bbf9
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions src/configuration.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
#define CFG_SYSLOG "syslog"
#define CFG_SYSLOG_FACILITY "syslog-facility"
#define CFG_PARAM_SYSLOG_FACILITY 11015
#define CFG_PARAM_SEND_BUFSIZE 11016
#define CFG_PARAM_RECV_BUFSIZE 11017
#define CFG_DAEMON "daemon"
#define CFG_WRITE_IP "write-ip"
#define CFG_WRITE_PROXY "write-proxy"
Expand Down Expand Up @@ -805,6 +807,10 @@ config_param_validate(char *k, char *v, hitch_config *cfg,
}
} else if (strcmp(k, CFG_QUIET) == 0) {
r = config_param_val_bool(v, &cfg->QUIET);
} else if (strcmp(k, CFG_LOG_FILENAME) == 0) {
if (strlen(v) > 0) {
config_assign_str(&cfg->LOG_FILENAME, v);
}
} else if (strcmp(k, CFG_SYSLOG) == 0) {
r = config_param_val_bool(v, &cfg->SYSLOG);
} else if (strcmp(k, CFG_SYSLOG_FACILITY) == 0) {
Expand Down Expand Up @@ -1025,10 +1031,12 @@ config_print_usage_fd(char *prog, FILE *out)
fprintf(out, "\n");
fprintf(out, "SOCKET:\n");
fprintf(out, "\n");
fprintf(out, " --client Enable client proxy mode\n");
fprintf(out, " -b --backend=[HOST]:PORT Backend [connect] (default is \"%s\")\n", config_disp_hostport(cfg->BACK_IP, cfg->BACK_PORT));
fprintf(out, " --client Enable client proxy mode\n");
fprintf(out, " -b --backend=[HOST]:PORT Backend [connect] (default is \"%s\")\n", config_disp_hostport(cfg->BACK_IP, cfg->BACK_PORT));
fprintf(out, " -f --frontend=[HOST]:PORT[+CERT] Frontend [bind] (default is \"%s\")\n", config_disp_hostport(cfg->LISTEN_DEFAULT->ip, cfg->LISTEN_DEFAULT->port));
fprintf(out, " (Note: brackets are mandatory in endpoint specifiers.)");
fprintf(out, " (Note: brackets are mandatory in endpoint specifiers.)\n");
fprintf(out, " --recv-bufsize=SIZE Receive buffer size on client socket (Default: %d)\n", cfg->RECV_BUFSIZE);
fprintf(out, " --send-bufsize=SIZE Send buffer size on client socket (Default: %d)\n", cfg->SEND_BUFSIZE);

#ifdef USE_SHARED_CACHE
fprintf(out, "\n");
Expand All @@ -1049,6 +1057,7 @@ config_print_usage_fd(char *prog, FILE *out)
fprintf(out, " -B --backlog=NUM Set listen backlog size (Default: %d)\n", cfg->BACKLOG);
fprintf(out, " -k --keepalive=SECS TCP keepalive on client socket (Default: %d)\n", cfg->TCP_KEEPALIVE_TIME);


#ifdef USE_SHARED_CACHE
fprintf(out, " -C --session-cache=NUM Enable and set SSL session cache to specified number\n");
fprintf(out, " of sessions (Default: %d)\n", cfg->SHARED_CACHE);
Expand All @@ -1063,8 +1072,9 @@ config_print_usage_fd(char *prog, FILE *out)
fprintf(out, "\n");
fprintf(out, "LOGGING:\n");
fprintf(out, " -q --quiet Be quiet; emit only error messages\n");
fprintf(out, " -l --log-filename=FILE Send log message to a logfile instead of stderr/stdout\n");
fprintf(out, " -s --syslog Send log message to syslog in addition to stderr/stdout\n");
fprintf(out, " --syslog-facility=FACILITY Syslog facility to use (Default: \"%s\")\n", config_disp_log_facility(cfg->SYSLOG_FACILITY));
fprintf(out, " --syslog-facility=FACILITY Syslog facility to use (Default: \"%s\")\n", config_disp_log_facility(cfg->SYSLOG_FACILITY));
fprintf(out, "\n");
fprintf(out, "OTHER OPTIONS:\n");
fprintf(out, " --daemon Fork into background and become a daemon (Default: %s)\n", config_disp_bool(cfg->DAEMONIZE));
Expand Down Expand Up @@ -1191,8 +1201,11 @@ config_parse_cli(int argc, char **argv, hitch_config *cfg, int *retval)
{ CFG_USER, 1, NULL, 'u' },
{ CFG_GROUP, 1, NULL, 'g' },
{ CFG_QUIET, 0, NULL, 'q' },
{ CFG_LOG_FILENAME, 1, NULL, 'l' },
{ CFG_SYSLOG, 0, NULL, 's' },
{ CFG_SYSLOG_FACILITY, 1, NULL, CFG_PARAM_SYSLOG_FACILITY },
{ CFG_SEND_BUFSIZE, 1, NULL, CFG_PARAM_SEND_BUFSIZE },
{ CFG_RECV_BUFSIZE, 1, NULL, CFG_PARAM_RECV_BUFSIZE },
{ CFG_DAEMON, 0, &cfg->DAEMONIZE, 1 },
{ CFG_WRITE_IP, 0, &cfg->WRITE_IP_OCTET, 1 },
{ CFG_WRITE_PROXY_V1, 0, &cfg->WRITE_PROXY_LINE_V1, 1 },
Expand All @@ -1207,7 +1220,7 @@ config_parse_cli(int argc, char **argv, hitch_config *cfg, int *retval)
{ "help", 0, NULL, 'h' },
{ 0, 0, 0, 0 }
};
#define SHORT_OPTS "c:e:Ob:f:n:B:C:U:p:P:M:k:r:u:g:qstVho:"
#define SHORT_OPTS "c:e:Ob:f:n:B:l:C:U:p:P:M:k:r:u:g:qstVho:"

if (argc == 1) {
config_print_usage(argv[0]);
Expand Down Expand Up @@ -1267,6 +1280,8 @@ config_parse_cli(int argc, char **argv, hitch_config *cfg, int *retval)
NULL, 0); \
break;
CFG_ARG(CFG_PARAM_SYSLOG_FACILITY, CFG_SYSLOG_FACILITY);
CFG_ARG(CFG_PARAM_SEND_BUFSIZE, CFG_SEND_BUFSIZE);
CFG_ARG(CFG_PARAM_RECV_BUFSIZE, CFG_RECV_BUFSIZE);
CFG_ARG(CFG_PARAM_ALPN_PROTOS, CFG_ALPN_PROTOS);
CFG_ARG('c', CFG_CIPHERS);
CFG_ARG('e', CFG_SSL_ENGINE);
Expand All @@ -1288,6 +1303,7 @@ CFG_ARG('g', CFG_GROUP);
CFG_ARG('o', CFG_OCSP_DIR);
CFG_ON('O', CFG_PREFER_SERVER_CIPHERS);
CFG_ON('q', CFG_QUIET);
CFG_ARG('l', CFG_LOG_FILENAME);
CFG_ON('s', CFG_SYSLOG);
#undef CFG_ARG
#undef CFG_ON
Expand Down Expand Up @@ -1353,7 +1369,6 @@ CFG_ON('s', CFG_SYSLOG);


if (cfg->DAEMONIZE) {
cfg->SYSLOG = 1;
cfg->QUIET = 1;
}

Expand Down

0 comments on commit ab4bbf9

Please sign in to comment.