tor  0.4.2.0-alpha-dev
shutdown.c
Go to the documentation of this file.
1 /* Copyright (c) 2001 Matej Pfajfar.
2  * Copyright (c) 2001-2004, Roger Dingledine.
3  * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
4  * Copyright (c) 2007-2018, The Tor Project, Inc. */
5 /* See LICENSE for licensing information */
6 
13 #include "core/or/or.h"
14 
15 #include "app/config/config.h"
16 #include "app/config/statefile.h"
17 #include "app/main/main.h"
18 #include "app/main/shutdown.h"
19 #include "app/main/subsysmgr.h"
21 #include "core/mainloop/mainloop_pubsub.h"
22 #include "core/or/channeltls.h"
23 #include "core/or/circuitlist.h"
25 #include "core/or/circuitpadding.h"
27 #include "core/or/dos.h"
28 #include "core/or/scheduler.h"
29 #include "feature/client/addressmap.h"
30 #include "feature/client/bridges.h"
36 #include "feature/dirauth/shared_random.h"
37 #include "feature/dircache/consdiffmgr.h"
41 #include "feature/hs/hs_common.h"
47 #include "feature/relay/ext_orport.h"
48 #include "feature/rend/rendcache.h"
51 #include "feature/stats/rephist.h"
53 #include "lib/geoip/geoip.h"
54 
55 void evdns_shutdown(int);
56 
58 void
60 {
61  const or_options_t *options = get_options();
62  if (options->command == CMD_RUN_TOR) {
63  time_t now = time(NULL);
64  /* Remove our pid file. We don't care if there was an error when we
65  * unlink, nothing we could do about it anyways. */
66  tor_remove_file(options->PidFile);
67  /* Remove control port file */
69  /* Remove cookie authentication file */
70  {
71  char *cookie_fname = get_controller_cookie_file_name();
72  tor_remove_file(cookie_fname);
73  tor_free(cookie_fname);
74  }
75  /* Remove Extended ORPort cookie authentication file */
76  {
77  char *cookie_fname = get_ext_or_auth_cookie_file_name();
78  tor_remove_file(cookie_fname);
79  tor_free(cookie_fname);
80  }
81  if (accounting_is_enabled(options))
82  accounting_record_bandwidth_usage(now, get_or_state());
83  or_state_mark_dirty(get_or_state(), 0); /* force an immediate save. */
84  or_state_save(now);
85  if (authdir_mode(options)) {
86  sr_save_and_cleanup();
87  }
90  }
91 
93 
94  tor_free_all(0); /* We could move tor_free_all back into the ifdef below
95  later, if it makes shutdown unacceptably slow. But for
96  now, leave it here: it's helped us catch bugs in the
97  past. */
98 }
99 
108 void
109 tor_free_all(int postfork)
110 {
111  if (!postfork) {
112  evdns_shutdown(1);
113  }
114  geoip_free_all();
126  pt_free_all();
137  consdiffmgr_free_all();
138  hs_free_all();
139  dos_free_all();
143 
144  if (!postfork) {
145  config_free_all();
146  or_state_free_all();
147  }
148  if (!postfork) {
149 #ifndef _WIN32
150  tor_getpwnam(NULL);
151 #endif
152  }
153  /* stuff in main.c */
154 
155  tor_mainloop_disconnect_pubsub();
156 
157  if (!postfork) {
159  }
160 
161  subsystems_shutdown();
162 
163  /* Stuff in util.c and address.c*/
164  if (!postfork) {
165  esc_router_info(NULL);
166  }
167 }
void rep_hist_free_all(void)
Definition: rephist.c:2899
Header file for dirserv.c.
Header for statefile.c.
char * PidFile
Definition: or_options_st.h:71
int authdir_mode_tests_reachability(const or_options_t *options)
Definition: authmode.c:59
Header file for channeltls.c.
Header file containing common data for the whole HS subsytem.
Header file for circuitbuild.c.
Header file for control_auth.c.
void tor_cleanup(void)
Definition: shutdown.c:59
void routerparse_free_all(void)
Definition: routerparse.c:1242
Header file for geoip_stats.c.
Header file for connection.c.
void circuitmux_ewma_free_all(void)
int authdir_mode(const or_options_t *options)
Definition: authmode.c:25
Header file for nodelist.c.
Header file for shutdown.c.
const struct passwd * tor_getpwnam(const char *username)
Definition: userdb.c:70
Header file for config.c.
Header file for microdesc.c.
#define tor_free(p)
Definition: malloc.h:52
void bridges_free_all(void)
Definition: bridges.c:1025
Header file for geoip.c.
Header file for scheduler*.c.
char * get_controller_cookie_file_name(void)
Definition: control_auth.c:48
Header file for main.c.
void rend_service_authorization_free_all(void)
Definition: rendclient.c:1157
void accounting_free_all(void)
Definition: hibernate.c:1254
Header file for directory authority mode.
Header file for hibernate.c.
void rend_cache_free_all(void)
Definition: rendcache.c:233
void control_free_all(void)
Definition: control.c:571
enum or_options_t::@28 command
Header file for circuitpadding.c.
void scheduler_free_all(void)
Definition: scheduler.c:485
Header file for rendcache.c.
Header file for circuitbuild.c.
Master header file for Tor-specific functionality.
void dirserv_free_all(void)
Definition: dirserv.c:911
void release_lockfile(void)
Definition: main.c:721
char * ControlPortWriteToFile
Header file for rephist.c.
void circpad_machines_free(void)
void addressmap_free_all(void)
Definition: addressmap.c:329
void config_free_all(void)
Definition: config.c:1060
void entry_guards_free_all(void)
Definition: entrynodes.c:3812
Header file for circuitmux_ewma.c.
void timers_shutdown(void)
Definition: timers.c:232
Header file for circuitlist.c.
Headers for transports.c.
const char * esc_router_info(const routerinfo_t *router)
Definition: routerlist.c:3182
void channel_free_all(void)
Definition: channel.c:2243
Header file for connection_edge.c.
void circpad_free_all(void)
void microdesc_free_all(void)
Definition: microdesc.c:926
void nodelist_free_all(void)
Definition: nodelist.c:827
Header file for control.c.
void circuit_free_all(void)
Definition: circuitlist.c:1291
void channel_tls_free_all(void)
Definition: channeltls.c:295
void routerlist_free_all(void)
Definition: routerlist.c:1425
void or_state_mark_dirty(or_state_t *state, time_t when)
Definition: statefile.c:722
int rep_hist_record_mtbf_data(time_t now, int missing_means_down)
Definition: rephist.c:626
int or_state_save(time_t now)
Definition: statefile.c:500
void geoip_stats_free_all(void)
Definition: geoip_stats.c:1402
void networkstatus_free_all(void)
char * get_ext_or_auth_cookie_file_name(void)
Definition: ext_orport.c:127
int accounting_record_bandwidth_usage(time_t now, or_state_t *state)
Definition: hibernate.c:705
void pt_free_all(void)
Definition: transports.c:1754
void connection_free_all(void)
Definition: connection.c:5499
Header for compat_libevent.c.
Header file for rendclient.c.
void tor_remove_file(const char *filename)
Definition: main.c:734
Header file for networkstatus.c.
void tor_free_all(int postfork)
Definition: shutdown.c:109
Header file for routerlist.c.
Header file for routerparse.c.
void connection_edge_free_all(void)
void geoip_free_all(void)
Definition: geoip.c:504