compat.c File Reference

Wrappers to make calls more portable. This code defines functions such as tor_malloc, tor_snprintf, get/set various data types, renaming, setting socket options, switching user IDs. It is basically where the non-portable items are conditionally included depending on the platform. More...

#include "compat.h"
#include <sys/utsname.h>
#include <unistd.h>
#include <sys/fcntl.h>
#include <pwd.h>
#include <grp.h>
#include <fcntl.h>
#include <errno.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <sys/param.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <signal.h>
#include <utime.h>
#include <sys/mman.h>
#include <sys/file.h>
#include "log.h"
#include "util.h"
#include "container.h"
#include "address.h"
#include "strlcpy.c"
#include "strlcat.c"

Data Structures

struct  tor_lockfile_t
struct  tor_pthread_data_t

Defines

#define _GNU_SOURCE
#define SEEK_CUR   1
#define SEEK_END   2
#define mark_socket_open(s)   STMT_NIL
#define ULIMIT_BUFFER   32
#define CREDENTIAL_LOG_LEVEL   LOG_INFO
#define TIME_FNS_NEED_LOCKS

Functions

tor_mmap_ttor_mmap_file (const char *filename)
void tor_munmap_file (tor_mmap_t *handle)
int tor_snprintf (char *str, size_t size, const char *format,...)
int tor_vsnprintf (char *str, size_t size, const char *format, va_list args)
int tor_asprintf (char **strp, const char *fmt,...)
int tor_vasprintf (char **strp, const char *fmt, va_list args)
const void * tor_memmem (const void *_haystack, size_t hlen, const void *_needle, size_t nlen)
char * tor_strtok_r_impl (char *str, const char *sep, char **lasts)
uint16_t get_uint16 (const char *cp)
uint32_t get_uint32 (const char *cp)
uint64_t get_uint64 (const char *cp)
void set_uint16 (char *cp, uint16_t v)
void set_uint32 (char *cp, uint32_t v)
void set_uint64 (char *cp, uint64_t v)
int replace_file (const char *from, const char *to)
int touch_file (const char *fname)
tor_lockfile_ttor_lockfile_lock (const char *filename, int blocking, int *locked_out)
void tor_lockfile_unlock (tor_lockfile_t *lockfile)
off_t tor_fd_getpos (int fd)
int tor_fd_seekend (int fd)
static INLINE void socket_accounting_lock (void)
static INLINE void socket_accounting_unlock (void)
int tor_close_socket (int s)
int tor_open_socket (int domain, int type, int protocol)
int tor_accept_socket (int sockfd, struct sockaddr *addr, socklen_t *len)
int get_n_open_sockets (void)
void set_socket_nonblocking (int socket)
int tor_socketpair (int family, int type, int protocol, int fd[2])
int set_max_file_descriptors (rlim_t limit, int *max_out)
static int log_credential_status (void)
int switch_id (const char *user)
char * get_user_homedir (const char *username)
int tor_inet_aton (const char *str, struct in_addr *addr)
const char * tor_inet_ntop (int af, const void *src, char *dst, size_t len)
int tor_inet_pton (int af, const char *src, void *dst)
int tor_lookup_hostname (const char *name, uint32_t *addr)
const char * get_uname (void)
static void * tor_pthread_helper_fn (void *_data)
int spawn_func (void(*func)(void *), void *data)
void spawn_exit (void)
void tor_gettimeofday (struct timeval *timeval)
void tor_mutex_init (tor_mutex_t *mutex)
void tor_mutex_acquire (tor_mutex_t *m)
void tor_mutex_release (tor_mutex_t *m)
void tor_mutex_uninit (tor_mutex_t *m)
unsigned long tor_get_thread_id (void)
tor_mutex_ttor_mutex_new (void)
void tor_mutex_free (tor_mutex_t *m)
void tor_threads_init (void)
int tor_mlockall (void)
void set_main_thread (void)
int in_main_thread (void)
int network_init (void)

Variables

