|
Tor 0.4.9.3-alpha-dev
|
Invocation module. Initializes subsystems and runs the main loop. More...
#include "core/or/or.h"#include "app/config/config.h"#include "app/config/statefile.h"#include "app/config/quiet_level.h"#include "app/main/main.h"#include "app/main/ntmain.h"#include "app/main/risky_options.h"#include "app/main/shutdown.h"#include "app/main/subsysmgr.h"#include "core/mainloop/connection.h"#include "core/mainloop/cpuworker.h"#include "core/mainloop/mainloop.h"#include "core/mainloop/mainloop_pubsub.h"#include "core/mainloop/netstatus.h"#include "core/or/channel.h"#include "core/or/channelpadding.h"#include "core/or/circuitpadding.h"#include "core/or/congestion_control_common.h"#include "core/or/congestion_control_flow.h"#include "core/or/circuitlist.h"#include "core/or/command.h"#include "core/or/connection_or.h"#include "core/or/relay.h"#include "core/or/status.h"#include "feature/api/tor_api.h"#include "feature/api/tor_api_internal.h"#include "feature/client/addressmap.h"#include "feature/control/control.h"#include "feature/control/control_auth.h"#include "feature/control/control_events.h"#include "feature/dirauth/keypin.h"#include "feature/dirauth/process_descs.h"#include "feature/dircache/consdiffmgr.h"#include "feature/dirparse/routerparse.h"#include "feature/hibernate/hibernate.h"#include "feature/hs/hs_dos.h"#include "feature/hs/hs_service.h"#include "feature/nodelist/authcert.h"#include "feature/nodelist/networkstatus.h"#include "feature/nodelist/routerlist.h"#include "feature/relay/dns.h"#include "feature/relay/ext_orport.h"#include "feature/relay/routerkeys.h"#include "feature/relay/routermode.h"#include "feature/stats/predict_ports.h"#include "feature/stats/bwhist.h"#include "feature/stats/rephist.h"#include "lib/compress/compress.h"#include "lib/buf/buffers.h"#include "lib/crypt_ops/crypto_format.h"#include "lib/crypt_ops/crypto_rand.h"#include "lib/crypt_ops/crypto_s2k.h"#include "lib/net/resolve.h"#include "lib/trace/trace.h"#include "lib/process/waitpid.h"#include "lib/pubsub/pubsub_build.h"#include "lib/meminfo/meminfo.h"#include "lib/osinfo/uname.h"#include "lib/osinfo/libc.h"#include "lib/sandbox/sandbox.h"#include "lib/fs/lockfile.h"#include "lib/tls/tortls.h"#include "lib/evloop/compat_libevent.h"#include "lib/encoding/confline.h"#include "lib/evloop/timers.h"#include "lib/crypt_ops/crypto_init.h"#include "lib/version/torversion.h"#include <event2/event.h>#include "feature/dirauth/authmode.h"#include "feature/dirauth/shared_random.h"#include "core/or/or_connection_st.h"#include "core/or/port_cfg_st.h"Go to the source code of this file.
Macros | |
| #define | UNIX_ONLY 1 |
| #define | OPEN(name) sandbox_cfg_allow_open_filename(&cfg, tor_strdup(name)) |
| #define | OPENDIR(dir) sandbox_cfg_allow_opendir_dirname(&cfg, tor_strdup(dir)) |
| #define | OPEN_DATADIR(name) sandbox_cfg_allow_open_filename(&cfg, get_datadir_fname(name)) |
| #define | OPEN_DATADIR2(name, name2) sandbox_cfg_allow_open_filename(&cfg, get_datadir_fname2((name), (name2))) |
| #define | OPEN_DATADIR_SUFFIX(name, suffix) |
| #define | OPEN_DATADIR2_SUFFIX(name, name2, suffix) |
| #define | OPEN_KEY_DIRECTORY() OPEN(options->KeyDirectory) |
| #define | OPEN_CACHEDIR(name) sandbox_cfg_allow_open_filename(&cfg, get_cachedir_fname(name)) |
| #define | OPEN_CACHEDIR_SUFFIX(name, suffix) |
| #define | OPEN_KEYDIR(name) sandbox_cfg_allow_open_filename(&cfg, get_keydir_fname(name)) |
| #define | OPEN_KEYDIR_SUFFIX(name, suffix) |
| #define | RENAME_SUFFIX(name, suffix) |
| #define | RENAME_SUFFIX2(prefix, name, suffix) |
| #define | RENAME_CACHEDIR_SUFFIX(name, suffix) |
| #define | RENAME_KEYDIR_SUFFIX(name, suffix) |
| #define | STAT_DATADIR(name) sandbox_cfg_allow_stat_filename(&cfg, get_datadir_fname(name)) |
| #define | STAT_CACHEDIR(name) sandbox_cfg_allow_stat_filename(&cfg, get_cachedir_fname(name)) |
| #define | STAT_DATADIR2(name, name2) sandbox_cfg_allow_stat_filename(&cfg, get_datadir_fname2((name), (name2))) |
| #define | STAT_KEY_DIRECTORY() sandbox_cfg_allow_stat_filename(&cfg, tor_strdup(options->KeyDirectory)) |
Functions | |
| static void | dumpmemusage (int severity) |
| static void | dumpstats (int severity) |
| static void | process_signal (int sig) |
| static int | do_hup (void) |
| static void | signal_callback (evutil_socket_t fd, short events, void *arg) |
| void | handle_signals (void) |
| void | activate_signal (int signal_num) |
| int | tor_init (int argc, char *argv[]) |
| 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) |
| static int | do_list_fingerprint (void) |
| static void | do_hash_password (void) |
| static int | do_dump_config (void) |
| static int | do_keygen_family (const char *fname_base) |
| static void | init_addrinfo (void) |
| static sandbox_cfg_t * | sandbox_init_filter (void) |
| int | run_tor_main_loop (void) |
| void | pubsub_install (void) |
| void | pubsub_connect (void) |
| int | tor_run_main (const tor_main_configuration_t *tor_cfg) |
Variables | ||
| struct { | ||
| int signal_value | ||
| int try_to_register | ||
| struct event * signal_event | ||
| } | signal_handlers [] | |
| static tor_lockfile_t * | lockfile = NULL | |
Invocation module. Initializes subsystems and runs the main loop.
Definition in file main.c.
| #define OPEN_CACHEDIR_SUFFIX | ( | name, | |
| suffix | |||
| ) |
| #define OPEN_DATADIR2_SUFFIX | ( | name, | |
| name2, | |||
| suffix | |||
| ) |
| #define OPEN_DATADIR_SUFFIX | ( | name, | |
| suffix | |||
| ) |
| #define OPEN_KEYDIR_SUFFIX | ( | name, | |
| suffix | |||
| ) |
| #define RENAME_CACHEDIR_SUFFIX | ( | name, | |
| suffix | |||
| ) |
| #define RENAME_KEYDIR_SUFFIX | ( | name, | |
| suffix | |||
| ) |
| #define RENAME_SUFFIX | ( | name, | |
| suffix | |||
| ) |
| #define RENAME_SUFFIX2 | ( | prefix, | |
| name, | |||
| suffix | |||
| ) |
|
static |
Entry point for configuration dumping: write the configuration to stdout.
Definition at line 805 of file main.c.
Referenced by tor_run_main().
|
static |
Entry point for password hashing: take the desired password from the command line, and print its salted hash to stdout.
Definition at line 787 of file main.c.
Referenced by tor_run_main().
|
static |
Called when we get a SIGHUP: reload configuration files and keys, retry all connections, and so on.
Definition at line 114 of file main.c.
Referenced by process_signal().
|
static |
Implement –keygen-family; create a family ID key and write it to a file.
Definition at line 837 of file main.c.
Referenced by tor_run_main().
|
static |
Read/create keys as needed, and echo our fingerprint to stdout.
Definition at line 733 of file main.c.
Referenced by tor_run_main().
|
static |
Write current memory usage information to the log.
Definition at line 319 of file main.c.
Referenced by dumpstats().
|
static |
Write all statistics to the log, with log level severity. Called in response to a SIGUSR1.
Definition at line 332 of file main.c.
Referenced by process_signal().
| void handle_signals | ( | void | ) |
| int have_lockfile | ( | void | ) |
Return true iff we've successfully acquired the lock file.
Definition at line 703 of file main.c.
Referenced by init_curve25519_keypair_from_file(), init_key_from_file(), and options_act().
|
static |
Do the work of acting on a signal received in sig
Definition at line 220 of file main.c.
Referenced by signal_callback().
| void pubsub_connect | ( | void | ) |
Connect the mainloop to its publish/subscribe message delivery events if appropriate, and configure the global channels appropriately.
Definition at line 1353 of file main.c.
Referenced by tor_run_main().
| void pubsub_install | ( | void | ) |
Install the publish/subscribe relationships for all the subsystems.
Definition at line 1341 of file main.c.
Referenced by tor_run_main().
| void release_lockfile | ( | void | ) |
If we have successfully acquired the lock file, release it.
Definition at line 710 of file main.c.
Referenced by tor_free_all().
|
static |
|
static |
Libevent callback: invoked when we get a signal.
Definition at line 207 of file main.c.
Referenced by handle_signals().
| int tor_init | ( | int | argc, |
| char * | argv[] | ||
| ) |
Main entry point for the Tor command-line client. Return 0 on "success", negative on "failure", and positive on "success and exit".
Definition at line 539 of file main.c.
Referenced by tor_run_main().
| void tor_remove_file | ( | const char * | filename | ) |
Remove the specified file, and log a warning if the operation fails for any reason other than the file not existing. Ignores NULL filenames.
Definition at line 723 of file main.c.
Referenced by tor_cleanup().
| int tor_run_main | ( | const tor_main_configuration_t * | tor_cfg | ) |
Run the tor process, as if from the command line.
The command line arguments from tor_main_configuration_set_command_line() are taken as if they had been passed to main().
This function will not return until Tor is done running. It returns zero on success, and nonzero on failure.
If you want to control when Tor exits, make sure to configure a control socket. The OwningControllerFD option may be helpful there.
BUG 23847: Sometimes, if you call tor_main a second time (after it has returned), Tor may crash or behave strangely. We have fixed all issues of this type that we could find, but more may remain.
LIMITATION: You cannot run more than one instance of Tor in the same process at the same time. Concurrent calls will cause undefined behavior. We do not currently have plans to change this.
LIMITATION: While we will try to fix any problems found here, you should be aware that Tor was originally written to run as its own process, and that the functionality of this file was added later. If you find any bugs or strange behavior, please report them, and we'll try to straighten them out.
| int try_locking | ( | const or_options_t * | options, |
| int | err_if_locked | ||
| ) |
Try to grab the lock file described in options, if we do not already have it. If err_if_locked is true, warn if somebody else is holding the lock, and exit if we can't get it after waiting. Otherwise, return -1 if we can't get the lockfile. Return 0 on success.
Definition at line 667 of file main.c.
Referenced by init_curve25519_keypair_from_file(), init_key_from_file(), options_act(), and try_locking().
|
static |
A lockfile structure, used to prevent two Tors from messing with the data directory at once. If this variable is non-NULL, we're holding the lockfile.
Definition at line 659 of file main.c.
Referenced by have_lockfile(), release_lockfile(), tor_lockfile_unlock(), and try_locking().
| struct event* signal_event |
Pointer to hold the event object constructed for this signal.
Definition at line 447 of file main.c.
Referenced by handle_signals().
| int signal_value |
A numeric code for this signal. Must match the signal value if try_to_register is true.
Definition at line 442 of file main.c.
Referenced by handle_signals().
| int try_to_register |
True if we should try to register this signal with libevent and catch corresponding posix signals. False otherwise.
Definition at line 445 of file main.c.
Referenced by handle_signals().