summaryrefslogtreecommitdiff
path: root/src/or/main.c
diff options
context:
space:
mode:
authorFernando Fernandez Mancera <ffernandezmancera@gmail.com>2017-12-15 17:01:22 +0100
committerFernando Fernandez Mancera <ffernandezmancera@gmail.com>2017-12-15 17:01:22 +0100
commit61c721f1458c9779541aa6e07e5e59404cf31dc4 (patch)
treedddff02802c97d4a942216e04d0fc952fee37181 /src/or/main.c
parent15b41fa6ae6a1356d5453242ccb7d7d301dd5e67 (diff)
downloadtor-61c721f1458c9779541aa6e07e5e59404cf31dc4.tar.gz
tor-61c721f1458c9779541aa6e07e5e59404cf31dc4.zip
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@gmail.com>
Diffstat (limited to 'src/or/main.c')
-rw-r--r--src/or/main.c33
1 files changed, 20 insertions, 13 deletions
diff --git a/src/or/main.c b/src/or/main.c
index c340e4128b..9d9391fc0a 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. */