const uint32_t TOR_ISALPHA_TABLE [8]
const uint32_t TOR_ISALNUM_TABLE [8]
const uint32_t TOR_ISSPACE_TABLE [8] = { 0x3e00, 0x1, 0, 0, 0, 0, 0, 0 }
const uint32_t TOR_ISXDIGIT_TABLE [8]
const uint32_t TOR_ISDIGIT_TABLE [8] = { 0, 0x3ff0000, 0, 0, 0, 0, 0, 0 }
const uint32_t TOR_ISPRINT_TABLE [8]
const uint32_t TOR_ISUPPER_TABLE [8] = { 0, 0, 0x7fffffe, 0, 0, 0, 0, 0 }
const uint32_t TOR_ISLOWER_TABLE [8] = { 0, 0, 0, 0x7fffffe, 0, 0, 0, 0 }
const char TOR_TOUPPER_TABLE [256]
const char TOR_TOLOWER_TABLE [256]
static int n_sockets_open = 0
static tor_mutex_tsocket_accounting_mutex = NULL
static char uname_result [256]
static int uname_result_is_set = 0
static pthread_mutexattr_t attr_reentrant
static int threads_initialized = 0
static unsigned long main_thread_id = -1


Detailed Description

Wrappers to make calls more portable. This code defines functions such as tor_malloc, tor_snprintf, get/set various data types, renaming, setting socket options, switching user IDs. It is basically where the non-portable items are conditionally included depending on the platform.


Define Documentation

#define TIME_FNS_NEED_LOCKS

Defined iff we need to add locks when defining fake versions of reentrant versions of time-related functions.


Function Documentation

int get_n_open_sockets ( void   ) 

Return the number of sockets we currently have opened.

Referenced by connection_connect(), connection_create_listener(), and warn_too_many_conns().

uint16_t get_uint16 ( const char *  cp  ) 

Read a 16-bit value beginning at cp. Equivalent to *(uint16_t*)(cp), but will not cause segfaults on platforms that forbid unaligned memory access.

Referenced by circuit_extend(), command_process_versions_cell(), detect_compression_method(), fetch_from_buf_socks(), fetch_var_cell_from_buf(), peek_buf_has_control0_command(), relay_header_unpack(), rend_mid_establish_intro(), rend_parse_service_descriptor(), rend_service_introduce(), and tag_unpack().

uint32_t get_uint32 ( const char *  cp  ) 

uint64_t get_uint64 ( const char *  cp  ) 

Read a 64-bit value beginning at cp. Equivalent to *(uint64_t*)(cp), but will not cause segfaults on platforms that forbid unaligned memory access.

Referenced by tag_unpack().

const char* get_uname ( void   ) 

Return a pointer to a description of our platform.

References tor_snprintf().

Referenced by get_platform_str(), options_validate(), and tor_init().

char* get_user_homedir ( const char *  username  ) 

Allocate and return a string containing the home directory for the user username. Only works on posix-like systems.

References LD_CONFIG, and tor_assert.

Referenced by expand_filename().

int in_main_thread ( void   ) 

Return true iff called from the main thread.

References tor_get_thread_id().

Referenced by control_event_logmsg().

static int log_credential_status ( void   )  [static]

Log details of current user and group credentials. Return 0 on success. Logs and return -1 on failure.

References LD_GENERAL, smartlist_add(), smartlist_create(), smartlist_free(), smartlist_join_strings(), tor_free, and tor_snprintf().

Referenced by switch_id().

int network_init ( void   ) 

