[or-cvs] Start the process of converting warn to log_warn and so on.

arma at seul.org arma at seul.org
Mon Feb 13 08:02:01 UTC 2006


Update of /home2/or/cvsroot/tor/src/common
In directory moria:/home/arma/work/onion/cvs/tor/src/common

Modified Files:
	compat.c crypto.c log.h torgzip.c tortls.c util.c 
Log Message:
Start the process of converting warn to log_warn and so on.
This is needed because Windows already has an err() that we
can't clobber. And we need to be able to make the log functions
a macro so we can print the function's name in the log entry.


Index: compat.c
===================================================================
RCS file: /home2/or/cvsroot/tor/src/common/compat.c,v
retrieving revision 1.82
retrieving revision 1.83
diff -u -p -d -r1.82 -r1.83
--- compat.c	9 Feb 2006 05:46:48 -0000	1.82
+++ compat.c	13 Feb 2006 08:01:59 -0000	1.83
@@ -359,7 +359,7 @@ tor_socketpair(int family, int type, int
     if (listener == -1)
       return -tor_socket_errno(-1);
     if (!SOCKET_IS_POLLABLE(listener)) {
-      warn(LD_NET, "Too many connections; can't open socketpair");
+      log_warn(LD_NET, "Too many connections; can't open socketpair");
       tor_close_socket(listener);
 #ifdef MS_WINDOWS
       return -ENFILE;
@@ -381,7 +381,7 @@ tor_socketpair(int family, int type, int
     if (connector == -1)
       goto tidy_up_and_fail;
     if (!SOCKET_IS_POLLABLE(connector)) {
-      warn(LD_NET, "Too many connections; can't open socketpair");
+      log_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.  */
@@ -399,7 +399,7 @@ tor_socketpair(int family, int type, int
     if (acceptor == -1)
       goto tidy_up_and_fail;
     if (!SOCKET_IS_POLLABLE(acceptor)) {
-      warn(LD_NET, "Too many connections; can't open socketpair");
+      log_warn(LD_NET, "Too many connections; can't open socketpair");
       goto tidy_up_and_fail;
     }
     if (size != sizeof(listen_addr))
@@ -457,7 +457,7 @@ set_max_file_descriptors(unsigned long l
   log_fn(LOG_INFO, LD_NET,
          "This platform is missing getrlimit(). Proceeding.");
   if (limit < cap) {
-    log(LOG_INFO, LD_CONFIG, "ConnLimit must be at most %d. Using that.", cap);
+    log_info(LD_CONFIG, "ConnLimit must be at most %d. Using that.", cap);
     limit = cap;
   }
 #else
@@ -467,25 +467,25 @@ set_max_file_descriptors(unsigned long l
   tor_assert(cap > 0);
 
   if (getrlimit(RLIMIT_NOFILE, &rlim) != 0) {
-    warn(LD_NET, "Could not get maximum number of file descriptors: %s",
-           strerror(errno));
+    log_warn(LD_NET, "Could not get maximum number of file descriptors: %s",
+             strerror(errno));
     return -1;
   }
   if (rlim.rlim_max < limit) {
-    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);
+    log_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) {
-    info(LD_NET,"Raising max file descriptors from %lu to %lu.",
-           (unsigned long)rlim.rlim_cur, most);
+    log_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) {
-    warn(LD_CONFIG, "Could not set maximum number of file descriptors: %s",
-           strerror(errno));
+    log_warn(LD_CONFIG, "Could not set maximum number of file descriptors: %s",
+             strerror(errno));
     return -1;
   }
   /* leave some overhead for logs, etc, */
@@ -493,7 +493,8 @@ set_max_file_descriptors(unsigned long l
 #endif
 
   if (limit < ULIMIT_BUFFER) {
-    warn(LD_CONFIG,"ConnLimit must be at least %d. Failing.", ULIMIT_BUFFER);
+    log_warn(LD_CONFIG,
+             "ConnLimit must be at least %d. Failing.", ULIMIT_BUFFER);
     return -1;
   }
   return limit - ULIMIT_BUFFER;
@@ -512,7 +513,7 @@ switch_id(char *user, char *group)
   if (user) {
     pw = getpwnam(user);
     if (pw == NULL) {
-      err(LD_CONFIG,"User '%s' not found.", user);
+      log_err(LD_CONFIG,"User '%s' not found.", user);
       return -1;
     }
   }
@@ -521,17 +522,17 @@ switch_id(char *user, char *group)
   if (group) {
     gr = getgrnam(group);
     if (gr == NULL) {
-      err(LD_CONFIG,"Group '%s' not found.", group);
+      log_err(LD_CONFIG,"Group '%s' not found.", group);
       return -1;
     }
 
     if (setgid(gr->gr_gid) != 0) {
-      err(LD_GENERAL,"Error setting GID: %s", strerror(errno));
+      log_err(LD_GENERAL,"Error setting GID: %s", strerror(errno));
       return -1;
     }
   } else if (user) {
     if (setgid(pw->pw_gid) != 0) {
-      err(LD_GENERAL,"Error setting GID: %s", strerror(errno));
+      log_err(LD_GENERAL,"Error setting GID: %s", strerror(errno));
       return -1;
     }
   }
@@ -540,7 +541,7 @@ switch_id(char *user, char *group)
      privileges */
   if (user) {
     if (setuid(pw->pw_uid) != 0) {
-      err(LD_GENERAL,"Error setting UID: %s", strerror(errno));
+      log_err(LD_GENERAL,"Error setting UID: %s", strerror(errno));
       return -1;
     }
   }
@@ -548,8 +549,8 @@ switch_id(char *user, char *group)
   return 0;
 #endif
 
-  err(LD_CONFIG,
-      "User or group specified, but switching users is not supported.");
+  log_err(LD_CONFIG,
+          "User or group specified, but switching users is not supported.");
   return -1;
 }
 
@@ -563,7 +564,7 @@ get_user_homedir(const char *username)
   tor_assert(username);
 
   if (!(pw = getpwnam(username))) {
-    err(LD_CONFIG,"User \"%s\" not found.", username);
+    log_err(LD_CONFIG,"User \"%s\" not found.", username);
     return NULL;
   }
   return tor_strdup(pw->pw_dir);
@@ -909,7 +910,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) {
-    err(LD_GENERAL,"System time is before 1970; failing.");
+    log_err(LD_GENERAL,"System time is before 1970; failing.");
     exit(1);
   }
   ft.ft_64 -= EPOCH_BIAS;
@@ -917,7 +918,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)) {
-    err(LD_GENERAL,"gettimeofday failed.");
+    log_err(LD_GENERAL,"gettimeofday failed.");
     /* If gettimeofday dies, we have either given a bad timezone (we didn't),
        or segfaulted.*/
     exit(1);
@@ -1026,7 +1027,7 @@ tor_mutex_acquire(tor_mutex_t *m)
       tor_assert(0);
       break;
     case WAIT_FAILED:
-      warn(LD_GENERAL, "Failed to acquire mutex: %d", GetLastError());
+      log_warn(LD_GENERAL, "Failed to acquire mutex: %d", GetLastError());
   }
 }
 void
@@ -1035,7 +1036,7 @@ tor_mutex_release(tor_mutex_t *m)
   BOOL r;
   r = ReleaseMutex(m->handle);
   if (!r) {
-    warn(LD_GENERAL, "Failed to release mutex: %d", GetLastError());
+    log_warn(LD_GENERAL, "Failed to release mutex: %d", GetLastError());
   }
 }
 unsigned long
@@ -1207,7 +1208,7 @@ network_init(void)
   int r;
   r = WSAStartup(0x101,&WSAData);
   if (r) {
-    warn(LD_NET,"Error initializing windows network layer: code was %d",r);
+    log_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.

Index: crypto.c
===================================================================
RCS file: /home2/or/cvsroot/tor/src/common/crypto.c,v
retrieving revision 1.186
retrieving revision 1.187
diff -u -p -d -r1.186 -r1.187
--- crypto.c	9 Feb 2006 05:46:48 -0000	1.186
+++ crypto.c	13 Feb 2006 08:01:59 -0000	1.187
@@ -206,8 +206,8 @@ crypto_global_init(int useAccel)
 #ifndef NO_ENGINES
     if (useAccel) {
       if (useAccel < 0)
-        warn(LD_CRYPTO, "Initializing OpenSSL via tor_tls_init().");
-      info(LD_CRYPTO, "Initializing OpenSSL engine support.");
+        log_warn(LD_CRYPTO, "Initializing OpenSSL via tor_tls_init().");
+      log_info(LD_CRYPTO, "Initializing OpenSSL engine support.");
       ENGINE_load_builtin_engines();
       if (!ENGINE_register_all_complete())
         return -1;
@@ -363,7 +363,7 @@ crypto_create_init_cipher(const char *ke
   crypto_cipher_env_t *crypto = NULL;
 
   if (! (crypto = crypto_new_cipher_env())) {
-    warn(LD_CRYPTO, "Unable to allocate crypto object");
+    log_warn(LD_CRYPTO, "Unable to allocate crypto object");
     return NULL;
   }
 
@@ -474,7 +474,7 @@ crypto_pk_read_private_key_from_filename
   /* Read the file into a string. */
   contents = read_file_to_str(keyfile, 0);
   if (!contents) {
-    warn(LD_CRYPTO, "Error reading private key from \"%s\"", keyfile);
+    log_warn(LD_CRYPTO, "Error reading private key from \"%s\"", keyfile);
     return -1;
   }
 
@@ -616,7 +616,7 @@ crypto_pk_DER64_encode_public_key(crypto
   }
   *out = tor_malloc(len * 2); /* too long, but safe. */
   if (base64_encode(*out, len*2, buf, len) < 0) {
-    warn(LD_CRYPTO, "Error base64-encoding DER-encoded key");
+    log_warn(LD_CRYPTO, "Error base64-encoding DER-encoded key");
     tor_free(*out);
     return -1;
   }
@@ -652,7 +652,7 @@ crypto_pk_DER64_decode_public_key(const 
     return NULL;
   len = base64_decode(buf, sizeof(buf), partitioned, strlen(partitioned));
   if (len<0) {
-    warn(LD_CRYPTO,"Error base-64 decoding key");
+    log_warn(LD_CRYPTO,"Error base-64 decoding key");
     return NULL;
   }
   return crypto_pk_asn1_decode(buf, len);
@@ -810,16 +810,16 @@ crypto_pk_public_checksig_digest(crypto_
   tor_assert(sig);
 
   if (crypto_digest(digest,data,datalen)<0) {
-    warn(LD_CRYPTO, "couldn't compute digest");
+    log_warn(LD_CRYPTO, "couldn't compute digest");
     return -1;
   }
   r = crypto_pk_public_checksig(env,buf,sig,siglen);
   if (r != DIGEST_LEN) {
-    warn(LD_CRYPTO, "Invalid signature");
+    log_warn(LD_CRYPTO, "Invalid signature");
     return -1;
   }
   if (memcmp(buf, digest, DIGEST_LEN)) {
-    warn(LD_CRYPTO, "Signature mismatched with digest.");
+    log_warn(LD_CRYPTO, "Signature mismatched with digest.");
     return -1;
   }
 
@@ -1415,8 +1415,8 @@ crypto_dh_generate_public(crypto_dh_env_
     return -1;
   }
   if (tor_check_dh_key(dh->dh->pub_key)<0) {
-    warn(LD_CRYPTO, "Weird! Our own DH key was invalid.  I guess once-in-"
-         "the-universe chances really do happen.  Trying again.");
+    log_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);
@@ -1444,8 +1444,9 @@ crypto_dh_get_public(crypto_dh_env_t *dh
   bytes = BN_num_bytes(dh->dh->pub_key);
   tor_assert(bytes >= 0);
   if (pubkey_len < (size_t)bytes) {
-    warn(LD_CRYPTO, "Weird! pubkey_len (%d) was smaller than DH_BYTES (%d)",
-         (int) pubkey_len, bytes);
+    log_warn(LD_CRYPTO,
+             "Weird! pubkey_len (%d) was smaller than DH_BYTES (%d)",
+             (int) pubkey_len, bytes);
     return -1;
   }
 
@@ -1471,13 +1472,13 @@ tor_check_dh_key(BIGNUM *bn)
     init_dh_param();
   BN_set_word(x, 1);
   if (BN_cmp(bn,x)<=0) {
-    warn(LD_CRYPTO, "DH key must be at least 2.");
+    log_warn(LD_CRYPTO, "DH key must be at least 2.");
     goto err;
   }
   BN_copy(x,dh_param_p);
   BN_sub_word(x, 1);
   if (BN_cmp(bn,x)>=0) {
-    warn(LD_CRYPTO, "DH key must be at most p-2.");
+    log_warn(LD_CRYPTO, "DH key must be at most p-2.");
     goto err;
   }
   BN_free(x);
@@ -1485,7 +1486,7 @@ tor_check_dh_key(BIGNUM *bn)
  err:
   BN_free(x);
   s = BN_bn2hex(bn);
-  warn(LD_CRYPTO, "Rejecting insecure DH key [%s]", s);
+  log_warn(LD_CRYPTO, "Rejecting insecure DH key [%s]", s);
   OPENSSL_free(s);
   return -1;
 }
@@ -1518,13 +1519,13 @@ crypto_dh_compute_secret(crypto_dh_env_t
     goto error;
   if (tor_check_dh_key(pubkey_bn)<0) {
     /* Check for invalid public keys. */
-    warn(LD_CRYPTO,"Rejected invalid g^x");
+    log_warn(LD_CRYPTO,"Rejected invalid g^x");
     goto error;
   }
   secret_tmp = tor_malloc(crypto_dh_get_bytes(dh));
   result = DH_compute_key((unsigned char*)secret_tmp, pubkey_bn, dh->dh);
   if (result < 0) {
-    warn(LD_CRYPTO,"DH_compute_key() failed.");
+    log_warn(LD_CRYPTO,"DH_compute_key() failed.");
     goto error;
   }
   secret_len = result;
@@ -1644,7 +1645,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)
-    warn(LD_CRYPTO, "RAND_poll() failed.");
+    log_warn(LD_CRYPTO, "RAND_poll() failed.");
 #else
   rand_poll_status = 0;
 #endif
@@ -1654,14 +1655,14 @@ crypto_seed_rng(void)
     if (!CryptAcquireContext(&provider, NULL, NULL, PROV_RSA_FULL,
                              CRYPT_VERIFYCONTEXT)) {
       if (GetLastError() != NTE_BAD_KEYSET) {
-        warn(LD_CRYPTO, "Can't get CryptoAPI provider [1]");
+        log_warn(LD_CRYPTO, "Can't get CryptoAPI provider [1]");
         return rand_poll_status ? 0 : -1;
       }
     }
     provider_set = 1;
   }
   if (!CryptGenRandom(provider, sizeof(buf), buf)) {
-    warn(LD_CRYPTO, "Can't get entropy from CryptoAPI.");
+    log_warn(LD_CRYPTO, "Can't get entropy from CryptoAPI.");
     return rand_poll_status ? 0 : -1;
   }
   RAND_seed(buf, sizeof(buf));
@@ -1670,19 +1671,19 @@ crypto_seed_rng(void)
   for (i = 0; filenames[i]; ++i) {
     fd = open(filenames[i], O_RDONLY, 0);
     if (fd<0) continue;
-    info(LD_CRYPTO, "Seeding RNG from \"%s\"", filenames[i]);
+    log_info(LD_CRYPTO, "Seeding RNG from \"%s\"", filenames[i]);
     n = read_all(fd, buf, sizeof(buf), 0);
     close(fd);
     if (n != sizeof(buf)) {
-      warn(LD_CRYPTO,
-           "Error reading from entropy source (read only %d bytes).", n);
+      log_warn(LD_CRYPTO,
+               "Error reading from entropy source (read only %d bytes).", n);
       return -1;
     }
     RAND_seed(buf, sizeof(buf));
     return 0;
   }
 
-  warn(LD_CRYPTO, "Cannot seed RNG -- no entropy source found.");
+  log_warn(LD_CRYPTO, "Cannot seed RNG -- no entropy source found.");
   return rand_poll_status ? 0 : -1;
 #endif
 }

Index: log.h
===================================================================
RCS file: /home2/or/cvsroot/tor/src/common/log.h,v
retrieving revision 1.64
retrieving revision 1.65
diff -u -p -d -r1.64 -r1.65
--- log.h	9 Feb 2006 05:46:48 -0000	1.64
+++ log.h	13 Feb 2006 08:01:59 -0000	1.65
@@ -128,15 +128,15 @@ void _log_fn(int severity, uint32_t doma
  * of the current function name. */
 #define log_fn(severity, domain, args...)               \
   _log_fn(severity, domain, __PRETTY_FUNCTION__, args)
-#define debug(domain, args...)                          \
+#define log_debug(domain, args...)                          \
   _log_fn(LOG_DEBUG, domain, __PRETTY_FUNCTION__, args)
-#define info(domain, args...)                           \
+#define log_info(domain, args...)                           \
   _log_fn(LOG_INFO, domain, __PRETTY_FUNCTION__, args)
-#define notice(domain, args...)                         \
+#define log_notice(domain, args...)                         \
   _log_fn(LOG_NOTICE, domain, __PRETTY_FUNCTION__, args)
-#define warn(domain, args...)                           \
+#define log_warn(domain, args...)                           \
   _log_fn(LOG_WARN, domain, __PRETTY_FUNCTION__, args)
-#define err(domain, args...)                            \
+#define log_err(domain, args...)                            \
   _log_fn(LOG_ERR, domain, __PRETTY_FUNCTION__, args)
 
 #else /* ! defined(__GNUC__) */

Index: torgzip.c
===================================================================
RCS file: /home2/or/cvsroot/tor/src/common/torgzip.c,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -p -d -r1.28 -r1.29
--- torgzip.c	12 Feb 2006 23:43:17 -0000	1.28
+++ torgzip.c	13 Feb 2006 08:01:59 -0000	1.29
@@ -76,7 +76,7 @@ tor_gzip_compress(char **out, size_t *ou
 
   if (method == GZIP_METHOD && !is_gzip_supported()) {
     /* Old zlib version don't support gzip in deflateInit2 */
-    warn(LD_GENERAL, "Gzip not supported with zlib %s", ZLIB_VERSION);
+    log_warn(LD_GENERAL, "Gzip not supported with zlib %s", ZLIB_VERSION);
     return -1;
   }
 
@@ -92,8 +92,8 @@ tor_gzip_compress(char **out, size_t *ou
   if (deflateInit2(stream, Z_BEST_COMPRESSION, Z_DEFLATED,
                    method_bits(method),
                    8, Z_DEFAULT_STRATEGY) != Z_OK) {
-    warn(LD_GENERAL, "Error from deflateInit2: %s",
-           stream->msg?stream->msg:"<no message>");
+    log_warn(LD_GENERAL, "Error from deflateInit2: %s",
+             stream->msg?stream->msg:"<no message>");
     goto err;
   }
 
@@ -121,15 +121,15 @@ tor_gzip_compress(char **out, size_t *ou
         stream->avail_out = out_size - offset;
         break;
       default:
-        warn(LD_GENERAL, "Gzip compression didn't finish: %s",
-               stream->msg ? stream->msg : "<no message>");
+        log_warn(LD_GENERAL, "Gzip compression didn't finish: %s",
+                 stream->msg ? stream->msg : "<no message>");
         goto err;
       }
   }
  done:
   *out_len = stream->total_out;
   if (deflateEnd(stream)!=Z_OK) {
-    warn(LD_GENERAL, "Error freeing gzip structures");
+    log_warn(LD_GENERAL, "Error freeing gzip structures");
     goto err;
   }
   tor_free(stream);
@@ -171,7 +171,7 @@ tor_gzip_uncompress(char **out, size_t *
 
   if (method == GZIP_METHOD && !is_gzip_supported()) {
     /* Old zlib version don't support gzip in inflateInit2 */
-    warn(LD_GENERAL, "Gzip not supported with zlib %s", ZLIB_VERSION);
+    log_warn(LD_GENERAL, "Gzip not supported with zlib %s", ZLIB_VERSION);
     return -1;
   }
 
@@ -186,8 +186,8 @@ tor_gzip_uncompress(char **out, size_t *
 
   if (inflateInit2(stream,
                    method_bits(method)) != Z_OK) {
-    warn(LD_GENERAL, "Error from inflateInit2: %s",
-           stream->msg?stream->msg:"<no message>");
+    log_warn(LD_GENERAL, "Error from inflateInit2: %s",
+             stream->msg?stream->msg:"<no message>");
     goto err;
   }
 
@@ -206,8 +206,8 @@ tor_gzip_uncompress(char **out, size_t *
           goto done;
         /* There may be more compressed data here. */
         if (inflateInit2(stream, method_bits(method)) != Z_OK) {
-          warn(LD_GENERAL, "Error from inflateInit2: %s",
-                 stream->msg?stream->msg:"<no message>");
+          log_warn(LD_GENERAL, "Error from inflateInit2: %s",
+                   stream->msg?stream->msg:"<no message>");
           goto err;
         }
         break;
@@ -230,8 +230,8 @@ tor_gzip_uncompress(char **out, size_t *
         stream->avail_out = out_size - offset;
         break;
       default:
-        warn(LD_GENERAL, "Gzip decompression returned an error: %s",
-               stream->msg ? stream->msg : "<no message>");
+        log_warn(LD_GENERAL, "Gzip decompression returned an error: %s",
+                 stream->msg ? stream->msg : "<no message>");
         goto err;
       }
   }
@@ -240,7 +240,7 @@ tor_gzip_uncompress(char **out, size_t *
   r = inflateEnd(stream);
   tor_free(stream);
   if (r != Z_OK) {
-    warn(LD_GENERAL, "Error freeing gzip structures");
+    log_warn(LD_GENERAL, "Error freeing gzip structures");
     goto err;
   }
 

Index: tortls.c
===================================================================
RCS file: /home2/or/cvsroot/tor/src/common/tortls.c,v
retrieving revision 1.116
retrieving revision 1.117
diff -u -p -d -r1.116 -r1.117
--- tortls.c	9 Feb 2006 05:46:48 -0000	1.116
+++ tortls.c	13 Feb 2006 08:01:59 -0000	1.117
@@ -495,12 +495,12 @@ tor_tls_read(tor_tls_t *tls, char *cp, s
     return r;
   err = tor_tls_get_error(tls, r, CATCH_ZERO, "reading", LOG_DEBUG);
   if (err == _TOR_TLS_ZERORETURN) {
-    debug(LD_NET,"read returned r=%d; TLS is closed",r);
+    log_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);
-    debug(LD_NET,"read returned r=%d, err=%d",r,err);
+    log_debug(LD_NET,"read returned r=%d, err=%d",r,err);
     return err;
   }
 }
@@ -522,8 +522,8 @@ tor_tls_write(tor_tls_t *tls, char *cp, 
   if (tls->wantwrite_n) {
     /* if WANTWRITE last time, we must use the _same_ n as before */
     tor_assert(n >= tls->wantwrite_n);
-    debug(LD_NET,"resuming pending-write, (%d to flush, reusing %d)",
-           (int)n, (int)tls->wantwrite_n);
+    log_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;
   }
@@ -657,11 +657,11 @@ tor_tls_get_peer_cert_nickname(tor_tls_t
   int r = -1;
 
   if (!(cert = SSL_get_peer_certificate(tls->ssl))) {
-    warn(LD_PROTOCOL, "Peer has no certificate");
+    log_warn(LD_PROTOCOL, "Peer has no certificate");
     goto error;
   }
   if (!(name = X509_get_subject_name(cert))) {
-    warn(LD_PROTOCOL, "Peer certificate has no subject name");
+    log_warn(LD_PROTOCOL, "Peer certificate has no subject name");
     goto error;
   }
   if ((nid = OBJ_txt2nid("commonName")) == NID_undef)
@@ -671,11 +671,11 @@ tor_tls_get_peer_cert_nickname(tor_tls_t
   if (lenout == -1)
     goto error;
   if (((int)strspn(buf, LEGAL_NICKNAME_CHARACTERS)) < lenout) {
-    warn(LD_PROTOCOL,
-         "Peer certificate nickname \"%s\" has illegal characters.", buf);
+    log_warn(LD_PROTOCOL,
+             "Peer certificate nickname \"%s\" has illegal characters.", buf);
     if (strchr(buf, '.'))
-      warn(LD_PROTOCOL, "  (Maybe it is not really running Tor at its "
-           "advertised OR port.)");
+      log_warn(LD_PROTOCOL, "  (Maybe it is not really running Tor at its "
+               "advertised OR port.)");
     goto error;
   }
 
@@ -700,11 +700,12 @@ log_cert_lifetime(X509 *cert, const char
   struct tm tm;
 
   if (problem)
-    warn(LD_GENERAL,"Certificate %s: is your system clock set incorrectly?",
-           problem);
+    log_warn(LD_GENERAL,
+             "Certificate %s: is your system clock set incorrectly?",
+             problem);
 
   if (!(bio = BIO_new(BIO_s_mem()))) {
-    warn(LD_GENERAL, "Couldn't allocate BIO!"); goto end;
+    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");
@@ -723,9 +724,9 @@ log_cert_lifetime(X509 *cert, const char
 
   strftime(mytime, 32, "%b %d %H:%M:%S %Y GMT", tor_gmtime_r(&now, &tm));
 
-  warn(LD_GENERAL,
-       "(certificate lifetime runs from %s through %s. Your time is %s.)",
-       s1,s2,mytime);
+  log_warn(LD_GENERAL,
+           "(certificate lifetime runs from %s through %s. Your time is %s.)",
+           s1,s2,mytime);
 
  end:
   /* Not expected to get invoked */

Index: util.c
===================================================================
RCS file: /home2/or/cvsroot/tor/src/common/util.c,v
retrieving revision 1.246
retrieving revision 1.247
diff -u -p -d -r1.246 -r1.247
--- util.c	13 Feb 2006 00:26:43 -0000	1.246
+++ util.c	13 Feb 2006 08:01:59 -0000	1.247
@@ -130,7 +130,7 @@ _tor_malloc(size_t size DMALLOC_PARAMS)
   result = dmalloc_malloc(file, line, size, DMALLOC_FUNC_MALLOC, 0, 0);
 
   if (!result) {
-    err(LD_MM,"Out of memory. Dying.");
+    log_err(LD_MM,"Out of memory. Dying.");
     /* XXX if these functions die within a worker process, they won't
      * call spawn_exit */
     exit(1);
@@ -162,7 +162,7 @@ _tor_realloc(void *ptr, size_t size DMAL
 
   result = dmalloc_realloc(file, line, ptr, size, DMALLOC_FUNC_REALLOC, 0);
   if (!result) {
-    err(LD_MM,"Out of memory. Dying.");
+    log_err(LD_MM,"Out of memory. Dying.");
     exit(1);
   }
   return result;
@@ -180,7 +180,7 @@ _tor_strdup(const char *s DMALLOC_PARAMS
 
   dup = dmalloc_strdup(file, line, s, 0);
   if (!dup) {
-    err(LD_MM,"Out of memory. Dying.");
+    log_err(LD_MM,"Out of memory. Dying.");
     exit(1);
   }
   return dup;
@@ -577,7 +577,7 @@ tv_udiff(struct timeval *start, struct t
   long secdiff = end->tv_sec - start->tv_sec;
 
   if (labs(secdiff+1) > LONG_MAX/1000000) {
-    warn(LD_GENERAL, "comparing times too far apart.");
+    log_warn(LD_GENERAL, "comparing times too far apart.");
     return LONG_MAX;
   }
 
@@ -647,7 +647,7 @@ tor_timegm(struct tm *tm)
   int i;
   year = tm->tm_year + 1900;
   if (year < 1970 || tm->tm_mon < 0 || tm->tm_mon > 11) {
-    warn(LD_BUG, "Out-of-range argument to tor_timegm");
+    log_warn(LD_BUG, "Out-of-range argument to tor_timegm");
     return -1;
   }
   days = 365 * (year-1970) + n_leapdays(1970,year);
@@ -700,7 +700,7 @@ parse_rfc1123_time(const char *buf, time
   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) {
-    warn(LD_GENERAL, "Got invalid RFC1123 time \"%s\"", buf);
+    log_warn(LD_GENERAL, "Got invalid RFC1123 time \"%s\"", buf);
     return -1;
   }
 
@@ -712,13 +712,14 @@ parse_rfc1123_time(const char *buf, time
     }
   }
   if (m<0) {
-    warn(LD_GENERAL, "Got invalid RFC1123 time \"%s\"", buf);
+    log_warn(LD_GENERAL, "Got invalid RFC1123 time \"%s\"", buf);
     return -1;
   }
   tm.tm_mon = m;
 
   if (tm.tm_year < 1970) {
-    warn(LD_GENERAL, "Got invalid RFC1123 time \"%s\". (Before 1970)", buf);
+    log_warn(LD_GENERAL,
+             "Got invalid RFC1123 time \"%s\". (Before 1970)", buf);
     return -1;
   }
   tm.tm_year -= 1900;
@@ -747,17 +748,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)) {
-    warn(LD_GENERAL, "Published time was unparseable"); return -1;
+    log_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) {
-    warn(LD_GENERAL, "Published time was unparseable"); return -1;
+    log_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) {
-    warn(LD_GENERAL, "Published time was nonsensical"); return -1;
+    log_warn(LD_GENERAL, "Published time was nonsensical"); return -1;
   }
   st_tm.tm_year = year-1900;
   st_tm.tm_mon = month-1;
@@ -767,7 +768,7 @@ parse_iso_time(const char *cp, time_t *t
   st_tm.tm_sec = second;
 #endif
   if (st_tm.tm_year < 70) {
-    warn(LD_GENERAL, "Got invalid ISO time \"%s\". (Before 1970)", cp);
+    log_warn(LD_GENERAL, "Got invalid ISO time \"%s\". (Before 1970)", cp);
     return -1;
   }
   *t = tor_timegm(&st_tm);
@@ -903,7 +904,7 @@ check_private_dir(const char *dirname, c
       log(LOG_WARN, LD_FS, "Directory %s does not exist.", dirname);
       return -1;
     } else if (check == CPD_CREATE) {
-      info(LD_GENERAL, "Creating directory %s", dirname);
+      log_info(LD_GENERAL, "Creating directory %s", dirname);
 #ifdef MS_WINDOWS
       r = mkdir(dirname);
 #else
@@ -965,8 +966,8 @@ write_str_to_file(const char *fname, con
 {
 #ifdef MS_WINDOWS
   if (!bin && strchr(str, '\r')) {
-    warn(LD_BUG,
-           "Bug: we're writing a text string that already contains a CR.");
+    log_warn(LD_BUG,
+             "Bug: we're writing a text string that already contains a CR.");
   }
 #endif
   return write_bytes_to_file(fname, str, strlen(str), bin);
@@ -1091,13 +1092,13 @@ read_file_to_str(const char *filename, i
   r = stat(f, &statbuf);
   tor_free(f);
   if (r < 0) {
-    info(LD_FS,"Could not stat \"%s\".",filename);
+    log_info(LD_FS,"Could not stat \"%s\".",filename);
     return NULL;
   }
 
   fd = open(filename,O_RDONLY|(bin?O_BINARY:O_TEXT),0);
   if (fd<0) {
-    warn(LD_FS,"Could not open \"%s\".",filename);
+    log_warn(LD_FS,"Could not open \"%s\".",filename);
     return NULL;
   }
 
@@ -1105,8 +1106,8 @@ read_file_to_str(const char *filename, i
 
   r = read_all(fd,string,statbuf.st_size,0);
   if (r<0) {
-    warn(LD_FS,"Error reading from file \"%s\": %s", filename,
-         strerror(errno));
+    log_warn(LD_FS,"Error reading from file \"%s\": %s", filename,
+             strerror(errno));
     tor_free(string);
     close(fd);
     return NULL;
@@ -1116,17 +1117,17 @@ read_file_to_str(const char *filename, i
   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. */
-    warn(LD_FS,"Could read only %d of %ld bytes of file \"%s\".",
-           r, (long)statbuf.st_size,filename);
+    log_warn(LD_FS,"Could read only %d of %ld bytes of file \"%s\".",
+             r, (long)statbuf.st_size,filename);
     tor_free(string);
     close(fd);
     return NULL;
   }
 #ifdef MS_WINDOWS
   if (!bin && strchr(string, '\r')) {
-    debug(LD_FS, "We didn't convert CRLF to LF as well as we hoped "
-          "when reading %s. Coping.",
-          filename);
+    log_debug(LD_FS, "We didn't convert CRLF to LF as well as we hoped "
+              "when reading %s. Coping.",
+              filename);
     tor_strstrip(string, "\r");
   }
 #endif
@@ -1220,8 +1221,8 @@ expand_filename(const char *filename)
     if (filename[1] == '/' || filename[1] == '\0') {
       home = getenv("HOME");
       if (!home) {
-        warn(LD_CONFIG, "Couldn't find $HOME environment variable while "
-             "expanding %s", filename);
+        log_warn(LD_CONFIG, "Couldn't find $HOME environment variable while "
+                 "expanding %s", filename);
         return NULL;
       }
       home = tor_strdup(home);
@@ -1235,14 +1236,14 @@ expand_filename(const char *filename)
       else
         username = tor_strdup(filename+1);
       if (!(home = get_user_homedir(username))) {
-        warn(LD_CONFIG,"Couldn't get homedir for \"%s\"",username);
+        log_warn(LD_CONFIG,"Couldn't get homedir for \"%s\"",username);
         tor_free(username);
         return NULL;
       }
       tor_free(username);
       rest = slash ? (slash+1) : NULL;
 #else
-      warn(LD_CONFIG, "Couldn't expend homedir on system without pwd.h");
+      log_warn(LD_CONFIG, "Couldn't expend homedir on system without pwd.h");
       return tor_strdup(filename);
 #endif
     }
@@ -1289,7 +1290,7 @@ tor_listdir(const char *dirname)
     }
     if (!FindNextFile(handle, &findData)) {
       if (GetLastError() != ERROR_NO_MORE_FILES) {
-        warn(LD_FS, "Error reading directory.");
+        log_warn(LD_FS, "Error reading directory.");
       }
       break;
     }
@@ -1384,12 +1385,13 @@ parse_addr_port(const char *addrport, ch
     _address = tor_strndup(addrport, colon-addrport);
     _port = (int) tor_parse_long(colon+1,10,1,65535,NULL,NULL);
     if (!_port) {
-      warn(LD_GENERAL, "Port '%s' out of range", colon+1);
+      log_warn(LD_GENERAL, "Port '%s' out of range", colon+1);
       ok = 0;
     }
     if (!port_out) {
-      warn(LD_GENERAL, "Port '%s' given on '%s' when not required", colon+1,
-             addrport);
+      log_warn(LD_GENERAL,
+               "Port '%s' given on '%s' when not required",
+               colon+1, addrport);
       ok = 0;
     }
   } else {
@@ -1400,7 +1402,7 @@ parse_addr_port(const char *addrport, ch
   if (addr) {
     /* There's an addr pointer, so we need to resolve the hostname. */
     if (tor_lookup_hostname(_address,addr)) {
-      warn(LD_NET, "Couldn't look up '%s'", _address);
+      log_warn(LD_NET, "Couldn't look up '%s'", _address);
       ok = 0;
       *addr = 0;
     }
@@ -1477,8 +1479,8 @@ parse_addr_and_port_range(const char *s,
   } else if (tor_inet_aton(address, &in) != 0) {
     *addr_out = ntohl(in.s_addr);
   } else {
-    warn(LD_GENERAL, "Malformed IP \"%s\" in address pattern; rejecting.",
-         address);
+    log_warn(LD_GENERAL, "Malformed IP \"%s\" in address pattern; rejecting.",
+             address);
     goto err;
   }
 
@@ -1493,16 +1495,17 @@ parse_addr_and_port_range(const char *s,
     if (!*endptr) {
       /* strtol handled the whole mask. */
       if (bits < 0 || bits > 32) {
-        warn(LD_GENERAL,
-             "Bad number of mask bits on address range; rejecting.");
+        log_warn(LD_GENERAL,
+                 "Bad number of mask bits on address range; rejecting.");
         goto err;
       }
       *mask_out = ~((1u<<(32-bits))-1);
     } else if (tor_inet_aton(mask, &in) != 0) {
       *mask_out = ntohl(in.s_addr);
     } else {
-      warn(LD_GENERAL, "Malformed mask \"%s\" on address range; rejecting.",
-             mask);
+      log_warn(LD_GENERAL,
+               "Malformed mask \"%s\" on address range; rejecting.",
+               mask);
       goto err;
     }
   }
@@ -1520,18 +1523,20 @@ parse_addr_and_port_range(const char *s,
       *port_max_out = (uint16_t) tor_parse_long(port, 10, 1, 65535, NULL,
                                                 &endptr);
       if (*endptr || !*port_max_out) {
-        warn(LD_GENERAL, "Malformed port \"%s\" on address range rejecting.",
-             port);
+        log_warn(LD_GENERAL,
+                 "Malformed port \"%s\" on address range rejecting.",
+                 port);
       }
     } else if (*endptr || !*port_min_out) {
-      warn(LD_GENERAL, "Malformed port \"%s\" on address range; rejecting.",
-             port);
+      log_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) {
-      warn(LD_GENERAL, "Insane port range on address policy; rejecting.");
+      log_warn(LD_GENERAL, "Insane port range on address policy; rejecting.");
       goto err;
     }
   }
@@ -1607,7 +1612,7 @@ get_interface_address(uint32_t *addr)
   sock = socket(PF_INET,SOCK_DGRAM,IPPROTO_UDP);
   if (sock < 0) {
     int e = tor_socket_errno(-1);
-    warn(LD_NET, "unable to create socket: %s", tor_socket_strerror(e));
+    log_warn(LD_NET, "unable to create socket: %s", tor_socket_strerror(e));
     goto err;
   }
 
@@ -1621,14 +1626,14 @@ get_interface_address(uint32_t *addr)
 
   if (connect(sock,(struct sockaddr *)&target_addr,sizeof(target_addr))<0) {
     int e = tor_socket_errno(sock);
-    warn(LD_NET, "connnect() failed: %s", tor_socket_strerror(e));
+    log_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);
-    warn(LD_NET, "getsockname() failed: %s", tor_socket_strerror(e));
+    log_warn(LD_NET, "getsockname() failed: %s", tor_socket_strerror(e));
     goto err;
   }
 
@@ -1667,7 +1672,7 @@ start_daemon(void)
   pipe(daemon_filedes);
   pid = fork();
   if (pid < 0) {
-    err(LD_GENERAL,"fork failed. Exiting.");
+    log_err(LD_GENERAL,"fork failed. Exiting.");
     exit(1);
   }
   if (pid) {  /* Parent */
@@ -1722,14 +1727,14 @@ finish_daemon(const char *desired_cwd)
     desired_cwd = "/";
    /* Don't hold the wrong FS mounted */
   if (chdir(desired_cwd) < 0) {
-    err(LD_GENERAL,"chdir to \"%s\" failed. Exiting.",desired_cwd);
+    log_err(LD_GENERAL,"chdir to \"%s\" failed. Exiting.",desired_cwd);
     exit(1);
   }
 
   nullfd = open("/dev/null",
                 O_CREAT | O_RDWR | O_APPEND);
   if (nullfd < 0) {
-    err(LD_GENERAL,"/dev/null can't be opened. Exiting.");
+    log_err(LD_GENERAL,"/dev/null can't be opened. Exiting.");
     exit(1);
   }
   /* close fds linking to invoking terminal, but
@@ -1739,7 +1744,7 @@ finish_daemon(const char *desired_cwd)
   if (dup2(nullfd,0) < 0 ||
       dup2(nullfd,1) < 0 ||
       dup2(nullfd,2) < 0) {
-    err(LD_GENERAL,"dup2 failed. Exiting.");
+    log_err(LD_GENERAL,"dup2 failed. Exiting.");
     exit(1);
   }
   if (nullfd > 2)
@@ -1768,8 +1773,8 @@ write_pidfile(char *filename)
   FILE *pidfile;
 
   if ((pidfile = fopen(filename, "w")) == NULL) {
-    warn(LD_FS, "Unable to open \"%s\" for writing: %s", filename,
-           strerror(errno));
+    log_warn(LD_FS, "Unable to open \"%s\" for writing: %s", filename,
+             strerror(errno));
   } else {
     fprintf(pidfile, "%d\n", (int)getpid());
     fclose(pidfile);



More information about the tor-commits mailing list