[tor-commits] [tor/master] Add remove file function and remove ephemeral files.
nickm at torproject.org
nickm at torproject.org
Wed Dec 20 15:43:32 UTC 2017
commit 61c721f1458c9779541aa6e07e5e59404cf31dc4
Author: Fernando Fernandez Mancera <ffernandezmancera at gmail.com>
Date: Fri Dec 15 17:01:22 2017 +0100
Add remove file function and remove ephemeral files.
Adding tor_remove_file(filename) and refactoring tor_cleanup().
Removing CookieAuthFile and ExtORPortCookieAuthFile when tor_cleanup() is
called.
Fixes #23271.
Signed-off-by: Fernando Fernandez Mancera <ffernandezmancera at gmail.com>
---
changes/ticket23271 | 6 ++++++
src/or/main.c | 33 ++++++++++++++++++++-------------
src/or/main.h | 2 ++
3 files changed, 28 insertions(+), 13 deletions(-)
diff --git a/changes/ticket23271 b/changes/ticket23271
new file mode 100644
index 000000000..42d5921a7
--- /dev/null
+++ b/changes/ticket23271
@@ -0,0 +1,6 @@
+ o Code simplification and refactoring:
+ - Separate the function that deletes ephemeral files when Tor stops
+ gracefully.
+ o Minor features (cleanup):
+ - Tor now deletes the CookieAuthFile and ExtORPortCookieAuthFile when it
+ stops. Closes ticket 23271.
diff --git a/src/or/main.c b/src/or/main.c
index c340e4128..9d9391fc0 100644
--- a/src/or/main.c
+++ b/src/or/main.c
@@ -3303,6 +3303,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)
@@ -3312,19 +3324,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 132ab12bb..d05800f93 100644
--- a/src/or/main.h
+++ b/src/or/main.h
@@ -71,6 +71,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);
More information about the tor-commits
mailing list