On Windows, WSAEWOULDBLOCK is not always correct: when you see it, you need to ask the socket for its actual errno. Also, you need to get your errors from WSAGetLastError, not errno. (If you supply a socket of -1, we check WSAGetLastError, but don't correct WSAEWOULDBLOCKs.)

The upshot of all of this is that when a socket call fails, you should call tor_socket_errno at most once on the failing socket to get the error. Called before we make any calls to network-related functions. (Some operating systems require their network libraries to be initialized.)

References LD_NET.

Referenced by tor_init().

int replace_file ( const char *  from,
const char *  to 
)

Rename the file from to the file to. On Unix, this is the same as rename(2). On windows, this removes to first if it already exists. Returns 0 on success. Returns -1 and sets errno on failure.

References file_status().

Referenced by finish_writing_to_file_impl(), rotate_onion_key(), and router_rebuild_store().

void set_main_thread ( void   ) 

Start considering the current thread to be the 'main thread'. This has no effect on anything besides in_main_thread().

References tor_get_thread_id().

Referenced by start_daemon(), and tor_threads_init().

int set_max_file_descriptors ( rlim_t  limit,
int *  max_out 
)

Learn the maximum allowed number of file descriptors. (Some systems have a low soft limit.

We compute this by finding the largest number that we can use. If we can't find a number greater than or equal to limit, then we fail: return -1.

Otherwise, return 0 and store the maximum we found inside max_out.

References LD_CONFIG, LD_NET, and tor_assert.

Referenced by options_act_reversible().

void set_socket_nonblocking ( int  socket  ) 

Turn socket into a nonblocking socket.

Referenced by connection_connect(), connection_create_listener(), connection_handle_listener_read(), and spawn_cpuworker().

void set_uint16 ( char *  cp,
uint16_t  v 
)

Set a 16-bit value beginning at cp to v. Equivalent to *(uint16_t*)(cp) = v, but will not cause segfaults on platforms that forbid unaligned memory access.

Referenced by circuit_send_next_onion_skin(), connection_ap_handshake_socks_resolved(), connection_control_process_inbuf(), connection_or_send_versions(), relay_header_pack(), rend_service_intro_has_opened(), tag_pack(), and var_cell_pack_header().

void set_uint32 ( char *  cp,
uint32_t  v 
)

Set a 32-bit value beginning at cp to v. Equivalent to *(uint32_t*)(cp) = v, but will not cause segfaults on platforms that forbid unaligned memory access.

Referenced by circuit_send_next_onion_skin(), connection_edge_end(), connection_edge_finished_connecting(), connection_exit_connect(), connection_or_send_netinfo(), send_resolved_cell(), and send_resolved_hostname_cell().

void set_uint64 ( char *  cp,
uint64_t  v 
)

Set a 64-bit value beginning at cp to v. Equivalent to *(uint64_t*)(cp) = v, but will not cause segfaults on platforms that forbid unaligned memory access.

Referenced by tag_pack().

void spawn_exit ( void   ) 

End the current thread/process.

References tor_assert.

Referenced by cpuworker_main().

int spawn_func ( void(*)(void *)  func,
void *  data 
)

Minimalist interface to run a void function in the background. On Unix calls fork, on win32 calls beginthread. Returns -1 on failure. func should not return, but rather should call spawn_exit.

NOTE: if data is used, it should not be allocated on the stack, since in a multithreaded environment, there is no way to be sure that the caller's stack will still be around when the called function is running.

References tor_pthread_data_t::data, tor_pthread_data_t::func, tor_assert, and tor_pthread_helper_fn().

Referenced by spawn_cpuworker().

int switch_id ( const char *  user  ) 

Call setuid and setgid to run as user and switch to their primary group. Return 0 on success. On failure, log and return -1.

References LD_CONFIG, LD_GENERAL, log_credential_status(), and tor_assert.

Referenced by options_act_reversible().

int tor_accept_socket ( int  sockfd,
struct sockaddr *  addr,
socklen_t *  len 
)

As socket(), but counts the number of open sockets.

Referenced by connection_handle_listener_read(), and tor_socketpair().

int tor_asprintf ( char **  strp,
const char *  fmt,
  ... 
)

Portable asprintf implementation. Does a printf() into a newly malloc'd string. Sets *strp to this string, and returns its length (not including the terminating NUL character).

You can treat this function as if its implementation were something like

     char buf[_INFINITY_];
     tor_snprintf(buf, sizeof(buf), fmt, args);
strp = tor_strdup(buf);
     return strlen(*strp):
   
Where _INFINITY_ is an imaginary constant so big that any string can fit into it.

References LD_BUG, tor_assert, and tor_vasprintf().

Referenced by check_nickname_list(), circuit_list_path_impl(), config_assign_line(), config_assign_value(), config_dump(), ensure_bandwidth_cap(), geoip_get_client_history(), geoip_get_request_history(), get_assigned_option(), getinfo_helper_config(), list_getinfo_options(), log_entry_guards(), networkstatus_compute_consensus(), options_act_reversible(), options_init_from_string(), options_transition_allowed(), options_validate(), or_state_save(), parse_bridge_stats_controller(), rep_hist_buffer_stats_write(), rep_hist_format_router_status(), validate_ports_csv(), and write_configuration_file().

int tor_close_socket ( int  s  ) 

As close(), but guaranteed to work for sockets across platforms (including Windows, where close()ing a socket doesn't work. Returns 0 on success, -1 on failure.

References LD_BUG, LD_NET, and tor_assert.

Referenced by _connection_free(), connection_close_immediate(), connection_connect(), connection_create_listener(), connection_handle_listener_read(), cpuworker_main(), get_interface_address6(), spawn_cpuworker(), and tor_socketpair().

off_t tor_fd_getpos ( int  fd  ) 

Return the position of fd with respect to the start of the file.

Referenced by log_tor_version().

int tor_fd_seekend ( int  fd  ) 

Move fd to the end of the file. Return -1 on error, 0 on success.

Referenced by add_file_log(), and start_writing_to_file().

unsigned long tor_get_thread_id ( void   ) 

Return an integer representing this thread.

Referenced by in_main_thread(), set_main_thread(), and setup_openssl_threading().

void tor_gettimeofday ( struct timeval *  timeval  ) 

Set *timeval to the current time of day. On error, log and terminate. (Same as gettimeofday(timeval,NULL), but never returns -1.)

References LD_GENERAL.

Referenced by _log_prefix(), circuit_send_next_onion_skin(), geoip_change_dirreq_state(), geoip_get_dirreq_history(), geoip_start_dirreq(), and init_circuit_base().

int tor_inet_aton ( const char *  str,
struct in_addr *  addr 
)

const char* tor_inet_ntop ( int  af,
const void *  src,
char *  dst,
size_t  len 
)

Given af==AF_INET and src a struct in_addr, or af==AF_INET6 and src a struct in6_addr, try to format the address and store it in the len-byte buffer dst. Returns dst on success, NULL on failure.

(Like inet_ntop(af,src,dst,len), but works on platforms that don't have it: Tor sometimes needs to format ipv6 addresses even on platforms without ipv6 support.)

References tor_inet_ntoa(), and tor_snprintf().

Referenced by tor_addr_to_str(), and tor_dup_ip().

int tor_inet_pton ( int  af,
const char *  src,
void *  dst 
)

Given af==AF_INET or af==AF_INET6, and a string src encoding an IPv4 address or IPv6 address correspondingly, try to parse the address and store the result in dst (which must have space for a struct in_addr or a struct in6_addr, as appropriate). Return 1 on success, 0 on a bad parse, and -1 on a bad af.

(Like inet_pton(af,src,dst) but works on platforms that don't have it: Tor sometimes needs to format ipv6 addresses even on platforms without ipv6 support.)

References tor_assert, tor_inet_aton(), and tor_sscanf().

Referenced by tor_addr_from_str(), tor_addr_lookup(), and tor_addr_parse_mask_ports().

tor_lockfile_t* tor_lockfile_lock ( const char *  filename,
int  blocking,
int *  locked_out 
)

Try to get a lock on the lockfile filename, creating it as necessary. If someone else has the lock and blocking is true, wait until the lock is available. Otherwise return immediately whether we succeeded or not.

Set *locked_out to true if somebody else had the lock, and to false otherwise.

Return a tor_lockfile_t on success, NULL on failure.

(Implementation note: because we need to fall back to fcntl on some platforms, these locks are per-process, not per-thread. If you want to do in-process locking, use tor_mutex_t like a normal person.)

References tor_lockfile_t::fd, tor_lockfile_t::filename, and LD_FS.

Referenced by try_locking().

void tor_lockfile_unlock ( tor_lockfile_t lockfile  ) 

Release the lock held as lockfile.

References tor_lockfile_t::fd, tor_lockfile_t::filename, LD_FS, tor_assert, and tor_free.

Referenced by release_lockfile().

int tor_lookup_hostname ( const char *  name,
uint32_t *  addr 
)

Similar behavior to Unix gethostbyname: resolve name, and set *addr to the proper IP address, in host byte order. Returns 0 on success, -1 on failure; 1 on transient failure.

(This function exists because standard windows gethostbyname doesn't treat raw IP addresses properly.)

References tor_addr_family(), tor_addr_lookup(), and tor_addr_to_ipv4h().

Referenced by add_trusted_dir_server(), parse_addr_port(), and resolve_my_address().

const void* tor_memmem ( const void *  _haystack,
size_t  hlen,
const void *  _needle,
size_t  nlen 
)

Given hlen bytes at haystack and nlen bytes at needle, return a pointer to the first occurrence of the needle within the haystack, or NULL if there is no such occurrence.

Requires that nlen be greater than zero.

References tor_assert.

int tor_mlockall ( void   ) 

Attempt to lock all current and all future memory pages. This should only be called once and while we're privileged. Like mlockall() we return 0 when we're successful and -1 when we're not. Unlike mlockall() we return 1 if we've already attempted to lock memory.

References LD_GENERAL.

Referenced by options_act_reversible().

tor_mmap_t* tor_mmap_file ( const char *  filename  ) 

Try to create a memory mapping for filename and return it. On failure, return NULL. Sets errno properly, using ERANGE to mean "empty file".

References tor_mmap_t::data, LD_FS, tor_mmap_t::mapping_size, tor_mmap_t::size, and tor_assert.

Referenced by microdesc_cache_rebuild(), microdesc_cache_reload(), router_rebuild_store(), and router_reload_router_list_impl().

void tor_munmap_file ( tor_mmap_t handle  ) 

void tor_mutex_acquire ( tor_mutex_t m  ) 

void tor_mutex_free ( tor_mutex_t m  ) 

Release all storage and system resources held by m.

References tor_free, and tor_mutex_uninit().

Referenced by _openssl_dynlock_destroy_cb(), crypto_global_cleanup(), and router_free_all().

void tor_mutex_init ( tor_mutex_t mutex  ) 

Initialize mutex so it can be locked. Every mutex must be set up with tor_mutex_init() or tor_mutex_new(); not both.

References LD_GENERAL, tor_mutex_t::mutex, tor_fragile_assert, and tor_threads_init().

Referenced by init_logging(), and tor_mutex_new().

tor_mutex_t* tor_mutex_new ( void   ) 

Return a newly allocated, ready-for-use mutex.

References tor_mutex_init().

Referenced by _openssl_dynlock_create_cb(), init_keys(), and setup_openssl_threading().

void tor_mutex_release ( tor_mutex_t m  ) 

Release the lock m so another thread can have it.

References LD_GENERAL, tor_mutex_t::mutex, tor_assert, and tor_fragile_assert.

Referenced by _openssl_dynlock_lock_cb(), _openssl_locking_cb(), dup_onion_keys(), rotate_onion_key(), and set_onion_key().

void tor_mutex_uninit ( tor_mutex_t m  ) 

Clean up the mutex m so that it no longer uses any system resources. Does not free m. This function must only be called on mutexes from tor_mutex_init().

References LD_GENERAL, tor_mutex_t::mutex, tor_assert, and tor_fragile_assert.

Referenced by tor_mutex_free().

int tor_open_socket ( int  domain,
int  type,
int  protocol 
)

As socket(), but counts the number of open sockets.

Referenced by connection_connect(), connection_create_listener(), get_interface_address6(), and tor_socketpair().

static void* tor_pthread_helper_fn ( void *  _data  )  [static]

Given a tor_pthread_data_t _data, call _data->func(d->data) and free _data. Used to make sure we can call functions the way pthread expects.

References tor_pthread_data_t::data, tor_pthread_data_t::func, and tor_free.

Referenced by spawn_func().

int tor_snprintf ( char *  str,
size_t  size,
const char *  format,
  ... 
)

Replacement for snprintf. Differs from platform snprintf in two ways: First, always NUL-terminates its output. Second, always returns -1 if the result is truncated. (Note that this return behavior does not conform to C99; it just happens to be easier to emulate "return -1" with conformant implementations than it is to emulate "return number that would be written" with non-conformant implementations.)

References tor_vsnprintf().

Referenced by _log_prefix(), add_trusted_dir_server(), addressmap_get_mappings(), addressmap_rewrite_reverse(), circuit_build_times_update_state(), circuit_list_path_impl(), circuit_purpose_to_controller_string(), circuit_state_to_string(), clear_trackexithost_mappings(), client_dns_set_addressmap_impl(), client_dns_set_reverse_addressmap(), conn_state_to_string(), conn_type_to_string(), connection_ap_handshake_send_begin(), connection_proxy_connect(), control_event_bootstrap(), control_event_bootstrap_problem(), control_event_circuit_status(), control_event_descriptors_changed(), control_event_guard(), control_event_or_authdir_new_descriptor(), control_event_or_conn_status(), control_event_status(), control_event_stream_status(), control_setconf_helper(), directory_get_consensus_url(), directory_send_command(), dirserv_add_multiple_descriptors(), dirserv_dump_directory_to_string(), dirvote_compute_params(), dirvote_create_microdescriptor(), dirvote_format_microdesc_vote_line(), dump_desc(), entry_guards_update_state(), esc_for_log(), esc_router_info(), expand_filename(), extrainfo_dump_to_string(), format_msg(), format_networkstatus_vote(), format_time_interval(), generate_runningrouters(), generate_v2_networkstatus_opinion(), geoip_bridge_stats_write(), geoip_get_dirreq_history(), get_next_token(), get_platform_str(), get_uname(), get_version(), getinfo_helper_accounting(), getinfo_helper_entry_guards(), getinfo_helper_events(), handle_control_getconf(), handle_control_mapaddress(), inform_testing_reachability(), init_keys(), load_downloaded_routers(), log_credential_status(), log_tor_version(), lookup_last_hid_serv_request(), make_consensus_method_list(), networkstatus_dump_bridge_status_to_file(), networkstatus_format_signatures(), networkstatus_get_detached_signatures(), networkstatus_set_current_consensus(), options_act(), options_act_reversible(), options_get_datadir_fname2_suffix(), options_validate(), or_state_load(), orconn_target_get_name(), policies_parse_exit_policy(), policy_summarize(), policy_write_item(), remove_obsolete_entry_guards(), rend_cache_lookup_entry(), rend_cache_store(), rend_cache_store_v2_desc_as_client(), rend_encode_v2_descriptors(), rend_encode_v2_intro_points(), rend_parse_service_authorization(), rend_service_load_keys(), rep_hist_dump_stats(), rep_hist_fill_bandwidth_history(), rep_hist_get_bandwidth_lines(), rep_hist_get_router_stability_doc(), rep_hist_update_state(), router_dump_router_to_string(), router_load_single_router(), router_parse_addr_policy_item_from_string(), router_reload_consensus_networkstatus(), routerstatus_format_entry(), routerstatus_parse_entry_from_string(), smartlist_string_num_isin(), ssl_state_to_string(), start_writing_to_file(), token_check_object(), tor_addr_to_reverse_lookup_name(), tor_inet_ntoa(), tor_inet_ntop(), tor_init(), tor_listdir(), update_router_have_minimum_dir_info(), vote_routerstatus_find_microdesc_hash(), write_configuration_file(), write_http_response_header_impl(), write_http_status_line(), and write_stream_target_to_buf().

int tor_socketpair ( int  family,
int  type,
int  protocol,
int  fd[2] 
)

Allocate a pair of connected sockets. (Like socketpair(family, type,protocol,fd), but works on systems that don't have socketpair.)

Currently, only (AF_UNIX, SOCK_STREAM, 0) sockets are supported.

Note that on systems without socketpair, this call will fail if localhost is inaccessible (for example, if the networking stack is down). And even if it succeeds, the socket pair will not be able to read while localhost is down later (the socket pair may even close, depending on OS-specific timeouts).

Returns 0 on success and -errno on failure; do not rely on the value of errno or WSAGetLastError().

References tor_accept_socket(), tor_close_socket(), and tor_open_socket().

Referenced by spawn_cpuworker().

char* tor_strtok_r_impl ( char *  str,
const char *  sep,
char **  lasts 
)

Implementation of strtok_r for platforms whose coders haven't figured out how to write one. Hey guys! You can use this code here for free!

References tor_assert.

void tor_threads_init ( void   ) 

Set up common structures for use by threading.

References set_main_thread().

Referenced by tor_main(), and tor_mutex_init().

int tor_vasprintf ( char **  strp,
const char *  fmt,
va_list  args 
)

Portable vasprintf implementation. Does a printf() into a newly malloc'd string. Differs from regular vasprintf in the same ways that tor_asprintf() differs from regular asprintf.

References tor_free.

Referenced by tor_asprintf().

int tor_vsnprintf ( char *  str,
size_t  size,
const char *  format,
va_list  args 
)

Replacement for vsnprintf; behavior differs as tor_snprintf differs from snprintf.

Referenced by connection_printf_to_buf(), format_msg(), send_control_event_impl(), and tor_snprintf().

int touch_file ( const char *  fname  ) 

Change fname's modification time to now.

Referenced by router_set_networkstatus_v2().


Variable Documentation

pthread_mutexattr_t attr_reentrant [static]

A mutex attribute that we're going to use to tell pthreads that we want "reentrant" mutexes (i.e., once we can re-lock if we're already holding them.)

unsigned long main_thread_id = -1 [static]

Identity of the "main" thread

int n_sockets_open = 0 [static]

Count of number of sockets currently open. (Undercounts sockets opened by eventdns and libevent.)

Mutex to protect open_sockets, max_socket, and n_sockets_open.

int threads_initialized = 0 [static]

True iff we've called tor_threads_init()

const uint32_t TOR_ISALNUM_TABLE[8]

Initial value:

  { 0, 0x3ff0000, 0x7fffffe, 0x7fffffe, 0, 0, 0, 0 }

const uint32_t TOR_ISALPHA_TABLE[8]

Initial value:

  { 0, 0, 0x7fffffe, 0x7fffffe, 0, 0, 0, 0 }

const uint32_t TOR_ISPRINT_TABLE[8]

Initial value:

  { 0, 0xffffffff, 0xffffffff, 0x7fffffff, 0, 0, 0, 0x0 }

const uint32_t TOR_ISXDIGIT_TABLE[8]

Initial value:

  { 0, 0x3ff0000, 0x7e, 0x7e, 0, 0, 0, 0 }

const char TOR_TOLOWER_TABLE[256]

Initial value:

 {
  0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
  16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,
  32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,
  48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,
  64,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,
  112,113,114,115,116,117,118,119,120,121,122,91,92,93,94,95,
  96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,
  112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,
  128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,
  144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,
  160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,
  176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,
  192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,
  208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,
  224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,
  240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,
}

const char TOR_TOUPPER_TABLE[256]

Initial value:

 {
  0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
  16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,
  32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,
  48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,
  64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,
  80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,
  96,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,
  80,81,82,83,84,85,86,87,88,89,90,123,124,125,126,127,
  128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,
  144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,
  160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,
  176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,
  192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,
  208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,
  224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,
  240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,
}

char uname_result[256] [static]

Hold the result of our call to uname.

int uname_result_is_set = 0 [static]

True iff uname_result is set.


Generated on Tue May 25 00:30:40 2010 for tor by  doxygen 1.5.6