aboutsummaryrefslogtreecommitdiff
path: root/src/or
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2017-12-20 10:40:32 -0500
committerNick Mathewson <nickm@torproject.org>2017-12-20 10:40:32 -0500
commit18543c2c9b7b2a2b23b25b2e64262d60a5c448c5 (patch)
tree7d7898139fe469910ef26bf3a8f26e3ba843209f /src/or
parent3bc580633968ab38ddecb86c866bf95d116afccb (diff)
parent61c721f1458c9779541aa6e07e5e59404cf31dc4 (diff)
downloadtor-18543c2c9b7b2a2b23b25b2e64262d60a5c448c5.tar.gz
tor-18543c2c9b7b2a2b23b25b2e64262d60a5c448c5.zip
Merge remote-tracking branch 'ffmancera/github/bug23271'
Diffstat (limited to 'src/or')
-rw-r--r--src/or/main.c33
-rw-r--r--src/or/main.h2
2 files changed, 22 insertions, 13 deletions
diff --git a/src/or/main.c b/src/or/main.c
index aae98dd8ab..e66167fe41 100644
--- a/src/or/main.c
+++ b/src/or/main.c
@@ -3397,6 +3397,18 @@ tor_free_all(int postfork)
}
}
+/** Remove the specified file. */
+void
+tor_remove_file(const char *filename)
+{
+ if (file_status(filename) == FN_FILE) {
+ if (tor_unlink(filename) != 0) {
+ log_warn(LD_FS, "Couldn't unlink %s: %s",
+ filename, strerror(errno));
+ }
+ }
+}
+
/** Do whatever cleanup is necessary before shutting Tor down. */
void
tor_cleanup(void)
@@ -3406,19 +3418,14 @@ tor_cleanup(void)
time_t now = time(NULL);
/* Remove our pid file. We don't care if there was an error when we
* unlink, nothing we could do about it anyways. */
- if (options->PidFile) {
- if (unlink(options->PidFile) != 0) {
- log_warn(LD_FS, "Couldn't unlink pid file %s: %s",
- options->PidFile, strerror(errno));
- }
- }
- if (options->ControlPortWriteToFile) {
- if (unlink(options->ControlPortWriteToFile) != 0) {
- log_warn(LD_FS, "Couldn't unlink control port file %s: %s",
- options->ControlPortWriteToFile,
- strerror(errno));
- }
- }
+ tor_remove_file(options->PidFile);
+ /* Remove control port file */
+ tor_remove_file(options->ControlPortWriteToFile);
+ /* Remove cookie authentication file */
+ tor_remove_file(get_controller_cookie_file_name());
+ /* Remove Extended ORPort cookie authentication file */
+ tor_remove_file(get_ext_or_auth_cookie_file_name());
+
if (accounting_is_enabled(options))
accounting_record_bandwidth_usage(now, get_or_state());
or_state_mark_dirty(get_or_state(), 0); /* force an immediate save. */
diff --git a/src/or/main.h b/src/or/main.h
index 8eb977575e..132c302dda 100644
--- a/src/or/main.h
+++ b/src/or/main.h
@@ -73,6 +73,8 @@ int try_locking(const or_options_t *options, int err_if_locked);
int have_lockfile(void);
void release_lockfile(void);
+void tor_remove_file(const char *filename);
+
void tor_cleanup(void);
void tor_free_all(int postfork);