diff options
author | Nick Mathewson <nickm@torproject.org> | 2018-06-22 11:40:20 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2018-06-22 11:40:20 -0400 |
commit | 79f73ab330c0e643ba1ec2eb0633f0f80525a083 (patch) | |
tree | a4e923238c46a51efdd946bdcc890313d3336db4 /src/or | |
parent | 90a09df5ba7b3e55ea388a4cc9b92161442bb380 (diff) | |
download | tor-79f73ab330c0e643ba1ec2eb0633f0f80525a083.tar.gz tor-79f73ab330c0e643ba1ec2eb0633f0f80525a083.zip |
Finally extract the log library and make it build.
This patch:
- introduces an fdio module for low-level fd functions that don't
need to log.
- moves the responsibility for opening files outside of torlog.c,
so it won't need to call tor_open_cloexec.
Diffstat (limited to 'src/or')
-rw-r--r-- | src/or/config.c | 20 | ||||
-rw-r--r-- | src/or/config.h | 4 | ||||
-rw-r--r-- | src/or/keypin.c | 2 | ||||
-rw-r--r-- | src/or/microdesc.c | 4 |
4 files changed, 25 insertions, 5 deletions
diff --git a/src/or/config.c b/src/or/config.c index 6bdb4ab7dc..cc3cc3ec55 100644 --- a/src/or/config.c +++ b/src/or/config.c @@ -5638,6 +5638,23 @@ addressmap_register_auto(const char *from, const char *to, } /** + * As add_file_log, but open the file as appropriate. + */ +STATIC int +open_and_add_file_log(const log_severity_list_t *severity, + const char *filename, int truncate_log) +{ + int open_flags = O_WRONLY|O_CREAT; + open_flags |= truncate_log ? O_TRUNC : O_APPEND; + + int fd = tor_open_cloexec(filename, open_flags, 0640); + if (fd < 0) + return -1; + + return add_file_log(severity, filename, fd); +} + +/** * Initialize the logs based on the configuration file. */ static int @@ -5762,7 +5779,7 @@ options_init_logs(const or_options_t *old_options, or_options_t *options, } } } - if (add_file_log(severity, fname, truncate_log) < 0) { + if (open_and_add_file_log(severity, fname, truncate_log) < 0) { log_warn(LD_CONFIG, "Couldn't open file for 'Log %s': %s", opt->value, strerror(errno)); ok = 0; @@ -8452,4 +8469,3 @@ options_any_client_port_set(const or_options_t *options) options->DNSPort_set || options->HTTPTunnelPort_set); } - diff --git a/src/or/config.h b/src/or/config.h index dc3322e6b4..d2faf6c512 100644 --- a/src/or/config.h +++ b/src/or/config.h @@ -271,8 +271,10 @@ STATIC int check_bridge_distribution_setting(const char *bd); STATIC uint64_t compute_real_max_mem_in_queues(const uint64_t val, int log_guess); +STATIC int open_and_add_file_log(const log_severity_list_t *severity, + const char *fname, + int truncate_log); #endif /* defined(CONFIG_PRIVATE) */ #endif /* !defined(TOR_CONFIG_H) */ - diff --git a/src/or/keypin.c b/src/or/keypin.c index 312530fe45..db267673f8 100644 --- a/src/or/keypin.c +++ b/src/or/keypin.c @@ -20,6 +20,7 @@ #include "siphash.h" #include "lib/cc/torint.h" #include "lib/log/torlog.h" +#include "lib/fdio/fdio.h" #include "common/util.h" #include "common/util_format.h" @@ -498,4 +499,3 @@ keypin_clear(void) bad_entries); } } - diff --git a/src/or/microdesc.c b/src/or/microdesc.c index d29d2c300e..bbe5ead6b4 100644 --- a/src/or/microdesc.c +++ b/src/or/microdesc.c @@ -9,6 +9,9 @@ */ #include "or/or.h" + +#include "lib/fdio/fdio.h" + #include "or/circuitbuild.h" #include "or/config.h" #include "or/directory.h" @@ -1047,4 +1050,3 @@ usable_consensus_flavor,(void)) return FLAV_NS; } } - |