mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-10 21:23:58 +01:00
Start dividing log messages into logging domains. No, LD_ is not the best of identifiers. src/or has not been converted yet. Domains dont do anything yet.
svn:r5284
This commit is contained in:
parent
102df4a982
commit
edf5698474
@ -354,7 +354,7 @@ tor_socketpair(int family, int type, int protocol, int fd[2])
|
||||
if (listener == -1)
|
||||
return -tor_socket_errno(-1);
|
||||
if (!SOCKET_IS_POLLABLE(listener)) {
|
||||
log_fn(LOG_WARN, "Too many connections; can't open socketpair");
|
||||
warn(LD_NET, "Too many connections; can't open socketpair");
|
||||
tor_close_socket(listener);
|
||||
#ifdef MS_WINDOWS
|
||||
return -ENFILE;
|
||||
@ -376,7 +376,7 @@ tor_socketpair(int family, int type, int protocol, int fd[2])
|
||||
if (connector == -1)
|
||||
goto tidy_up_and_fail;
|
||||
if (!SOCKET_IS_POLLABLE(connector)) {
|
||||
log_fn(LOG_WARN, "Too many connections; can't open socketpair");
|
||||
warn(LD_NET, "Too many connections; can't open socketpair");
|
||||
goto tidy_up_and_fail;
|
||||
}
|
||||
/* We want to find out the port number to connect to. */
|
||||
@ -394,7 +394,7 @@ tor_socketpair(int family, int type, int protocol, int fd[2])
|
||||
if (acceptor == -1)
|
||||
goto tidy_up_and_fail;
|
||||
if (!SOCKET_IS_POLLABLE(acceptor)) {
|
||||
log_fn(LOG_WARN, "Too many connections; can't open socketpair");
|
||||
warn(LD_NET, "Too many connections; can't open socketpair");
|
||||
goto tidy_up_and_fail;
|
||||
}
|
||||
if (size != sizeof(listen_addr))
|
||||
@ -443,9 +443,10 @@ int
|
||||
set_max_file_descriptors(unsigned long limit, unsigned long cap)
|
||||
{
|
||||
#ifndef HAVE_GETRLIMIT
|
||||
log_fn(LOG_INFO,"This platform is missing getrlimit(). Proceeding.");
|
||||
log_fn(LOG_INFO, LD_NET,
|
||||
"This platform is missing getrlimit(). Proceeding.");
|
||||
if (limit > cap) {
|
||||
log(LOG_INFO, "ConnLimit must be at most %d. Capping it.", cap);
|
||||
log(LOG_INFO, LD_CONFIG, "ConnLimit must be at most %d. Capping it.", cap);
|
||||
limit = cap;
|
||||
}
|
||||
#else
|
||||
@ -455,22 +456,22 @@ set_max_file_descriptors(unsigned long limit, unsigned long cap)
|
||||
tor_assert(cap > 0);
|
||||
|
||||
if (getrlimit(RLIMIT_NOFILE, &rlim) != 0) {
|
||||
log_fn(LOG_WARN, "Could not get maximum number of file descriptors: %s",
|
||||
warn(LD_NET, "Could not get maximum number of file descriptors: %s",
|
||||
strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
if (rlim.rlim_max < limit) {
|
||||
log_fn(LOG_WARN,"We need %lu file descriptors available, and we're limited to %lu. Please change your ulimit -n.", limit, (unsigned long)rlim.rlim_max);
|
||||
warn(LD_CONFIG,"We need %lu file descriptors available, and we're limited to %lu. Please change your ulimit -n.", limit, (unsigned long)rlim.rlim_max);
|
||||
return -1;
|
||||
}
|
||||
most = (rlim.rlim_max > cap) ? cap : (unsigned) rlim.rlim_max;
|
||||
if (most > rlim.rlim_cur) {
|
||||
log_fn(LOG_INFO,"Raising max file descriptors from %lu to %lu.",
|
||||
info(LD_NET,"Raising max file descriptors from %lu to %lu.",
|
||||
(unsigned long)rlim.rlim_cur, most);
|
||||
}
|
||||
rlim.rlim_cur = most;
|
||||
if (setrlimit(RLIMIT_NOFILE, &rlim) != 0) {
|
||||
log_fn(LOG_WARN, "Could not set maximum number of file descriptors: %s",
|
||||
warn(LD_CONFIG, "Could not set maximum number of file descriptors: %s",
|
||||
strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
@ -479,7 +480,7 @@ set_max_file_descriptors(unsigned long limit, unsigned long cap)
|
||||
#endif
|
||||
|
||||
if (limit < ULIMIT_BUFFER) {
|
||||
log_fn(LOG_WARN,"ConnLimit must be at least %d. Failing.", ULIMIT_BUFFER);
|
||||
warn(LD_CONFIG,"ConnLimit must be at least %d. Failing.", ULIMIT_BUFFER);
|
||||
return -1;
|
||||
}
|
||||
return limit - ULIMIT_BUFFER;
|
||||
@ -498,7 +499,7 @@ switch_id(char *user, char *group)
|
||||
if (user) {
|
||||
pw = getpwnam(user);
|
||||
if (pw == NULL) {
|
||||
log_fn(LOG_ERR,"User '%s' not found.", user);
|
||||
err("User '%s' not found.", user);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@ -507,17 +508,17 @@ switch_id(char *user, char *group)
|
||||
if (group) {
|
||||
gr = getgrnam(group);
|
||||
if (gr == NULL) {
|
||||
log_fn(LOG_ERR,"Group '%s' not found.", group);
|
||||
err("Group '%s' not found.", group);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (setgid(gr->gr_gid) != 0) {
|
||||
log_fn(LOG_ERR,"Error setting GID: %s", strerror(errno));
|
||||
err("Error setting GID: %s", strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
} else if (user) {
|
||||
if (setgid(pw->pw_gid) != 0) {
|
||||
log_fn(LOG_ERR,"Error setting GID: %s", strerror(errno));
|
||||
err("Error setting GID: %s", strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@ -526,7 +527,7 @@ switch_id(char *user, char *group)
|
||||
privileges */
|
||||
if (user) {
|
||||
if (setuid(pw->pw_uid) != 0) {
|
||||
log_fn(LOG_ERR,"Error setting UID: %s", strerror(errno));
|
||||
err("Error setting UID: %s", strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@ -534,8 +535,7 @@ switch_id(char *user, char *group)
|
||||
return 0;
|
||||
#endif
|
||||
|
||||
log_fn(LOG_ERR,
|
||||
"User or group specified, but switching users is not supported.");
|
||||
err("User or group specified, but switching users is not supported.");
|
||||
|
||||
return -1;
|
||||
}
|
||||
@ -550,7 +550,7 @@ get_user_homedir(const char *username)
|
||||
tor_assert(username);
|
||||
|
||||
if (!(pw = getpwnam(username))) {
|
||||
log_fn(LOG_ERR,"User \"%s\" not found.", username);
|
||||
err("User \"%s\" not found.", username);
|
||||
return NULL;
|
||||
}
|
||||
return tor_strdup(pw->pw_dir);
|
||||
@ -879,7 +879,7 @@ tor_gettimeofday(struct timeval *timeval)
|
||||
/* number of 100-nsec units since Jan 1, 1601 */
|
||||
GetSystemTimeAsFileTime(&ft.ft_ft);
|
||||
if (ft.ft_64 < EPOCH_BIAS) {
|
||||
log_fn(LOG_ERR, "System time is before 1970; failing.");
|
||||
err("System time is before 1970; failing.");
|
||||
exit(1);
|
||||
}
|
||||
ft.ft_64 -= EPOCH_BIAS;
|
||||
@ -887,7 +887,7 @@ tor_gettimeofday(struct timeval *timeval)
|
||||
timeval->tv_usec = (unsigned) ((ft.ft_64 / UNITS_PER_USEC) % USEC_PER_SEC);
|
||||
#elif defined(HAVE_GETTIMEOFDAY)
|
||||
if (gettimeofday(timeval, NULL)) {
|
||||
log_fn(LOG_ERR, "gettimeofday failed.");
|
||||
err("gettimeofday failed.");
|
||||
/* If gettimeofday dies, we have either given a bad timezone (we didn't),
|
||||
or segfaulted.*/
|
||||
exit(1);
|
||||
@ -996,7 +996,7 @@ tor_mutex_acquire(tor_mutex_t *m)
|
||||
tor_assert(0);
|
||||
break;
|
||||
case WAIT_FAILED:
|
||||
log_fn(LOG_WARN, "Failed to acquire mutex: %d", GetLastError());
|
||||
warn(LD_GENERAL, "Failed to acquire mutex: %d", GetLastError());
|
||||
}
|
||||
}
|
||||
void
|
||||
@ -1005,7 +1005,7 @@ tor_mutex_release(tor_mutex_t *m)
|
||||
BOOL r;
|
||||
r = ReleaseMutex(m->handle);
|
||||
if (!r) {
|
||||
log_fn(LOG_WARN, "Failed to release mutex: %d", GetLastError());
|
||||
warn(LD_GENERAL, "Failed to release mutex: %d", GetLastError());
|
||||
}
|
||||
}
|
||||
unsigned long
|
||||
@ -1177,7 +1177,7 @@ network_init(void)
|
||||
int r;
|
||||
r = WSAStartup(0x101,&WSAData);
|
||||
if (r) {
|
||||
log_fn(LOG_WARN,"Error initializing windows network layer: code was %d",r);
|
||||
warn(LD_NET,"Error initializing windows network layer: code was %d",r);
|
||||
return -1;
|
||||
}
|
||||
/* WSAData.iMaxSockets might show the max sockets we're allowed to use.
|
||||
|
@ -165,9 +165,9 @@ crypto_log_errors(int severity, const char *doing)
|
||||
func = (const char*)ERR_func_error_string(err);
|
||||
if (!msg) msg = "(null)";
|
||||
if (doing) {
|
||||
log(severity, "crypto error while %s: %s (in %s:%s)", doing, msg, lib, func);
|
||||
log(severity, LD_CRYPTO, "crypto error while %s: %s (in %s:%s)", doing, msg, lib, func);
|
||||
} else {
|
||||
log(severity, "crypto error: %s (in %s:%s)", msg, lib, func);
|
||||
log(severity, LD_CRYPTO, "crypto error: %s (in %s:%s)", msg, lib, func);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -180,10 +180,10 @@ log_engine(const char *fn, ENGINE *e)
|
||||
const char *name, *id;
|
||||
name = ENGINE_get_name(e);
|
||||
id = ENGINE_get_id(e);
|
||||
log(LOG_NOTICE, "Using OpenSSL engine %s [%s] for %s",
|
||||
log(LOG_NOTICE, LD_CRYPTO, "Using OpenSSL engine %s [%s] for %s",
|
||||
name?name:"?", id?id:"?", fn);
|
||||
} else {
|
||||
log(LOG_INFO, "Using default implementation for %s", fn);
|
||||
log(LOG_INFO, LD_CRYPTO, "Using default implementation for %s", fn);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -201,8 +201,8 @@ crypto_global_init(int useAccel)
|
||||
#ifndef NO_ENGINES
|
||||
if (useAccel) {
|
||||
if (useAccel < 0)
|
||||
log_fn(LOG_WARN, "Initializing OpenSSL via tor_tls_init().");
|
||||
log_fn(LOG_INFO, "Initializing OpenSSL engine support.");
|
||||
warn(LD_CRYPTO, "Initializing OpenSSL via tor_tls_init().");
|
||||
info(LD_CRYPTO, "Initializing OpenSSL engine support.");
|
||||
ENGINE_load_builtin_engines();
|
||||
if (!ENGINE_register_all_complete())
|
||||
return -1;
|
||||
@ -342,7 +342,7 @@ crypto_create_init_cipher(const char *key, int encrypt_mode)
|
||||
crypto_cipher_env_t *crypto = NULL;
|
||||
|
||||
if (! (crypto = crypto_new_cipher_env())) {
|
||||
log_fn(LOG_WARN, "Unable to allocate crypto object");
|
||||
warn(LD_CRYPTO, "Unable to allocate crypto object");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -452,7 +452,7 @@ crypto_pk_read_private_key_from_filename(crypto_pk_env_t *env, const char *keyfi
|
||||
/* Read the file into a string. */
|
||||
contents = read_file_to_str(keyfile, 0);
|
||||
if (!contents) {
|
||||
log_fn(LOG_WARN, "Error reading private key from \"%s\"", keyfile);
|
||||
warn(LD_CRYPTO, "Error reading private key from \"%s\"", keyfile);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -592,7 +592,7 @@ crypto_pk_DER64_encode_public_key(crypto_pk_env_t *env, char **out)
|
||||
}
|
||||
*out = tor_malloc(len * 2); /* too long, but safe. */
|
||||
if (base64_encode(*out, len*2, buf, len) < 0) {
|
||||
log_fn(LOG_WARN, "Error base64-encoding DER-encoded key");
|
||||
warn(LD_CRYPTO, "Error base64-encoding DER-encoded key");
|
||||
tor_free(*out);
|
||||
return -1;
|
||||
}
|
||||
@ -628,7 +628,7 @@ crypto_pk_DER64_decode_public_key(const char *in)
|
||||
return NULL;
|
||||
len = base64_decode(buf, sizeof(buf), partitioned, strlen(partitioned));
|
||||
if (len<0) {
|
||||
log_fn(LOG_WARN,"Error base-64 decoding key");
|
||||
warn(LD_CRYPTO,"Error base-64 decoding key");
|
||||
return NULL;
|
||||
}
|
||||
return crypto_pk_asn1_decode(buf, len);
|
||||
@ -785,16 +785,16 @@ crypto_pk_public_checksig_digest(crypto_pk_env_t *env, const char *data,
|
||||
tor_assert(sig);
|
||||
|
||||
if (crypto_digest(digest,data,datalen)<0) {
|
||||
log_fn(LOG_WARN, "couldn't compute digest");
|
||||
warn(LD_CRYPTO, "couldn't compute digest");
|
||||
return -1;
|
||||
}
|
||||
r = crypto_pk_public_checksig(env,buf,sig,siglen);
|
||||
if (r != DIGEST_LEN) {
|
||||
log_fn(LOG_WARN, "Invalid signature");
|
||||
warn(LD_CRYPTO, "Invalid signature");
|
||||
return -1;
|
||||
}
|
||||
if (memcmp(buf, digest, DIGEST_LEN)) {
|
||||
log_fn(LOG_WARN, "Signature mismatched with digest.");
|
||||
warn(LD_CRYPTO, "Signature mismatched with digest.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -942,11 +942,13 @@ crypto_pk_private_hybrid_decrypt(crypto_pk_env_t *env,
|
||||
}
|
||||
outlen = crypto_pk_private_decrypt(env,buf,from,pkeylen,padding,warnOnFailure);
|
||||
if (outlen<0) {
|
||||
log_fn(warnOnFailure?LOG_WARN:LOG_DEBUG, "Error decrypting public-key data");
|
||||
log_fn(warnOnFailure?LOG_WARN:LOG_DEBUG, LD_CRYPTO,
|
||||
"Error decrypting public-key data");
|
||||
return -1;
|
||||
}
|
||||
if (outlen < CIPHER_KEY_LEN) {
|
||||
log_fn(warnOnFailure?LOG_WARN:LOG_INFO, "No room for a symmetric key");
|
||||
log_fn(warnOnFailure?LOG_WARN:LOG_INFO, LD_CRYPTO,
|
||||
"No room for a symmetric key");
|
||||
return -1;
|
||||
}
|
||||
cipher = crypto_create_init_cipher(buf, 0);
|
||||
@ -1398,7 +1400,7 @@ crypto_dh_generate_public(crypto_dh_env_t *dh)
|
||||
return -1;
|
||||
}
|
||||
if (tor_check_dh_key(dh->dh->pub_key)<0) {
|
||||
log_fn(LOG_WARN, "Weird! Our own DH key was invalid. I guess once-in-the-universe chances really do happen. Trying again.");
|
||||
warn(LD_CRYPTO, "Weird! Our own DH key was invalid. I guess once-in-the-universe chances really do happen. Trying again.");
|
||||
/* Free and clear the keys, so openssl will actually try again. */
|
||||
BN_free(dh->dh->pub_key);
|
||||
BN_free(dh->dh->priv_key);
|
||||
@ -1426,7 +1428,7 @@ crypto_dh_get_public(crypto_dh_env_t *dh, char *pubkey, size_t pubkey_len)
|
||||
bytes = BN_num_bytes(dh->dh->pub_key);
|
||||
tor_assert(bytes >= 0);
|
||||
if (pubkey_len < (size_t)bytes) {
|
||||
log_fn(LOG_WARN, "Weird! pubkey_len (%d) was smaller than DH_BYTES (%d)", (int) pubkey_len, bytes);
|
||||
warn(LD_CRYPTO, "Weird! pubkey_len (%d) was smaller than DH_BYTES (%d)", (int) pubkey_len, bytes);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -1457,11 +1459,11 @@ tor_check_dh_key(BIGNUM *bn)
|
||||
if (!dh_param_p)
|
||||
init_dh_param();
|
||||
if (bn->neg) {
|
||||
log_fn(LOG_WARN, "Rejecting DH key < 0");
|
||||
warn(LD_CRYPTO, "Rejecting DH key < 0");
|
||||
return -1;
|
||||
}
|
||||
if (BN_cmp(bn, dh_param_p)>=0) {
|
||||
log_fn(LOG_WARN, "Rejecting DH key >= p");
|
||||
warn(LD_CRYPTO, "Rejecting DH key >= p");
|
||||
return -1;
|
||||
}
|
||||
n_bits = BN_num_bits(bn);
|
||||
@ -1471,18 +1473,18 @@ tor_check_dh_key(BIGNUM *bn)
|
||||
++n_set;
|
||||
}
|
||||
if (n_set < MIN_DIFFERING_BITS || n_set >= n_bits-MIN_DIFFERING_BITS) {
|
||||
log_fn(LOG_WARN, "Too few/many bits in DH key (%d)", n_set);
|
||||
warn(LD_CRYPTO, "Too few/many bits in DH key (%d)", n_set);
|
||||
goto err;
|
||||
}
|
||||
BN_set_word(x, MIN_DIST_FROM_EDGE);
|
||||
if (BN_cmp(bn,x)<=0) {
|
||||
log_fn(LOG_WARN, "DH key is too close to 0");
|
||||
warn(LD_CRYPTO, "DH key is too close to 0");
|
||||
goto err;
|
||||
}
|
||||
BN_copy(x,dh_param_p);
|
||||
BN_sub_word(x, MIN_DIST_FROM_EDGE);
|
||||
if (BN_cmp(bn,x)>=0) {
|
||||
log_fn(LOG_WARN, "DH key is too close to p");
|
||||
warn(LD_CRYPTO, "DH key is too close to p");
|
||||
goto err;
|
||||
}
|
||||
BN_free(x);
|
||||
@ -1490,7 +1492,7 @@ tor_check_dh_key(BIGNUM *bn)
|
||||
err:
|
||||
BN_free(x);
|
||||
s = BN_bn2hex(bn);
|
||||
log_fn(LOG_WARN, "Rejecting invalid DH key [%s]", s);
|
||||
warn(LD_CRYPTO, "Rejecting invalid DH key [%s]", s);
|
||||
OPENSSL_free(s);
|
||||
return -1;
|
||||
}
|
||||
@ -1525,13 +1527,13 @@ crypto_dh_compute_secret(crypto_dh_env_t *dh,
|
||||
goto error;
|
||||
if (tor_check_dh_key(pubkey_bn)<0) {
|
||||
/* Check for invalid public keys. */
|
||||
log_fn(LOG_WARN,"Rejected invalid g^x");
|
||||
warn(LD_CRYPTO,"Rejected invalid g^x");
|
||||
goto error;
|
||||
}
|
||||
secret_tmp = tor_malloc(crypto_dh_get_bytes(dh)+1);
|
||||
result = DH_compute_key((unsigned char*)secret_tmp, pubkey_bn, dh->dh);
|
||||
if (result < 0) {
|
||||
log_fn(LOG_WARN,"DH_compute_key() failed.");
|
||||
warn(LD_CRYPTO,"DH_compute_key() failed.");
|
||||
goto error;
|
||||
}
|
||||
secret_len = result;
|
||||
@ -1612,7 +1614,7 @@ crypto_seed_rng(void)
|
||||
* functions. If one succeeds, we'll accept the RNG as seeded. */
|
||||
rand_poll_status = RAND_poll();
|
||||
if (rand_poll_status == 0)
|
||||
log_fn(LOG_WARN, "RAND_poll() failed.");
|
||||
warn(LD_CRYPTO, "RAND_poll() failed.");
|
||||
#else
|
||||
rand_poll_status = 0;
|
||||
#endif
|
||||
@ -1621,14 +1623,14 @@ crypto_seed_rng(void)
|
||||
if (!provider_set) {
|
||||
if (!CryptAcquireContext(&provider, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) {
|
||||
if (GetLastError() != NTE_BAD_KEYSET) {
|
||||
log_fn(LOG_WARN, "Can't get CryptoAPI provider [1]");
|
||||
warn(LD_CRYPTO, "Can't get CryptoAPI provider [1]");
|
||||
return rand_poll_status ? 0 : -1;
|
||||
}
|
||||
}
|
||||
provider_set = 1;
|
||||
}
|
||||
if (!CryptGenRandom(provider, sizeof(buf), buf)) {
|
||||
log_fn(LOG_WARN, "Can't get entropy from CryptoAPI.");
|
||||
warn(LD_CRYPTO, "Can't get entropy from CryptoAPI.");
|
||||
return rand_poll_status ? 0 : -1;
|
||||
}
|
||||
RAND_seed(buf, sizeof(buf));
|
||||
@ -1637,18 +1639,18 @@ crypto_seed_rng(void)
|
||||
for (i = 0; filenames[i]; ++i) {
|
||||
fd = open(filenames[i], O_RDONLY, 0);
|
||||
if (fd<0) continue;
|
||||
log_fn(LOG_INFO, "Seeding RNG from \"%s\"", filenames[i]);
|
||||
info(LD_CRYPTO, "Seeding RNG from \"%s\"", filenames[i]);
|
||||
n = read_all(fd, buf, sizeof(buf), 0);
|
||||
close(fd);
|
||||
if (n != sizeof(buf)) {
|
||||
log_fn(LOG_WARN, "Error reading from entropy source");
|
||||
warn(LD_CRYPTO, "Error reading from entropy source");
|
||||
return -1;
|
||||
}
|
||||
RAND_seed(buf, sizeof(buf));
|
||||
return 0;
|
||||
}
|
||||
|
||||
log_fn(LOG_WARN, "Cannot seed RNG -- no entropy source found.");
|
||||
warn(LD_CRYPTO, "Cannot seed RNG -- no entropy source found.");
|
||||
return rand_poll_status ? 0 : -1;
|
||||
#endif
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ typedef struct logfile_t {
|
||||
char *filename; /**< Filename to open. */
|
||||
FILE *file; /**< Stream to receive log messages. */
|
||||
int needs_close; /**< Boolean: true if the stream gets closed on shutdown. */
|
||||
int loglevel; /**< Lowest severity level to send to this stream. */
|
||||
int min_loglevel; /**< Lowest severity level to send to this stream. */
|
||||
int max_loglevel; /**< Highest severity level to send to this stream. */
|
||||
int is_temporary; /**< Boolean: close after initializing logging subsystem.*/
|
||||
int is_syslog; /**< Boolean: send messages to syslog. */
|
||||
@ -184,7 +184,8 @@ format_msg(char *buf, size_t buf_len,
|
||||
* message. The actual message is derived as from tor_snprintf(format,ap).
|
||||
*/
|
||||
static void
|
||||
logv(int severity, const char *funcname, const char *format, va_list ap)
|
||||
logv(int severity, int domain, const char *funcname, const char *format,
|
||||
va_list ap)
|
||||
{
|
||||
char buf[10024];
|
||||
int formatted = 0;
|
||||
@ -194,7 +195,7 @@ logv(int severity, const char *funcname, const char *format, va_list ap)
|
||||
assert(format);
|
||||
lf = logfiles;
|
||||
while (lf) {
|
||||
if (severity > lf->loglevel || severity < lf->max_loglevel) {
|
||||
if (severity > lf->min_loglevel || severity < lf->max_loglevel) {
|
||||
lf = lf->next;
|
||||
continue;
|
||||
}
|
||||
@ -215,7 +216,7 @@ logv(int severity, const char *funcname, const char *format, va_list ap)
|
||||
lf = lf->next;
|
||||
continue;
|
||||
} else if (lf->callback) {
|
||||
lf->callback(severity, end_of_prefix);
|
||||
lf->callback(severity, domain, end_of_prefix);
|
||||
lf = lf->next;
|
||||
continue;
|
||||
}
|
||||
@ -233,32 +234,77 @@ logv(int severity, const char *funcname, const char *format, va_list ap)
|
||||
|
||||
/** Output a message to the log. */
|
||||
void
|
||||
_log(int severity, const char *format, ...)
|
||||
_log(int severity, int domain, const char *format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap,format);
|
||||
logv(severity, NULL, format, ap);
|
||||
logv(severity, domain, NULL, format, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
/** Output a message to the log, prefixed with a function name <b>fn</b>. */
|
||||
#ifdef __GNUC__
|
||||
void
|
||||
_log_fn(int severity, const char *fn, const char *format, ...)
|
||||
_log_fn(int severity, int domain, const char *fn, const char *format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap,format);
|
||||
logv(severity, fn, format, ap);
|
||||
logv(severity, domain, fn, format, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
#else
|
||||
const char *_log_fn_function_name=NULL;
|
||||
void
|
||||
_log_fn(int severity, const char *format, ...)
|
||||
_log_fn(int severity, int domain, const char *format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap,format);
|
||||
logv(severity, _log_fn_function_name, format, ap);
|
||||
logv(severity, domain, _log_fn_function_name, format, ap);
|
||||
va_end(ap);
|
||||
_log_fn_function_name = NULL;
|
||||
}
|
||||
void
|
||||
_debug(int domain, const char *format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap,format);
|
||||
logv(LOG_DEBUG, domain, _log_fn_function_name, format, ap);
|
||||
va_end(ap);
|
||||
_log_fn_function_name = NULL;
|
||||
}
|
||||
void
|
||||
_info(int domain, const char *format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap,format);
|
||||
logv(LOG_INFO, domain, _log_fn_function_name, format, ap);
|
||||
va_end(ap);
|
||||
_log_fn_function_name = NULL;
|
||||
}
|
||||
void
|
||||
_notice(int domain, const char *format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap,format);
|
||||
logv(LOG_NOTICE, domain, _log_fn_function_name, format, ap);
|
||||
va_end(ap);
|
||||
_log_fn_function_name = NULL;
|
||||
}
|
||||
void
|
||||
_warn(int domain, const char *format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap,format);
|
||||
logv(LOG_ERR, domain, _log_fn_function_name, format, ap);
|
||||
va_end(ap);
|
||||
_log_fn_function_name = NULL;
|
||||
}
|
||||
void
|
||||
_err(const char *format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap,format);
|
||||
logv(LOG_ERR, LD_GENERAL, _log_fn_function_name, format, ap);
|
||||
va_end(ap);
|
||||
_log_fn_function_name = NULL;
|
||||
}
|
||||
@ -359,7 +405,7 @@ add_stream_log(int loglevelMin, int loglevelMax, const char *name, FILE *stream)
|
||||
logfile_t *lf;
|
||||
lf = tor_malloc_zero(sizeof(logfile_t));
|
||||
lf->filename = tor_strdup(name);
|
||||
lf->loglevel = loglevelMin;
|
||||
lf->min_loglevel = loglevelMin;
|
||||
lf->max_loglevel = loglevelMax;
|
||||
lf->file = stream;
|
||||
lf->next = logfiles;
|
||||
@ -386,7 +432,7 @@ add_callback_log(int loglevelMin, int loglevelMax, log_callback cb)
|
||||
{
|
||||
logfile_t *lf;
|
||||
lf = tor_malloc_zero(sizeof(logfile_t));
|
||||
lf->loglevel = loglevelMin;
|
||||
lf->min_loglevel = loglevelMin;
|
||||
lf->max_loglevel = loglevelMax;
|
||||
lf->filename = tor_strdup("<callback>");
|
||||
lf->callback = cb;
|
||||
@ -402,7 +448,7 @@ change_callback_log_severity(int loglevelMin, int loglevelMax,
|
||||
logfile_t *lf;
|
||||
for (lf = logfiles; lf; lf = lf->next) {
|
||||
if (lf->callback == cb) {
|
||||
lf->loglevel = loglevelMin;
|
||||
lf->min_loglevel = loglevelMin;
|
||||
lf->max_loglevel = loglevelMax;
|
||||
}
|
||||
}
|
||||
@ -468,7 +514,7 @@ add_syslog_log(int loglevelMin, int loglevelMax)
|
||||
openlog("Tor", LOG_NDELAY, LOG_DAEMON);
|
||||
|
||||
lf = tor_malloc_zero(sizeof(logfile_t));
|
||||
lf->loglevel = loglevelMin;
|
||||
lf->min_loglevel = loglevelMin;
|
||||
lf->filename = tor_strdup("<syslog>");
|
||||
lf->max_loglevel = loglevelMax;
|
||||
lf->is_syslog = 1;
|
||||
@ -510,8 +556,8 @@ get_min_log_level(void)
|
||||
logfile_t *lf;
|
||||
int min = LOG_ERR;
|
||||
for (lf = logfiles; lf; lf = lf->next) {
|
||||
if (lf->loglevel > min)
|
||||
min = lf->loglevel;
|
||||
if (lf->min_loglevel > min)
|
||||
min = lf->min_loglevel;
|
||||
}
|
||||
return min;
|
||||
}
|
||||
@ -522,7 +568,7 @@ switch_logs_debug(void)
|
||||
{
|
||||
logfile_t *lf;
|
||||
for (lf = logfiles; lf; lf=lf->next) {
|
||||
lf->loglevel = LOG_DEBUG;
|
||||
lf->min_loglevel = LOG_DEBUG;
|
||||
}
|
||||
}
|
||||
|
||||
@ -541,19 +587,20 @@ libevent_logging_callback(int severity, const char *msg)
|
||||
}
|
||||
switch (severity) {
|
||||
case _EVENT_LOG_DEBUG:
|
||||
log(LOG_DEBUG, "Message from libevent: %s", buf);
|
||||
log(LOG_DEBUG, LD_NET, "Message from libevent: %s", buf);
|
||||
break;
|
||||
case _EVENT_LOG_MSG:
|
||||
log(LOG_INFO, "Message from libevent: %s", buf);
|
||||
log(LOG_INFO, LD_NET, "Message from libevent: %s", buf);
|
||||
break;
|
||||
case _EVENT_LOG_WARN:
|
||||
log(LOG_WARN, "Warning from libevent: %s", buf);
|
||||
log(LOG_WARN, LD_GENERAL, "Warning from libevent: %s", buf);
|
||||
break;
|
||||
case _EVENT_LOG_ERR:
|
||||
log(LOG_ERR, "Error from libevent: %s", buf);
|
||||
log(LOG_ERR, LD_GENERAL, "Error from libevent: %s", buf);
|
||||
break;
|
||||
default:
|
||||
log(LOG_WARN, "Message [%d] from libevent: %s", severity, buf);
|
||||
log(LOG_WARN, LD_GENERAL, "Message [%d] from libevent: %s",
|
||||
severity, buf);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -50,7 +50,15 @@
|
||||
#define LOG_ERR 3
|
||||
#endif
|
||||
|
||||
typedef void (*log_callback)(int severity, const char *msg);
|
||||
/* Logging domains */
|
||||
#define LD_GENERAL 0
|
||||
#define LD_CRYPTO 1
|
||||
#define LD_NET 2
|
||||
#define LD_CONFIG 3
|
||||
#define LD_FS 4
|
||||
#define LD_PROTOCOL 5
|
||||
|
||||
typedef void (*log_callback)(int severity, int domain, const char *msg);
|
||||
|
||||
int parse_log_level(const char *level);
|
||||
const char *log_level_to_string(int level);
|
||||
@ -73,29 +81,69 @@ void change_callback_log_severity(int loglevelMin, int loglevelMax,
|
||||
log_callback cb);
|
||||
|
||||
/* Outputs a message to stdout */
|
||||
void _log(int severity, const char *format, ...) CHECK_PRINTF(2,3);
|
||||
void _log(int severity, int domain, const char *format, ...) CHECK_PRINTF(3,4);
|
||||
|
||||
#ifdef __GNUC__
|
||||
void _log_fn(int severity, const char *funcname, const char *format, ...)
|
||||
CHECK_PRINTF(3,4);
|
||||
void _log_fn(int severity, int domain,
|
||||
const char *funcname, const char *format, ...)
|
||||
CHECK_PRINTF(4,5);
|
||||
/** Log a message at level <b>severity</b>, using a pretty-printed version
|
||||
* of the current function name. */
|
||||
#define log_fn(severity, args...) \
|
||||
_log_fn(severity, __PRETTY_FUNCTION__, args)
|
||||
#elif defined(_MSC_VER) && _MSC_VER < 1300
|
||||
#ifdef OLD_LOG_INTERFACE
|
||||
#define log_fn(severity, args...) \
|
||||
_log_fn(severity, LD_GENERAL, __PRETTY_FUNCTION__, args)
|
||||
#define log(severity, args...) \
|
||||
_log(severity, LD_GENERAL, args)
|
||||
#else
|
||||
#define log_fn(severity, domain, args...) \
|
||||
_log_fn(severity, domain, __PRETTY_FUNCTION__, args)
|
||||
#define log _log
|
||||
#endif
|
||||
#define debug(domain, args...) \
|
||||
_log_fn(LOG_DEBUG, domain, __PRETTY_FUNCTION__, args)
|
||||
#define info(domain, args...) \
|
||||
_log_fn(LOG_INFO, domain, __PRETTY_FUNCTION__, args)
|
||||
#define notice(domain, args...) \
|
||||
_log_fn(LOG_INFO, domain, __PRETTY_FUNCTION__, args)
|
||||
#define warn(domain, args...) \
|
||||
_log_fn(LOG_INFO, domain, __PRETTY_FUNCTION__, args)
|
||||
#define err(args...) \
|
||||
_log_fn(LOG_ERR, LD_GENERAL, __PRETTY_FUNCTION__, args)
|
||||
#else
|
||||
|
||||
void _log_fn(int severity, int domain, const char *format, ...);
|
||||
void _debug(int domain, const char *format, ...);
|
||||
void _info(int domain, const char *format, ...);
|
||||
void _notice(int domain, const char *format, ...);
|
||||
void _warn(int domain, const char *format, ...);
|
||||
void _err(const char *format, ...);
|
||||
|
||||
#define log _log /* hack it so we don't conflict with log() as much */
|
||||
|
||||
#if defined(_MSC_VER) && _MSC_VER < 1300
|
||||
/* MSVC 6 and earlier don't have __FUNCTION__, or even __LINE__. */
|
||||
#define log_fn _log
|
||||
#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 */
|
||||
extern const char *_log_fn_function_name;
|
||||
void _log_fn(int severity, const char *format, ...);
|
||||
/* We abuse the comma operator here, since we can't use the standard
|
||||
* 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
|
||||
#define log _log /* hack it so we don't conflict with log() as much */
|
||||
|
||||
#endif /* !GNUC */
|
||||
|
||||
# define __LOG_H
|
||||
#endif
|
||||
|
@ -75,7 +75,7 @@ tor_gzip_compress(char **out, size_t *out_len,
|
||||
|
||||
if (method == GZIP_METHOD && !is_gzip_supported()) {
|
||||
/* Old zlib version don't support gzip in deflateInit2 */
|
||||
log_fn(LOG_WARN, "Gzip not supported with zlib %s", ZLIB_VERSION);
|
||||
warn(LD_GENERAL, "Gzip not supported with zlib %s", ZLIB_VERSION);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -91,7 +91,7 @@ tor_gzip_compress(char **out, size_t *out_len,
|
||||
if (deflateInit2(stream, Z_BEST_COMPRESSION, Z_DEFLATED,
|
||||
method_bits(method),
|
||||
8, Z_DEFAULT_STRATEGY) != Z_OK) {
|
||||
log_fn(LOG_WARN, "Error from deflateInit2: %s",
|
||||
warn(LD_GENERAL, "Error from deflateInit2: %s",
|
||||
stream->msg?stream->msg:"<no message>");
|
||||
goto err;
|
||||
}
|
||||
@ -120,7 +120,7 @@ tor_gzip_compress(char **out, size_t *out_len,
|
||||
stream->avail_out = out_size - offset;
|
||||
break;
|
||||
default:
|
||||
log_fn(LOG_WARN, "Gzip compression didn't finish: %s",
|
||||
warn(LD_GENERAL, "Gzip compression didn't finish: %s",
|
||||
stream->msg ? stream->msg : "<no message>");
|
||||
goto err;
|
||||
}
|
||||
@ -128,7 +128,7 @@ tor_gzip_compress(char **out, size_t *out_len,
|
||||
done:
|
||||
*out_len = stream->total_out;
|
||||
if (deflateEnd(stream)!=Z_OK) {
|
||||
log_fn(LOG_WARN, "Error freeing gzip structures");
|
||||
warn(LD_GENERAL, "Error freeing gzip structures");
|
||||
goto err;
|
||||
}
|
||||
tor_free(stream);
|
||||
@ -168,7 +168,7 @@ tor_gzip_uncompress(char **out, size_t *out_len,
|
||||
|
||||
if (method == GZIP_METHOD && !is_gzip_supported()) {
|
||||
/* Old zlib version don't support gzip in inflateInit2 */
|
||||
log_fn(LOG_WARN, "Gzip not supported with zlib %s", ZLIB_VERSION);
|
||||
warn(LD_GENERAL, "Gzip not supported with zlib %s", ZLIB_VERSION);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -183,7 +183,7 @@ tor_gzip_uncompress(char **out, size_t *out_len,
|
||||
|
||||
if (inflateInit2(stream,
|
||||
method_bits(method)) != Z_OK) {
|
||||
log_fn(LOG_WARN, "Error from inflateInit2: %s",
|
||||
warn(LD_GENERAL, "Error from inflateInit2: %s",
|
||||
stream->msg?stream->msg:"<no message>");
|
||||
goto err;
|
||||
}
|
||||
@ -203,7 +203,7 @@ tor_gzip_uncompress(char **out, size_t *out_len,
|
||||
goto done;
|
||||
/* There may be more compressed data here. */
|
||||
if (inflateInit2(stream, method_bits(method)) != Z_OK) {
|
||||
log_fn(LOG_WARN, "Error from inflateInit2: %s",
|
||||
warn(LD_GENERAL, "Error from inflateInit2: %s",
|
||||
stream->msg?stream->msg:"<no message>");
|
||||
goto err;
|
||||
}
|
||||
@ -216,7 +216,7 @@ tor_gzip_uncompress(char **out, size_t *out_len,
|
||||
break;
|
||||
case Z_BUF_ERROR:
|
||||
if (stream->avail_out > 0) {
|
||||
log_fn(LOG_WARN, "possible truncated or corrupt zlib data");
|
||||
warn(LD_PROTOCOL, "possible truncated or corrupt zlib data");
|
||||
goto err;
|
||||
}
|
||||
offset = stream->next_out - (unsigned char*)*out;
|
||||
@ -226,7 +226,7 @@ tor_gzip_uncompress(char **out, size_t *out_len,
|
||||
stream->avail_out = out_size - offset;
|
||||
break;
|
||||
default:
|
||||
log_fn(LOG_WARN, "Gzip decompression returned an error: %s",
|
||||
warn(LD_GENERAL, "Gzip decompression returned an error: %s",
|
||||
stream->msg ? stream->msg : "<no message>");
|
||||
goto err;
|
||||
}
|
||||
@ -236,7 +236,7 @@ tor_gzip_uncompress(char **out, size_t *out_len,
|
||||
r = inflateEnd(stream);
|
||||
tor_free(stream);
|
||||
if (r != Z_OK) {
|
||||
log_fn(LOG_WARN, "Error freeing gzip structures");
|
||||
warn(LD_GENERAL, "Error freeing gzip structures");
|
||||
goto err;
|
||||
}
|
||||
|
||||
|
@ -91,9 +91,9 @@ tls_log_errors(int severity, const char *doing)
|
||||
func = (const char*)ERR_func_error_string(err);
|
||||
if (!msg) msg = "(null)";
|
||||
if (doing) {
|
||||
log(severity, "TLS error while %s: %s (in %s:%s)", doing, msg, lib,func);
|
||||
log(severity, LD_NET, "TLS error while %s: %s (in %s:%s)", doing, msg, lib,func);
|
||||
} else {
|
||||
log(severity, "TLS error: %s (in %s:%s)", msg, lib, func);
|
||||
log(severity, LD_NET, "TLS error: %s (in %s:%s)", msg, lib, func);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -127,10 +127,10 @@ tor_tls_get_error(tor_tls_t *tls, int r, int extra,
|
||||
if (extra&CATCH_SYSCALL)
|
||||
return _TOR_TLS_SYSCALL;
|
||||
if (r == 0)
|
||||
log(severity, "TLS error: unexpected close while %s", doing);
|
||||
log(severity, LD_NET, "TLS error: unexpected close while %s", doing);
|
||||
else {
|
||||
int e = tor_socket_errno(tls->socket);
|
||||
log(severity, "TLS error: <syscall error while %s> (errno=%d: %s)",
|
||||
log(severity, LD_NET, "TLS error: <syscall error while %s> (errno=%d: %s)",
|
||||
doing, e, tor_socket_strerror(e));
|
||||
}
|
||||
tls_log_errors(severity, doing);
|
||||
@ -138,7 +138,7 @@ tor_tls_get_error(tor_tls_t *tls, int r, int extra,
|
||||
case SSL_ERROR_ZERO_RETURN:
|
||||
if (extra&CATCH_ZERO)
|
||||
return _TOR_TLS_ZERORETURN;
|
||||
log(severity, "TLS error: Zero return");
|
||||
log(severity, LD_NET, "TLS error: Zero return");
|
||||
tls_log_errors(severity, doing);
|
||||
return TOR_TLS_ERROR;
|
||||
default:
|
||||
@ -333,7 +333,7 @@ tor_tls_context_new(crypto_pk_env_t *identity,
|
||||
idcert = tor_tls_create_certificate(identity, identity, nn2, nn2,
|
||||
IDENTITY_CERT_LIFETIME);
|
||||
if (!cert || !idcert) {
|
||||
log(LOG_WARN, "Error creating certificate");
|
||||
log(LOG_WARN, LD_CRYPTO, "Error creating certificate");
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
@ -481,12 +481,12 @@ tor_tls_read(tor_tls_t *tls, char *cp, size_t len)
|
||||
return r;
|
||||
err = tor_tls_get_error(tls, r, CATCH_ZERO, "reading", LOG_DEBUG);
|
||||
if (err == _TOR_TLS_ZERORETURN) {
|
||||
log_fn(LOG_DEBUG,"read returned r=%d; TLS is closed",r);
|
||||
debug(LD_NET,"read returned r=%d; TLS is closed",r);
|
||||
tls->state = TOR_TLS_ST_CLOSED;
|
||||
return TOR_TLS_CLOSE;
|
||||
} else {
|
||||
tor_assert(err != TOR_TLS_DONE);
|
||||
log_fn(LOG_DEBUG,"read returned r=%d, err=%d",r,err);
|
||||
debug(LD_NET,"read returned r=%d, err=%d",r,err);
|
||||
return err;
|
||||
}
|
||||
}
|
||||
@ -508,7 +508,7 @@ tor_tls_write(tor_tls_t *tls, char *cp, size_t n)
|
||||
if (tls->wantwrite_n) {
|
||||
/* if WANTWRITE last time, we must use the _same_ n as before */
|
||||
tor_assert(n >= tls->wantwrite_n);
|
||||
log_fn(LOG_DEBUG,"resuming pending-write, (%d to flush, reusing %d)",
|
||||
debug(LD_NET,"resuming pending-write, (%d to flush, reusing %d)",
|
||||
(int)n, (int)tls->wantwrite_n);
|
||||
n = tls->wantwrite_n;
|
||||
tls->wantwrite_n = 0;
|
||||
@ -602,7 +602,7 @@ tor_tls_shutdown(tor_tls_t *tls)
|
||||
*/
|
||||
if (tls->state == TOR_TLS_ST_GOTCLOSE ||
|
||||
tls->state == TOR_TLS_ST_SENTCLOSE) {
|
||||
log(LOG_WARN,
|
||||
log(LOG_WARN, LD_NET,
|
||||
"TLS returned \"half-closed\" value while already half-closed");
|
||||
return TOR_TLS_ERROR;
|
||||
}
|
||||
@ -643,11 +643,11 @@ tor_tls_get_peer_cert_nickname(tor_tls_t *tls, char *buf, size_t buflen)
|
||||
int r = -1;
|
||||
|
||||
if (!(cert = SSL_get_peer_certificate(tls->ssl))) {
|
||||
log_fn(LOG_WARN, "Peer has no certificate");
|
||||
warn(LD_PROTOCOL, "Peer has no certificate");
|
||||
goto error;
|
||||
}
|
||||
if (!(name = X509_get_subject_name(cert))) {
|
||||
log_fn(LOG_WARN, "Peer certificate has no subject name");
|
||||
warn(LD_PROTOCOL, "Peer certificate has no subject name");
|
||||
goto error;
|
||||
}
|
||||
if ((nid = OBJ_txt2nid("commonName")) == NID_undef)
|
||||
@ -657,10 +657,10 @@ tor_tls_get_peer_cert_nickname(tor_tls_t *tls, char *buf, size_t buflen)
|
||||
if (lenout == -1)
|
||||
goto error;
|
||||
if (((int)strspn(buf, LEGAL_NICKNAME_CHARACTERS)) < lenout) {
|
||||
log_fn(LOG_WARN, "Peer certificate nickname \"%s\" has illegal characters.",
|
||||
warn(LD_PROTOCOL, "Peer certificate nickname \"%s\" has illegal characters.",
|
||||
buf);
|
||||
if (strchr(buf, '.'))
|
||||
log_fn(LOG_WARN, " (Maybe it is not really running Tor at its advertised OR port.)");
|
||||
warn(LD_PROTOCOL, " (Maybe it is not really running Tor at its advertised OR port.)");
|
||||
goto error;
|
||||
}
|
||||
|
||||
@ -685,11 +685,11 @@ log_cert_lifetime(X509 *cert, const char *problem)
|
||||
struct tm tm;
|
||||
|
||||
if (problem)
|
||||
log_fn(LOG_WARN,"Certificate %s: is your system clock set incorrectly?",
|
||||
warn(LD_GENERAL,"Certificate %s: is your system clock set incorrectly?",
|
||||
problem);
|
||||
|
||||
if (!(bio = BIO_new(BIO_s_mem()))) {
|
||||
log_fn(LOG_WARN, "Couldn't allocate BIO!"); goto end;
|
||||
log_fn(LOG_WARN, LD_GENERAL, "Couldn't allocate BIO!"); goto end;
|
||||
}
|
||||
if (!(ASN1_TIME_print(bio, X509_get_notBefore(cert)))) {
|
||||
tls_log_errors(LOG_WARN, "printing certificate lifetime");
|
||||
@ -708,7 +708,7 @@ log_cert_lifetime(X509 *cert, const char *problem)
|
||||
|
||||
strftime(mytime, 32, "%b %d %H:%M:%S %Y GMT", tor_gmtime_r(&now, &tm));
|
||||
|
||||
log_fn(LOG_WARN, "(certificate lifetime runs from %s through %s. Your time is %s.)",s1,s2,mytime);
|
||||
warn(LD_GENERAL, "(certificate lifetime runs from %s through %s. Your time is %s.)",s1,s2,mytime);
|
||||
|
||||
end:
|
||||
/* Not expected to get invoked */
|
||||
@ -748,7 +748,7 @@ tor_tls_verify(int severity, tor_tls_t *tls, crypto_pk_env_t **identity_key)
|
||||
* cert and the id_cert.
|
||||
*/
|
||||
if (num_in_chain < 1) {
|
||||
log_fn(severity,"Unexpected number of certificates in chain (%d)",
|
||||
log_fn(severity,LD_PROTOCOL,"Unexpected number of certificates in chain (%d)",
|
||||
num_in_chain);
|
||||
goto done;
|
||||
}
|
||||
@ -758,13 +758,13 @@ tor_tls_verify(int severity, tor_tls_t *tls, crypto_pk_env_t **identity_key)
|
||||
break;
|
||||
}
|
||||
if (!id_cert) {
|
||||
log_fn(severity,"No distinct identity certificate found");
|
||||
log_fn(severity,LD_PROTOCOL,"No distinct identity certificate found");
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (!(id_pkey = X509_get_pubkey(id_cert)) ||
|
||||
X509_verify(cert, id_pkey) <= 0) {
|
||||
log_fn(severity,"X509_verify on cert and pkey returned <= 0");
|
||||
log_fn(severity,LD_PROTOCOL,"X509_verify on cert and pkey returned <= 0");
|
||||
tls_log_errors(severity,"verifying certificate");
|
||||
goto done;
|
||||
}
|
||||
@ -866,7 +866,7 @@ _check_no_tls_errors(const char *fname, int line)
|
||||
{
|
||||
if (ERR_peek_error() == 0)
|
||||
return;
|
||||
log_fn(LOG_WARN, "Unhandled OpenSSL errors found at %s:%d: ",
|
||||
log_fn(LOG_WARN, LD_CRYPTO, "Unhandled OpenSSL errors found at %s:%d: ",
|
||||
fname, line);
|
||||
tls_log_errors(LOG_WARN, NULL);
|
||||
}
|
||||
|
@ -127,7 +127,7 @@ _tor_malloc(size_t size DMALLOC_PARAMS)
|
||||
result = dmalloc_malloc(file, line, size, DMALLOC_FUNC_MALLOC, 0, 0);
|
||||
|
||||
if (!result) {
|
||||
log_fn(LOG_ERR, "Out of memory. Dying.");
|
||||
err("Out of memory. Dying.");
|
||||
/* XXX if these functions die within a worker process, they won't
|
||||
* call spawn_exit */
|
||||
exit(1);
|
||||
@ -159,7 +159,7 @@ _tor_realloc(void *ptr, size_t size DMALLOC_PARAMS)
|
||||
|
||||
result = dmalloc_realloc(file, line, ptr, size, DMALLOC_FUNC_REALLOC, 0);
|
||||
if (!result) {
|
||||
log_fn(LOG_ERR, "Out of memory. Dying.");
|
||||
err("Out of memory. Dying.");
|
||||
exit(1);
|
||||
}
|
||||
return result;
|
||||
@ -177,7 +177,7 @@ _tor_strdup(const char *s DMALLOC_PARAMS)
|
||||
|
||||
dup = dmalloc_strdup(file, line, s, 0);
|
||||
if (!dup) {
|
||||
log_fn(LOG_ERR,"Out of memory. Dying.");
|
||||
err("Out of memory. Dying.");
|
||||
exit(1);
|
||||
}
|
||||
return dup;
|
||||
@ -565,7 +565,7 @@ tv_udiff(struct timeval *start, struct timeval *end)
|
||||
long secdiff = end->tv_sec - start->tv_sec;
|
||||
|
||||
if (labs(secdiff+1) > LONG_MAX/1000000) {
|
||||
log_fn(LOG_WARN, "comparing times too far apart.");
|
||||
warn(LD_GENERAL, "comparing times too far apart.");
|
||||
return LONG_MAX;
|
||||
}
|
||||
|
||||
@ -687,7 +687,7 @@ parse_rfc1123_time(const char *buf, time_t *t)
|
||||
if (sscanf(buf, "%3s, %d %3s %d %d:%d:%d GMT", weekday,
|
||||
&tm.tm_mday, month, &tm.tm_year, &tm.tm_hour,
|
||||
&tm.tm_min, &tm.tm_sec) < 7) {
|
||||
log_fn(LOG_WARN, "Got invalid RFC1123 time \"%s\"", buf);
|
||||
warn(LD_GENERAL, "Got invalid RFC1123 time \"%s\"", buf);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -699,7 +699,7 @@ parse_rfc1123_time(const char *buf, time_t *t)
|
||||
}
|
||||
}
|
||||
if (m<0) {
|
||||
log_fn(LOG_WARN, "Got invalid RFC1123 time \"%s\"", buf);
|
||||
warn(LD_GENERAL, "Got invalid RFC1123 time \"%s\"", buf);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -729,17 +729,17 @@ parse_iso_time(const char *cp, time_t *t)
|
||||
struct tm st_tm;
|
||||
#ifdef HAVE_STRPTIME
|
||||
if (!strptime(cp, "%Y-%m-%d %H:%M:%S", &st_tm)) {
|
||||
log_fn(LOG_WARN, "Published time was unparseable"); return -1;
|
||||
warn(LD_GENERAL, "Published time was unparseable"); return -1;
|
||||
}
|
||||
#else
|
||||
unsigned int year=0, month=0, day=0, hour=100, minute=100, second=100;
|
||||
if (sscanf(cp, "%u-%u-%u %u:%u:%u", &year, &month,
|
||||
&day, &hour, &minute, &second) < 6) {
|
||||
log_fn(LOG_WARN, "Published time was unparseable"); return -1;
|
||||
warn(LD_GENERAL, "Published time was unparseable"); return -1;
|
||||
}
|
||||
if (year < 1970 || month < 1 || month > 12 || day < 1 || day > 31 ||
|
||||
hour > 23 || minute > 59 || second > 61) {
|
||||
log_fn(LOG_WARN, "Published time was nonsensical"); return -1;
|
||||
warn(LD_GENERAL, "Published time was nonsensical"); return -1;
|
||||
}
|
||||
st_tm.tm_year = year-1900;
|
||||
st_tm.tm_mon = month-1;
|
||||
@ -873,22 +873,22 @@ check_private_dir(const char *dirname, cpd_check_t check)
|
||||
tor_free(f);
|
||||
if (r) {
|
||||
if (errno != ENOENT) {
|
||||
log(LOG_WARN, "Directory %s cannot be read: %s", dirname,
|
||||
log(LOG_WARN, LD_FS, "Directory %s cannot be read: %s", dirname,
|
||||
strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
if (check == CPD_NONE) {
|
||||
log(LOG_WARN, "Directory %s does not exist.", dirname);
|
||||
log(LOG_WARN, LD_FS, "Directory %s does not exist.", dirname);
|
||||
return -1;
|
||||
} else if (check == CPD_CREATE) {
|
||||
log(LOG_INFO, "Creating directory %s", dirname);
|
||||
info(LD_GENERAL, "Creating directory %s", dirname);
|
||||
#ifdef MS_WINDOWS
|
||||
r = mkdir(dirname);
|
||||
#else
|
||||
r = mkdir(dirname, 0700);
|
||||
#endif
|
||||
if (r) {
|
||||
log(LOG_WARN, "Error creating directory %s: %s", dirname,
|
||||
log(LOG_WARN, LD_FS, "Error creating directory %s: %s", dirname,
|
||||
strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
@ -898,18 +898,18 @@ check_private_dir(const char *dirname, cpd_check_t check)
|
||||
return 0;
|
||||
}
|
||||
if (!(st.st_mode & S_IFDIR)) {
|
||||
log(LOG_WARN, "%s is not a directory", dirname);
|
||||
log(LOG_WARN, LD_FS, "%s is not a directory", dirname);
|
||||
return -1;
|
||||
}
|
||||
#ifndef MS_WINDOWS
|
||||
if (st.st_uid != getuid()) {
|
||||
log(LOG_WARN, "%s is not owned by this UID (%d). You must fix this to proceed.", dirname, (int)getuid());
|
||||
log(LOG_WARN, LD_FS, "%s is not owned by this UID (%d). You must fix this to proceed.", dirname, (int)getuid());
|
||||
return -1;
|
||||
}
|
||||
if (st.st_mode & 0077) {
|
||||
log(LOG_WARN, "Fixing permissions on directory %s", dirname);
|
||||
log(LOG_WARN, LD_FS, "Fixing permissions on directory %s", dirname);
|
||||
if (chmod(dirname, 0700)) {
|
||||
log(LOG_WARN, "Could not chmod directory %s: %s", dirname,
|
||||
log(LOG_WARN, LD_GENERAL, "Could not chmod directory %s: %s", dirname,
|
||||
strerror(errno));
|
||||
return -1;
|
||||
} else {
|
||||
@ -930,7 +930,7 @@ write_str_to_file(const char *fname, const char *str, int bin)
|
||||
{
|
||||
#ifdef MS_WINDOWS
|
||||
if (!bin && strchr(str, '\r')) {
|
||||
log_fn(LOG_WARN,
|
||||
warn(LD_GENERAL,
|
||||
"How odd. Writing a string that does contain CR already.");
|
||||
}
|
||||
#endif
|
||||
@ -953,13 +953,13 @@ write_chunks_to_file_impl(const char *fname, const smartlist_t *chunks,
|
||||
strlcpy(tempname, fname, tempname_len);
|
||||
} else {
|
||||
if (tor_snprintf(tempname, tempname_len, "%s.tmp", fname)<0) {
|
||||
log(LOG_WARN, "Failed to generate filename");
|
||||
log(LOG_WARN, LD_GENERAL, "Failed to generate filename");
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
if ((fd = open(tempname, open_flags, 0600))
|
||||
< 0) {
|
||||
log(LOG_WARN, "Couldn't open \"%s\" for writing: %s", tempname,
|
||||
log(LOG_WARN, LD_FS, "Couldn't open \"%s\" for writing: %s", tempname,
|
||||
strerror(errno));
|
||||
goto err;
|
||||
}
|
||||
@ -967,18 +967,18 @@ write_chunks_to_file_impl(const char *fname, const smartlist_t *chunks,
|
||||
{
|
||||
result = write_all(fd, chunk->bytes, chunk->len, 0);
|
||||
if (result < 0 || (size_t)result != chunk->len) {
|
||||
log(LOG_WARN, "Error writing to \"%s\": %s", tempname, strerror(errno));
|
||||
log(LOG_WARN, LD_FS, "Error writing to \"%s\": %s", tempname, strerror(errno));
|
||||
close(fd);
|
||||
goto err;
|
||||
}
|
||||
});
|
||||
if (close(fd)) {
|
||||
log(LOG_WARN,"Error flushing to \"%s\": %s", tempname, strerror(errno));
|
||||
log(LOG_WARN, LD_FS, "Error flushing to \"%s\": %s", tempname, strerror(errno));
|
||||
goto err;
|
||||
}
|
||||
if (!(open_flags & O_APPEND)) {
|
||||
if (replace_file(tempname, fname)) {
|
||||
log(LOG_WARN, "Error replacing \"%s\": %s", fname, strerror(errno));
|
||||
log(LOG_WARN, LD_FS, "Error replacing \"%s\": %s", fname, strerror(errno));
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
@ -1053,13 +1053,13 @@ read_file_to_str(const char *filename, int bin)
|
||||
r = stat(f, &statbuf);
|
||||
tor_free(f);
|
||||
if (r < 0) {
|
||||
log_fn(LOG_INFO,"Could not stat \"%s\".",filename);
|
||||
info(LD_FS,"Could not stat \"%s\".",filename);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
fd = open(filename,O_RDONLY|(bin?O_BINARY:O_TEXT),0);
|
||||
if (fd<0) {
|
||||
log_fn(LOG_WARN,"Could not open \"%s\".",filename);
|
||||
warn(LD_FS,"Could not open \"%s\".",filename);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -1067,8 +1067,8 @@ read_file_to_str(const char *filename, int bin)
|
||||
|
||||
r = read_all(fd,string,statbuf.st_size,0);
|
||||
if (r<0) {
|
||||
log_fn(LOG_WARN,"Error reading from file \"%s\": %s", filename,
|
||||
strerror(errno));
|
||||
warn(LD_FS,"Error reading from file \"%s\": %s", filename,
|
||||
strerror(errno));
|
||||
tor_free(string);
|
||||
close(fd);
|
||||
return NULL;
|
||||
@ -1078,7 +1078,7 @@ read_file_to_str(const char *filename, int bin)
|
||||
if (bin && r != statbuf.st_size) {
|
||||
/* If we're in binary mode, then we'd better have an exact match for
|
||||
* size. Otherwise, win32 encoding may throw us off, and that's okay. */
|
||||
log_fn(LOG_WARN,"Could read only %d of %ld bytes of file \"%s\".",
|
||||
warn(LD_FS,"Could read only %d of %ld bytes of file \"%s\".",
|
||||
r, (long)statbuf.st_size,filename);
|
||||
tor_free(string);
|
||||
close(fd);
|
||||
@ -1086,7 +1086,7 @@ read_file_to_str(const char *filename, int bin)
|
||||
}
|
||||
#ifdef MS_WINDOWS
|
||||
if (!bin && strchr(string, '\r')) {
|
||||
log_fn(LOG_DEBUG, "We didn't convert CRLF to LF as well as we hoped when reading %s. Coping.",
|
||||
debug(LD_FS, "We didn't convert CRLF to LF as well as we hoped when reading %s. Coping.",
|
||||
filename);
|
||||
tor_strstrip(string, "\r");
|
||||
}
|
||||
@ -1181,7 +1181,7 @@ expand_filename(const char *filename)
|
||||
if (filename[1] == '/' || filename[1] == '\0') {
|
||||
home = getenv("HOME");
|
||||
if (!home) {
|
||||
log_fn(LOG_WARN, "Couldn't find $HOME environment variable while expanding %s", filename);
|
||||
warn(LD_CONFIG, "Couldn't find $HOME environment variable while expanding %s", filename);
|
||||
return NULL;
|
||||
}
|
||||
home = tor_strdup(home);
|
||||
@ -1195,14 +1195,14 @@ expand_filename(const char *filename)
|
||||
else
|
||||
username = tor_strdup(filename+1);
|
||||
if (!(home = get_user_homedir(username))) {
|
||||
log_fn(LOG_WARN,"Couldn't get homedir for \"%s\"",username);
|
||||
warn(LD_CONFIG,"Couldn't get homedir for \"%s\"",username);
|
||||
tor_free(username);
|
||||
return NULL;
|
||||
}
|
||||
tor_free(username);
|
||||
rest = slash ? (slash+1) : NULL;
|
||||
#else
|
||||
log_fn(LOG_WARN, "Couldn't expend homedir on system without pwd.h");
|
||||
warn(LD_CONFIG, "Couldn't expend homedir on system without pwd.h");
|
||||
return tor_strdup(filename);
|
||||
#endif
|
||||
}
|
||||
@ -1328,11 +1328,11 @@ parse_addr_port(const char *addrport, char **address, uint32_t *addr,
|
||||
_address = tor_strndup(addrport, colon-addrport);
|
||||
_port = (int) tor_parse_long(colon+1,10,1,65535,NULL,NULL);
|
||||
if (!_port) {
|
||||
log_fn(LOG_WARN, "Port '%s' out of range", colon+1);
|
||||
warn(LD_GENERAL, "Port '%s' out of range", colon+1);
|
||||
ok = 0;
|
||||
}
|
||||
if (!port_out) {
|
||||
log_fn(LOG_WARN, "Port '%s' given on '%s' when not required", colon+1,
|
||||
warn(LD_GENERAL, "Port '%s' given on '%s' when not required", colon+1,
|
||||
addrport);
|
||||
ok = 0;
|
||||
}
|
||||
@ -1344,7 +1344,7 @@ parse_addr_port(const char *addrport, char **address, uint32_t *addr,
|
||||
if (addr) {
|
||||
/* There's an addr pointer, so we need to resolve the hostname. */
|
||||
if (tor_lookup_hostname(_address,addr)) {
|
||||
log_fn(LOG_WARN, "Couldn't look up '%s'", _address);
|
||||
warn(LD_NET, "Couldn't look up '%s'", _address);
|
||||
ok = 0;
|
||||
*addr = 0;
|
||||
}
|
||||
@ -1403,7 +1403,7 @@ parse_addr_and_port_range(const char *s, uint32_t *addr_out,
|
||||
} else if (tor_inet_aton(address, &in) != 0) {
|
||||
*addr_out = ntohl(in.s_addr);
|
||||
} else {
|
||||
log_fn(LOG_WARN, "Malformed IP \"%s\" in address pattern; rejecting.",address);
|
||||
warn(LD_GENERAL, "Malformed IP \"%s\" in address pattern; rejecting.",address);
|
||||
goto err;
|
||||
}
|
||||
|
||||
@ -1418,14 +1418,14 @@ parse_addr_and_port_range(const char *s, uint32_t *addr_out,
|
||||
if (!*endptr) {
|
||||
/* strtol handled the whole mask. */
|
||||
if (bits < 0 || bits > 32) {
|
||||
log_fn(LOG_WARN, "Bad number of mask bits on address range; rejecting.");
|
||||
warn(LD_GENERAL, "Bad number of mask bits on address range; rejecting.");
|
||||
goto err;
|
||||
}
|
||||
*mask_out = ~((1<<(32-bits))-1);
|
||||
} else if (tor_inet_aton(mask, &in) != 0) {
|
||||
*mask_out = ntohl(in.s_addr);
|
||||
} else {
|
||||
log_fn(LOG_WARN, "Malformed mask \"%s\" on address range; rejecting.",
|
||||
warn(LD_GENERAL, "Malformed mask \"%s\" on address range; rejecting.",
|
||||
mask);
|
||||
goto err;
|
||||
}
|
||||
@ -1444,18 +1444,18 @@ parse_addr_and_port_range(const char *s, uint32_t *addr_out,
|
||||
*port_max_out = (uint16_t) tor_parse_long(port, 10, 1, 65535, NULL,
|
||||
&endptr);
|
||||
if (*endptr || !*port_max_out) {
|
||||
log_fn(LOG_WARN, "Malformed port \"%s\" on address range rejecting.",
|
||||
warn(LD_GENERAL, "Malformed port \"%s\" on address range rejecting.",
|
||||
port);
|
||||
}
|
||||
} else if (*endptr || !*port_min_out) {
|
||||
log_fn(LOG_WARN, "Malformed port \"%s\" on address range; rejecting.",
|
||||
warn(LD_GENERAL, "Malformed port \"%s\" on address range; rejecting.",
|
||||
port);
|
||||
goto err;
|
||||
} else {
|
||||
*port_max_out = *port_min_out;
|
||||
}
|
||||
if (*port_min_out > *port_max_out) {
|
||||
log_fn(LOG_WARN,"Insane port range on address policy; rejecting.");
|
||||
warn(LD_GENERAL, "Insane port range on address policy; rejecting.");
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
@ -1531,7 +1531,7 @@ get_interface_address(uint32_t *addr)
|
||||
sock = socket(PF_INET,SOCK_DGRAM,IPPROTO_UDP);
|
||||
if (sock < 0) {
|
||||
int e = tor_socket_errno(-1);
|
||||
log_fn(LOG_WARN, "unable to create socket: %s", tor_socket_strerror(e));
|
||||
warn(LD_NET, "unable to create socket: %s", tor_socket_strerror(e));
|
||||
goto err;
|
||||
}
|
||||
|
||||
@ -1545,14 +1545,14 @@ get_interface_address(uint32_t *addr)
|
||||
|
||||
if (connect(sock,(struct sockaddr *)&target_addr,sizeof(target_addr))<0) {
|
||||
int e = tor_socket_errno(sock);
|
||||
log_fn(LOG_WARN, "connnect() failed: %s", tor_socket_strerror(e));
|
||||
warn(LD_NET, "connnect() failed: %s", tor_socket_strerror(e));
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* XXXX Can this be right on IPv6 clients? */
|
||||
if (getsockname(sock, (struct sockaddr*)&my_addr, &my_addr_len)) {
|
||||
int e = tor_socket_errno(sock);
|
||||
log_fn(LOG_WARN, "getsockname() failed: %s", tor_socket_strerror(e));
|
||||
warn(LD_NET, "getsockname() failed: %s", tor_socket_strerror(e));
|
||||
goto err;
|
||||
}
|
||||
|
||||
@ -1591,7 +1591,7 @@ start_daemon(void)
|
||||
pipe(daemon_filedes);
|
||||
pid = fork();
|
||||
if (pid < 0) {
|
||||
log_fn(LOG_ERR,"fork failed. Exiting.");
|
||||
err("fork failed. Exiting.");
|
||||
exit(1);
|
||||
}
|
||||
if (pid) { /* Parent */
|
||||
@ -1646,14 +1646,14 @@ finish_daemon(const char *desired_cwd)
|
||||
desired_cwd = "/";
|
||||
/* Don't hold the wrong FS mounted */
|
||||
if (chdir(desired_cwd) < 0) {
|
||||
log_fn(LOG_ERR,"chdir to \"%s\" failed. Exiting.",desired_cwd);
|
||||
err("chdir to \"%s\" failed. Exiting.",desired_cwd);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
nullfd = open("/dev/null",
|
||||
O_CREAT | O_RDWR | O_APPEND);
|
||||
if (nullfd < 0) {
|
||||
log_fn(LOG_ERR,"/dev/null can't be opened. Exiting.");
|
||||
err("/dev/null can't be opened. Exiting.");
|
||||
exit(1);
|
||||
}
|
||||
/* close fds linking to invoking terminal, but
|
||||
@ -1663,7 +1663,7 @@ finish_daemon(const char *desired_cwd)
|
||||
if (dup2(nullfd,0) < 0 ||
|
||||
dup2(nullfd,1) < 0 ||
|
||||
dup2(nullfd,2) < 0) {
|
||||
log_fn(LOG_ERR,"dup2 failed. Exiting.");
|
||||
err("dup2 failed. Exiting.");
|
||||
exit(1);
|
||||
}
|
||||
if (nullfd > 2)
|
||||
@ -1692,7 +1692,7 @@ write_pidfile(char *filename)
|
||||
FILE *pidfile;
|
||||
|
||||
if ((pidfile = fopen(filename, "w")) == NULL) {
|
||||
log_fn(LOG_WARN, "Unable to open \"%s\" for writing: %s", filename,
|
||||
warn(LD_FS, "Unable to open \"%s\" for writing: %s", filename,
|
||||
strerror(errno));
|
||||
} else {
|
||||
fprintf(pidfile, "%d\n", (int)getpid());
|
||||
|
@ -38,14 +38,25 @@
|
||||
*/
|
||||
#error "Sorry; we don't support building with NDEBUG."
|
||||
#else
|
||||
#define tor_assert(expr) do { \
|
||||
if (!(expr)) { \
|
||||
log(LOG_ERR, "%s:%d: %s: Assertion %s failed; aborting.", \
|
||||
_SHORT_FILE_, __LINE__, __FUNCTION__, #expr); \
|
||||
fprintf(stderr,"%s:%d %s: Assertion %s failed; aborting.\n", \
|
||||
_SHORT_FILE_, __LINE__, __FUNCTION__, #expr); \
|
||||
abort(); /* unreached */ \
|
||||
#ifdef OLD_LOG_INTERFACE
|
||||
#define tor_assert(expr) do { \
|
||||
if (!(expr)) { \
|
||||
log(LOG_ERR, "%s:%d: %s: Assertion %s failed; aborting.", \
|
||||
_SHORT_FILE_, __LINE__, __FUNCTION__, #expr); \
|
||||
fprintf(stderr,"%s:%d %s: Assertion %s failed; aborting.\n", \
|
||||
_SHORT_FILE_, __LINE__, __FUNCTION__, #expr); \
|
||||
abort(); /* unreached */ \
|
||||
} } while (0)
|
||||
#else
|
||||
#define tor_assert(expr) do { \
|
||||
if (!(expr)) { \
|
||||
log(LOG_ERR, LD_GENERAL, "%s:%d: %s: Assertion %s failed; aborting.", \
|
||||
_SHORT_FILE_, __LINE__, __FUNCTION__, #expr); \
|
||||
fprintf(stderr,"%s:%d %s: Assertion %s failed; aborting.\n", \
|
||||
_SHORT_FILE_, __LINE__, __FUNCTION__, #expr); \
|
||||
abort(); /* unreached */ \
|
||||
} } while (0)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef USE_DMALLOC
|
||||
|
@ -133,6 +133,7 @@
|
||||
|
||||
#include "../common/crypto.h"
|
||||
#include "../common/tortls.h"
|
||||
#define OLD_LOG_INTERFACE
|
||||
#include "../common/log.h"
|
||||
#include "../common/compat.h"
|
||||
#include "../common/container.h"
|
||||
|
@ -1506,6 +1506,7 @@ router_load_routers_from_string(const char *s, int from_cache,
|
||||
if (smartlist_len(changed))
|
||||
control_event_descriptors_changed(changed);
|
||||
|
||||
routerlist_assert_ok(routerlist);
|
||||
router_rebuild_store(0);
|
||||
|
||||
smartlist_free(routers);
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
#include "orconfig.h"
|
||||
|
||||
#define OLD_LOG_INTERFACE
|
||||
#include "../common/compat.h"
|
||||
#include "../common/util.h"
|
||||
#include "../common/log.h"
|
||||
|
Loading…
Reference in New Issue
Block a user