From 9b432311c4d692d68f913027a95e050b1067c5d9 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Tue, 15 Nov 2005 03:05:23 +0000 Subject: [PATCH] Make new logging stuff work on windows; fix a couple of windows typos. svn:r5375 --- src/common/compat.c | 4 ++-- src/common/log.c | 20 ++++++++++---------- src/common/log.h | 14 +++++++++----- src/common/util.c | 4 ++-- src/or/circuituse.c | 12 ++++++------ src/or/main.c | 16 ++++++++-------- src/or/rendclient.c | 12 ++++++------ src/or/routerlist.c | 6 +++--- 8 files changed, 46 insertions(+), 42 deletions(-) diff --git a/src/common/compat.c b/src/common/compat.c index 69b58b619a..703011f6cf 100644 --- a/src/common/compat.c +++ b/src/common/compat.c @@ -757,7 +757,7 @@ get_uname(void) tor_snprintf(uname_result, sizeof(uname_result), "Unrecognized version of Windows [major=%d,minor=%d] %s", (int)info.dwMajorVersion,(int)info.dwMinorVersion, - infor.szCSDVersion); + info.szCSDVersion); } if (info.wProductType == VER_NT_DOMAIN_CONTROLLER) { strlcat(uname_result, " [domain controller]", sizeof(uname_result)); @@ -768,7 +768,7 @@ get_uname(void) } leftover_mask = info.wSuiteMask; for (i = 0; win_mask_table[i].mask; ++i) { - if (info.wSuiteMask & win_mask_table[i]) { + if (info.wSuiteMask & win_mask_table[i].mask) { strlcat(uname_result, win_mask_table[i].str, sizeof(uname_result)); leftover_mask &= ~win_mask_table[i].mask; } diff --git a/src/common/log.c b/src/common/log.c index 85cd04df44..3cb7b764cb 100644 --- a/src/common/log.c +++ b/src/common/log.c @@ -264,47 +264,47 @@ _log_fn(int severity, uint32_t domain, const char *format, ...) _log_fn_function_name = NULL; } void -_debug(uint32_t domain, const char *format, ...) +debug(uint32_t domain, const char *format, ...) { va_list ap; va_start(ap,format); - logv(LOG_DEBUG, domain, _log_fn_function_name, format, ap); + logv(LOG_DEBUG, domain, NULL, format, ap); va_end(ap); _log_fn_function_name = NULL; } void -_info(uint32_t domain, const char *format, ...) +info(uint32_t domain, const char *format, ...) { va_list ap; va_start(ap,format); - logv(LOG_INFO, domain, _log_fn_function_name, format, ap); + logv(LOG_INFO, domain, NULL, format, ap); va_end(ap); _log_fn_function_name = NULL; } void -_notice(uint32_t domain, const char *format, ...) +notice(uint32_t domain, const char *format, ...) { va_list ap; va_start(ap,format); - logv(LOG_NOTICE, domain, _log_fn_function_name, format, ap); + logv(LOG_NOTICE, domain, NULL, format, ap); va_end(ap); _log_fn_function_name = NULL; } void -_warn(uint32_t domain, const char *format, ...) +warn(uint32_t domain, const char *format, ...) { va_list ap; va_start(ap,format); - logv(LOG_WARN, domain, _log_fn_function_name, format, ap); + logv(LOG_WARN, domain, NULL, format, ap); va_end(ap); _log_fn_function_name = NULL; } void -_err(uint32_t domain, const char *format, ...) +err(uint32_t domain, const char *format, ...) { va_list ap; va_start(ap,format); - logv(LOG_ERR, domain, _log_fn_function_name, format, ap); + logv(LOG_ERR, domain, NULL, format, ap); va_end(ap); _log_fn_function_name = NULL; } diff --git a/src/common/log.h b/src/common/log.h index dd7dcbd9b7..40d66aab2a 100644 --- a/src/common/log.h +++ b/src/common/log.h @@ -138,20 +138,22 @@ void _log_fn(int severity, uint32_t domain, #else /* ! defined(__GNUC__) */ void _log_fn(int severity, uint32_t domain, const char *format, ...); -void _debug(uint32_t domain, const char *format, ...); -void _info(uint32_t domain, const char *format, ...); -void _notice(uint32_t domain, const char *format, ...); -void _warn(uint32_t domain, const char *format, ...); -void _err(uint32_t domain, const char *format, ...); +void debug(uint32_t domain, const char *format, ...); +void info(uint32_t domain, const char *format, ...); +void notice(uint32_t domain, const char *format, ...); +void warn(uint32_t domain, const char *format, ...); +void err(uint32_t domain, const char *format, ...); #if defined(_MSC_VER) && _MSC_VER < 1300 /* MSVC 6 and earlier don't have __FUNCTION__, or even __LINE__. */ #define log_fn _log_fn +/* #define debug _debug #define info _info #define notice _notice #define warn _warn #define err _err +*/ #else /* We don't have GCC's varargs macros, so use a global variable to pass the * function name to log_fn */ @@ -160,11 +162,13 @@ extern const char *_log_fn_function_name; * do {...} while (0) trick to wrap this macro, since the macro can't take * arguments. */ #define log_fn (_log_fn_function_name=__FUNCTION__),_log_fn +/* #define debug (_log_fn_function_name=__FUNCTION__),_debug #define info (_log_fn_function_name=__FUNCTION__),_info #define notice (_log_fn_function_name=__FUNCTION__),_notice #define warn (_log_fn_function_name=__FUNCTION__),_warn #define err (_log_fn_function_name=__FUNCTION__),_err +*/ #endif #endif /* !GNUC */ diff --git a/src/common/util.c b/src/common/util.c index dd289ff258..2d43f18600 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -433,7 +433,7 @@ find_whitespace(const char *s) err: \ if (ok) *ok = 0; \ if (next) *next = endptr; \ - return 0; + return 0 /** Extract a long from the start of s, in the given numeric base. If * there is unconverted data and next is provided, set *next to the @@ -1249,7 +1249,7 @@ tor_listdir(const char *dirname) smartlist_add(result, tor_strdup(findData.cFileName)); if (!FindNextFile(handle, &findData)) { if (GetLastError() != ERROR_NO_MORE_FILES) { - log_fn(LOG_WARN, "Error reading directory."); + warn(LD_FS, "Error reading directory."); } break; } diff --git a/src/or/circuituse.c b/src/or/circuituse.c index a7cf6ef340..d46537ace7 100644 --- a/src/or/circuituse.c +++ b/src/or/circuituse.c @@ -743,7 +743,7 @@ circuit_launch_by_router(uint8_t purpose, routerinfo_t *exit, * last hop need not be an exit node. Return the newly allocated circuit on * success, or NULL on failure. */ circuit_t * -circuit_launch_by_extend_info(uint8_t purpose, extend_info_t *info, +circuit_launch_by_extend_info(uint8_t purpose, extend_info_t *extend_info, int need_uptime, int need_capacity, int internal) { circuit_t *circ; @@ -753,10 +753,10 @@ circuit_launch_by_extend_info(uint8_t purpose, extend_info_t *info, return NULL; } - if ((info || purpose != CIRCUIT_PURPOSE_C_GENERAL) && + if ((extend_info || purpose != CIRCUIT_PURPOSE_C_GENERAL) && purpose != CIRCUIT_PURPOSE_TESTING) { /* see if there are appropriate circs available to cannibalize. */ - circ = circuit_find_to_cannibalize(CIRCUIT_PURPOSE_C_GENERAL, info, + circ = circuit_find_to_cannibalize(CIRCUIT_PURPOSE_C_GENERAL, extend_info, need_uptime, need_capacity, internal); if (circ) { info(LD_CIRC,"Cannibalizing circ '%s' for purpose %d", @@ -775,8 +775,8 @@ circuit_launch_by_extend_info(uint8_t purpose, extend_info_t *info, case CIRCUIT_PURPOSE_S_CONNECT_REND: case CIRCUIT_PURPOSE_C_GENERAL: /* need to add a new hop */ - tor_assert(info); - if (circuit_extend_to_new_exit(circ, info) < 0) + tor_assert(extend_info); + if (circuit_extend_to_new_exit(circ, extend_info) < 0) return NULL; break; default: @@ -796,7 +796,7 @@ circuit_launch_by_extend_info(uint8_t purpose, extend_info_t *info, } /* try a circ. if it fails, circuit_mark_for_close will increment n_circuit_failures */ - return circuit_establish_circuit(purpose, info, + return circuit_establish_circuit(purpose, extend_info, need_uptime, need_capacity, internal); } diff --git a/src/or/main.c b/src/or/main.c index 1bda2c0234..013965db77 100644 --- a/src/or/main.c +++ b/src/or/main.c @@ -1567,7 +1567,7 @@ nt_service_control(DWORD request) void nt_service_body(int argc, char **argv) { - int err; + int r; service_status.dwServiceType = SERVICE_WIN32_OWN_PROCESS; service_status.dwCurrentState = SERVICE_START_PENDING; service_status.dwControlsAccepted = @@ -1585,21 +1585,21 @@ nt_service_body(int argc, char **argv) // check for torrc if (nt_torrc_is_present()) { - err = tor_init(backup_argc, backup_argv); // refactor this part out of tor_main and do_main_loop - if (err) { - err = NT_SERVICE_ERROR_TORINIT_FAILED; + r = tor_init(backup_argc, backup_argv); // refactor this part out of tor_main and do_main_loop + if (r) { + r = NT_SERVICE_ERROR_TORINIT_FAILED; } } else { err(LD_CONFIG, "torrc is not in the current working directory. The Tor service will not start."); - err = NT_SERVICE_ERROR_NO_TORRC; + r = NT_SERVICE_ERROR_NO_TORRC; } - if (err) { + if (r) { // failed. service_status.dwCurrentState = SERVICE_STOPPED; - service_status.dwWin32ExitCode = err; - service_status.dwServiceSpecificExitCode = err; + service_status.dwWin32ExitCode = r; + service_status.dwServiceSpecificExitCode = r; SetServiceStatus(hStatus, &service_status); return; } diff --git a/src/or/rendclient.c b/src/or/rendclient.c index fd1af57aa4..07e8d02f24 100644 --- a/src/or/rendclient.c +++ b/src/or/rendclient.c @@ -216,10 +216,10 @@ rend_client_introduction_acked(circuit_t *circ, circ->rend_query) > 0) { /* There are introduction points left. Re-extend the circuit to * another intro point and try again. */ - extend_info_t *info; + extend_info_t *extend_info; int result; - info = rend_client_get_random_intro(circ->rend_query); - if (!info) { + extend_info = rend_client_get_random_intro(circ->rend_query); + if (!extend_info) { warn(LD_REND, "No introduction points left for %s. Closing.", safe_str(circ->rend_query)); circuit_mark_for_close(circ); @@ -229,9 +229,9 @@ rend_client_introduction_acked(circuit_t *circ, "Got nack for %s from %s. Re-extending circ %d, this time to %s.", safe_str(circ->rend_query), circ->build_state->chosen_exit->nickname, circ->n_circ_id, - info->nickname); - result = circuit_extend_to_new_exit(circ, info); - extend_info_free(info); + extend_info->nickname); + result = circuit_extend_to_new_exit(circ, extend_info); + extend_info_free(extend_info); return result; } } diff --git a/src/or/routerlist.c b/src/or/routerlist.c index e96ebc8ad7..8bb8fbbdb2 100644 --- a/src/or/routerlist.c +++ b/src/or/routerlist.c @@ -2348,12 +2348,12 @@ policy_includes_addr_mask_implicitly(addr_policy_t *policy, } /** If policy implicitly allows connections to any port on - * 127.*, 192.168.*, etc, then warn (if warn is set) and return + * 127.*, 192.168.*, etc, then warn (if should_warn is set) and return * true. Else return false. **/ int exit_policy_implicitly_allows_local_networks(addr_policy_t *policy, - int warn) + int should_warn) { addr_policy_t *p; int r=0,i; @@ -2372,7 +2372,7 @@ exit_policy_implicitly_allows_local_networks(addr_policy_t *policy, /* log_fn(LOG_INFO,"Checking network %s", private_networks[i].network); */ if (policy_includes_addr_mask_implicitly( policy, private_networks[i].addr, private_networks[i].mask, &p)) { - if (warn) + if (should_warn) warn(LD_CONFIG, "Exit policy %s implicitly accepts %s", p?p->string:"(default)", private_networks[i].network);