From 8ccba8ebfaca85017eb125c45b0f16ae358358a7 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Thu, 1 May 2014 16:26:39 +0200 Subject: Remove support for log files syslog/journald do a much better job at organizing logs, with the additional advantage of proper log rotation. If someone really wants to have a log file for fastd, they can just redirect stderr. --- src/config.c | 47 +---------------------------------------------- src/config.h | 1 - src/config.y | 8 ++++---- src/fastd.c | 42 ++---------------------------------------- src/fastd.h | 16 ---------------- src/log.c | 8 +------- src/types.h | 3 --- 7 files changed, 8 insertions(+), 117 deletions(-) diff --git a/src/config.c b/src/config.c index e7a69c3..6360475 100644 --- a/src/config.c +++ b/src/config.c @@ -195,44 +195,6 @@ static bool has_peer_group_peer_dirs(const fastd_peer_group_config_t *group) { return false; } -void fastd_config_add_log_file(const char *name, fastd_loglevel_t level) { - char *name2 = strdup(name); - char *name3 = strdup(name); - - char *dir = dirname(name2); - char *base = basename(name3); - - char *oldcwd = get_current_dir_name(); - - if (!chdir(dir)) { - char *logdir = get_current_dir_name(); - - fastd_log_file_t *file = malloc(sizeof(fastd_log_file_t)); - file->filename = malloc(strlen(logdir) + 1 + strlen(base) + 1); - - strcpy(file->filename, logdir); - strcat(file->filename, "/"); - strcat(file->filename, base); - - file->level = level; - - file->next = conf.log_files; - conf.log_files = file; - - if(chdir(oldcwd)) - pr_error("can't chdir to `%s': %s", oldcwd, strerror(errno)); - - free(logdir); - } - else { - pr_error("change from directory `%s' to `%s' failed: %s", oldcwd, dir, strerror(errno)); - } - - free(oldcwd); - free(name2); - free(name3); -} - static void read_peer_dir(const char *dir) { DIR *dirh = opendir("."); @@ -533,7 +495,7 @@ void fastd_configure(int argc, char *const argv[]) { fastd_config_handle_options(argc, argv); - if (!conf.log_stderr_level && !conf.log_syslog_level && !conf.log_files) + if (!conf.log_stderr_level && !conf.log_syslog_level) conf.log_stderr_level = FASTD_DEFAULT_LOG_LEVEL; } @@ -679,13 +641,6 @@ void fastd_config_release(void) { while (conf.peers) fastd_peer_config_delete(); - while (conf.log_files) { - fastd_log_file_t *next = conf.log_files->next; - free(conf.log_files->filename); - free(conf.log_files); - conf.log_files = next; - } - while (conf.bind_addrs) { fastd_bind_address_t *next = conf.bind_addrs->next; free(conf.bind_addrs->bindtodev); diff --git a/src/config.h b/src/config.h index 18e516a..d4cbf93 100644 --- a/src/config.h +++ b/src/config.h @@ -33,7 +33,6 @@ void fastd_config_protocol(const char *name); void fastd_config_method(const char *name); void fastd_config_cipher(const char *name, const char *impl); void fastd_config_mac(const char *name, const char *impl); -void fastd_config_add_log_file(const char *name, fastd_loglevel_t level); void fastd_config_bind_address(const fastd_peer_address_t *address, const char *bindtodev, bool default_v4, bool default_v6); void fastd_config_peer_group_push(const char *name); void fastd_config_peer_group_pop(void); diff --git a/src/config.y b/src/config.y index 8c53b07..a448a00 100644 --- a/src/config.y +++ b/src/config.y @@ -248,7 +248,10 @@ mac: TOK_STRING TOK_USE TOK_STRING { } log: TOK_LEVEL log_level { - conf.log_stderr_level = $2; + if (conf.log_syslog_level) + conf.log_syslog_level = $2; + if (conf.log_stderr_level || !conf.log_syslog_level) + conf.log_stderr_level = $2; } | TOK_TO TOK_STDERR maybe_log_level { conf.log_stderr_level = $3; @@ -262,9 +265,6 @@ log: TOK_LEVEL log_level { conf.log_syslog_level = $5; } - | TOK_TO TOK_STRING maybe_log_level { - fastd_config_add_log_file($2->str, $3); - } ; hide: TOK_IP TOK_ADDRESSES boolean { diff --git a/src/fastd.c b/src/fastd.c index 709f55f..2ca9dd4 100644 --- a/src/fastd.c +++ b/src/fastd.c @@ -120,49 +120,14 @@ static void init_signals(void) { } -static void init_log(void) { - uid_t uid = geteuid(); - gid_t gid = getegid(); - - if (conf.user || conf.group) { - if (setegid(conf.gid) < 0) - pr_debug_errno("setegid"); - if (seteuid(conf.uid) < 0) - pr_debug_errno("seteuid"); - } - +static inline void init_log(void) { if (conf.log_syslog_level > LL_UNSPEC) openlog(conf.log_syslog_ident, LOG_PID, LOG_DAEMON); - fastd_log_file_t *config; - for (config = conf.log_files; config; config = config->next) { - fastd_log_fd_t *file = malloc(sizeof(fastd_log_fd_t)); - - file->config = config; - file->fd = open(config->filename, O_WRONLY|O_APPEND|O_CREAT, 0600); - - file->next = ctx.log_files; - ctx.log_files = file; - } - ctx.log_initialized = true; - - if (seteuid(uid) < 0) - pr_debug_errno("seteuid"); - if (setegid(gid) < 0) - pr_debug_errno("setegid"); } -static void close_log(void) { - while (ctx.log_files) { - fastd_log_fd_t *next = ctx.log_files->next; - - close(ctx.log_files->fd); - free(ctx.log_files); - - ctx.log_files = next; - } - +static inline void close_log(void) { closelog(); } @@ -684,9 +649,6 @@ int main(int argc, char *argv[]) { pr_info("reconfigure triggered"); - close_log(); - init_log(); - fastd_config_load_peer_dirs(); init_peers(); } diff --git a/src/fastd.h b/src/fastd.h index 3bb4689..7e04132 100644 --- a/src/fastd.h +++ b/src/fastd.h @@ -84,20 +84,6 @@ union fastd_peer_address { struct sockaddr_in6 in6; }; -struct fastd_log_file { - fastd_log_file_t *next; - - fastd_loglevel_t level; - char *filename; -}; - -struct fastd_log_fd { - fastd_log_fd_t *next; - - fastd_log_file_t *config; - int fd; -}; - struct fastd_bind_address { fastd_bind_address_t *next; fastd_peer_address_t addr; @@ -145,7 +131,6 @@ struct fastd_config { fastd_loglevel_t log_stderr_level; fastd_loglevel_t log_syslog_level; char *log_syslog_ident; - fastd_log_file_t *log_files; unsigned maintenance_interval; unsigned keepalive_timeout; @@ -239,7 +224,6 @@ struct fastd_config { struct fastd_context { bool log_initialized; - fastd_log_fd_t *log_files; char *ifname; diff --git a/src/log.c b/src/log.c index 9bcbd14..b274dbd 100644 --- a/src/log.c +++ b/src/log.c @@ -239,7 +239,7 @@ void fastd_logf(fastd_loglevel_t level, const char *format, ...) { buffer[sizeof(buffer)-1] = 0; - if (!ctx.log_initialized || level <= conf.log_stderr_level || conf.log_files) { + if (!ctx.log_initialized || level <= conf.log_stderr_level) { time_t t; struct tm tm; @@ -256,11 +256,5 @@ void fastd_logf(fastd_loglevel_t level, const char *format, ...) { if (ctx.log_initialized) { if (level <= conf.log_syslog_level) syslog(get_syslog_level(level), "%s", buffer); - - fastd_log_fd_t *file; - for (file = ctx.log_files; file; file = file->next) { - if (level <= file->config->level) - dprintf(file->fd, "%s%s%s\n", timestr, get_log_prefix(level), buffer); - } } } diff --git a/src/types.h b/src/types.h index 4510be2..c7825ef 100644 --- a/src/types.h +++ b/src/types.h @@ -106,9 +106,6 @@ typedef struct fastd_remote fastd_remote_t; typedef struct fastd_stats fastd_stats_t; typedef struct fastd_handshake_timeout fastd_handshake_timeout_t; -typedef struct fastd_log_file fastd_log_file_t; -typedef struct fastd_log_fd fastd_log_fd_t; - typedef struct fastd_config fastd_config_t; typedef struct fastd_context fastd_context_t; -- cgit v1.2.3