clean up this TOR_FRAGILE business

svn:r4116
This commit is contained in:
Roger Dingledine 2005-04-26 18:52:16 +00:00
parent 5e86e87124
commit 509405a5f7
10 changed files with 28 additions and 69 deletions

View File

@ -23,7 +23,7 @@
#include <time.h> #include <time.h>
#endif #endif
/** Replace assert() with a variant that sends failures to the log before /* Replace assert() with a variant that sends failures to the log before
* calling assert() normally. * calling assert() normally.
*/ */
#ifdef NDEBUG #ifdef NDEBUG
@ -47,6 +47,11 @@
} } while (0) } } while (0)
#endif #endif
/** Define this if you want Tor to crash when any problem comes up,
* so you can get a coredump and track things down. */
// #define tor_fragile_assert() tor_assert(0)
#define tor_fragile_assert()
/* Memory management */ /* Memory management */
void *_tor_malloc(const char *file, const int line, size_t size); void *_tor_malloc(const char *file, const int line, size_t size);
void *_tor_malloc_zero(const char *file, const int line, size_t size); void *_tor_malloc_zero(const char *file, const int line, size_t size);

View File

@ -820,9 +820,7 @@ static int new_route_len(double cw, uint8_t purpose, smartlist_t *routers) {
routelen = 4; routelen = 4;
else { else {
log_fn(LOG_WARN,"Bug: unhandled purpose %d", purpose); log_fn(LOG_WARN,"Bug: unhandled purpose %d", purpose);
#ifdef TOR_FRAGILE tor_fragile_assert();
tor_assert(0);
#endif
return -1; return -1;
} }
#endif #endif
@ -1138,9 +1136,7 @@ choose_good_exit_server(uint8_t purpose, routerlist_t *dir,
return r; return r;
} }
log_fn(LOG_WARN,"Bug: unhandled purpose %d", purpose); log_fn(LOG_WARN,"Bug: unhandled purpose %d", purpose);
#ifdef TOR_FRAGILE tor_fragile_assert();
tor_assert(0);
#endif
return NULL; return NULL;
} }

View File

@ -731,9 +731,7 @@ circuit_launch_by_router(uint8_t purpose, routerinfo_t *exit,
default: default:
log_fn(LOG_WARN,"Bug: unexpected purpose %d when cannibalizing a general circ.", log_fn(LOG_WARN,"Bug: unexpected purpose %d when cannibalizing a general circ.",
purpose); purpose);
#ifdef TOR_FRAGILE tor_fragile_assert();
tor_assert(0);
#endif
return NULL; return NULL;
} }
return circ; return circ;

View File

@ -270,9 +270,7 @@ void connection_about_to_close_connection(connection_t *conn)
if (CONN_IS_EDGE(conn)) { if (CONN_IS_EDGE(conn)) {
if (!conn->has_sent_end) { if (!conn->has_sent_end) {
log_fn(LOG_WARN,"Harmless bug: Edge connection (marked at %s:%d) hasn't sent end yet?", conn->marked_for_close_file, conn->marked_for_close); log_fn(LOG_WARN,"Harmless bug: Edge connection (marked at %s:%d) hasn't sent end yet?", conn->marked_for_close_file, conn->marked_for_close);
#ifdef TOR_FRAGILE tor_fragile_assert();
tor_assert(0);
#endif
} }
} }
@ -345,9 +343,7 @@ void connection_close_immediate(connection_t *conn)
assert_connection_ok(conn,0); assert_connection_ok(conn,0);
if (conn->s < 0) { if (conn->s < 0) {
log_fn(LOG_WARN,"Bug: Attempt to close already-closed connection."); log_fn(LOG_WARN,"Bug: Attempt to close already-closed connection.");
#ifdef TOR_FRAGILE tor_fragile_assert();
tor_assert(0);
#endif
return; return;
} }
if (conn->outbuf_flushlen) { if (conn->outbuf_flushlen) {
@ -380,9 +376,7 @@ _connection_mark_for_close(connection_t *conn, int line, const char *file)
log(LOG_WARN, "Duplicate call to connection_mark_for_close at %s:%d" log(LOG_WARN, "Duplicate call to connection_mark_for_close at %s:%d"
" (first at %s:%d)", file, line, conn->marked_for_close_file, " (first at %s:%d)", file, line, conn->marked_for_close_file,
conn->marked_for_close); conn->marked_for_close);
#ifdef TOR_FRAGILE tor_fragile_assert();
tor_assert(0);
#endif
return; return;
} }
@ -1572,9 +1566,7 @@ static int connection_process_inbuf(connection_t *conn, int package_partial) {
return connection_control_process_inbuf(conn); return connection_control_process_inbuf(conn);
default: default:
log_fn(LOG_WARN,"Bug: got unexpected conn type %d.", conn->type); log_fn(LOG_WARN,"Bug: got unexpected conn type %d.", conn->type);
#ifdef TOR_FRAGILE tor_fragile_assert();
tor_assert(0);
#endif
return -1; return -1;
} }
} }
@ -1607,9 +1599,7 @@ static int connection_finished_flushing(connection_t *conn) {
return connection_control_finished_flushing(conn); return connection_control_finished_flushing(conn);
default: default:
log_fn(LOG_WARN,"Bug: got unexpected conn type %d.", conn->type); log_fn(LOG_WARN,"Bug: got unexpected conn type %d.", conn->type);
#ifdef TOR_FRAGILE tor_fragile_assert();
tor_assert(0);
#endif
return -1; return -1;
} }
} }
@ -1633,9 +1623,7 @@ static int connection_finished_connecting(connection_t *conn)
return connection_dir_finished_connecting(conn); return connection_dir_finished_connecting(conn);
default: default:
log_fn(LOG_WARN,"Bug: got unexpected conn type %d.", conn->type); log_fn(LOG_WARN,"Bug: got unexpected conn type %d.", conn->type);
#ifdef TOR_FRAGILE tor_fragile_assert();
tor_assert(0);
#endif
return -1; return -1;
} }
} }
@ -1658,9 +1646,7 @@ static int connection_reached_eof(connection_t *conn)
return connection_control_reached_eof(conn); return connection_control_reached_eof(conn);
default: default:
log_fn(LOG_WARN,"Bug: got unexpected conn type %d.", conn->type); log_fn(LOG_WARN,"Bug: got unexpected conn type %d.", conn->type);
#ifdef TOR_FRAGILE tor_fragile_assert();
tor_assert(0);
#endif
return -1; return -1;
} }
} }

View File

@ -129,9 +129,7 @@ int connection_edge_process_inbuf(connection_t *conn, int package_partial) {
return 0; return 0;
} }
log_fn(LOG_WARN,"Bug: Got unexpected state %d. Closing.",conn->state); log_fn(LOG_WARN,"Bug: Got unexpected state %d. Closing.",conn->state);
#ifdef TOR_FRAGILE tor_fragile_assert();
tor_assert(0);
#endif
connection_edge_end(conn, END_STREAM_REASON_INTERNAL, conn->cpath_layer); connection_edge_end(conn, END_STREAM_REASON_INTERNAL, conn->cpath_layer);
connection_mark_for_close(conn); connection_mark_for_close(conn);
return -1; return -1;
@ -176,9 +174,7 @@ connection_edge_end(connection_t *conn, char reason, crypt_path_t *cpath_layer)
if (conn->has_sent_end) { if (conn->has_sent_end) {
log_fn(LOG_WARN,"Harmless bug: Calling connection_edge_end (reason %d) on an already ended stream?", reason); log_fn(LOG_WARN,"Harmless bug: Calling connection_edge_end (reason %d) on an already ended stream?", reason);
#ifdef TOR_FRAGILE tor_fragile_assert();
tor_assert(0);
#endif
return -1; return -1;
} }
@ -251,9 +247,7 @@ int connection_edge_finished_flushing(connection_t *conn) {
return 0; return 0;
default: default:
log_fn(LOG_WARN,"BUG: called in unexpected state %d.", conn->state); log_fn(LOG_WARN,"BUG: called in unexpected state %d.", conn->state);
#ifdef TOR_FRAGILE tor_fragile_assert();
tor_assert(0);
#endif
return -1; return -1;
} }
return 0; return 0;

View File

@ -148,9 +148,7 @@ int connection_or_finished_flushing(connection_t *conn) {
break; break;
default: default:
log_fn(LOG_WARN,"BUG: called in unexpected state %d.", conn->state); log_fn(LOG_WARN,"BUG: called in unexpected state %d.", conn->state);
#ifdef TOR_FRAGILE tor_fragile_assert();
tor_assert(0);
#endif
return -1; return -1;
} }
return 0; return 0;

View File

@ -1126,9 +1126,7 @@ int connection_dir_finished_flushing(connection_t *conn) {
return 0; return 0;
default: default:
log_fn(LOG_WARN,"Bug: called in unexpected state %d.", conn->state); log_fn(LOG_WARN,"Bug: called in unexpected state %d.", conn->state);
#ifdef TOR_FRAGILE tor_fragile_assert();
tor_assert(0);
#endif
return -1; return -1;
} }
return 0; return 0;

View File

@ -139,15 +139,11 @@ static void purge_expired_resolves(uint32_t now) {
log(LOG_DEBUG,"Forgetting old cached resolve (expires %lu)", (unsigned long)resolve->expire); log(LOG_DEBUG,"Forgetting old cached resolve (expires %lu)", (unsigned long)resolve->expire);
if (resolve->state == CACHE_STATE_PENDING) { if (resolve->state == CACHE_STATE_PENDING) {
log_fn(LOG_WARN,"Bug: Expiring a dns resolve that's still pending. Forgot to cull it?"); log_fn(LOG_WARN,"Bug: Expiring a dns resolve that's still pending. Forgot to cull it?");
#ifdef TOR_FRAGILE tor_fragile_assert();
tor_assert(0);
#endif
} }
if (resolve->pending_connections) { if (resolve->pending_connections) {
log_fn(LOG_WARN, "Closing pending connections on expiring DNS resolve!"); log_fn(LOG_WARN, "Closing pending connections on expiring DNS resolve!");
#ifdef TOR_FRAGILE tor_fragile_assert();
tor_assert(0);
#endif
while (resolve->pending_connections) { while (resolve->pending_connections) {
pend = resolve->pending_connections; pend = resolve->pending_connections;
resolve->pending_connections = pend->next; resolve->pending_connections = pend->next;
@ -439,9 +435,7 @@ void dns_cancel_pending_resolve(char *address) {
if (!resolve->pending_connections) { if (!resolve->pending_connections) {
/* XXX this should never trigger, but sometimes it does */ /* XXX this should never trigger, but sometimes it does */
log_fn(LOG_WARN,"Bug: Address '%s' is pending but has no pending connections!", address); log_fn(LOG_WARN,"Bug: Address '%s' is pending but has no pending connections!", address);
#ifdef TOR_FRAGILE tor_fragile_assert();
tor_assert(0);
#endif
return; return;
} }
tor_assert(resolve->pending_connections); tor_assert(resolve->pending_connections);
@ -637,10 +631,8 @@ int connection_dns_process_inbuf(connection_t *conn) {
tor_assert(conn->type == CONN_TYPE_DNSWORKER); tor_assert(conn->type == CONN_TYPE_DNSWORKER);
if (conn->state != DNSWORKER_STATE_BUSY && buf_datalen(conn->inbuf)) { if (conn->state != DNSWORKER_STATE_BUSY && buf_datalen(conn->inbuf)) {
log_fn(LOG_WARN,"Bug: read data (%d bytes) from an idle dns worker. Please report.", (int)buf_datalen(conn->inbuf)); log_fn(LOG_WARN,"Bug: read data (%d bytes) from an idle dns worker (address '%s'. Please report.", (int)buf_datalen(conn->inbuf), conn->address);
#ifdef TOR_FRAGILE tor_fragile_assert();
tor_assert(0);
#endif
return 0; return 0;
} }
if (buf_datalen(conn->inbuf) < 5) /* entire answer available? */ if (buf_datalen(conn->inbuf) < 5) /* entire answer available? */

View File

@ -356,9 +356,7 @@ conn_read_callback(int fd, short event, void *_conn)
#ifndef MS_WINDOWS #ifndef MS_WINDOWS
log_fn(LOG_WARN,"Bug: unhandled error on read for %s connection (fd %d); removing", log_fn(LOG_WARN,"Bug: unhandled error on read for %s connection (fd %d); removing",
conn_type_to_string(conn->type), conn->s); conn_type_to_string(conn->type), conn->s);
#ifdef TOR_FRAGILE tor_fragile_assert();
tor_assert(0);
#endif
#endif #endif
if (CONN_IS_EDGE(conn)) if (CONN_IS_EDGE(conn))
connection_edge_end_errno(conn, conn->cpath_layer); connection_edge_end_errno(conn, conn->cpath_layer);
@ -388,9 +386,7 @@ static void conn_write_callback(int fd, short events, void *_conn)
/* this connection is broken. remove it. */ /* this connection is broken. remove it. */
log_fn(LOG_WARN,"Bug: unhandled error on write for %s connection (fd %d); removing", log_fn(LOG_WARN,"Bug: unhandled error on write for %s connection (fd %d); removing",
conn_type_to_string(conn->type), conn->s); conn_type_to_string(conn->type), conn->s);
#ifdef TOR_FRAGILE tor_fragile_assert();
tor_assert(0);
#endif
conn->has_sent_end = 1; /* otherwise we cry wolf about duplicate close */ conn->has_sent_end = 1; /* otherwise we cry wolf about duplicate close */
/* XXX do we need a close-immediate here, so we don't try to flush? */ /* XXX do we need a close-immediate here, so we don't try to flush? */
connection_mark_for_close(conn); connection_mark_for_close(conn);

View File

@ -146,10 +146,6 @@
#define cell_t tor_cell_t #define cell_t tor_cell_t
#endif #endif
/** Define this if you want Tor to crash when any problem comes up,
* so you can get a coredump and track things down. */
#undef TOR_FRAGILE
#define DEFAULT_BANDWIDTH_OP (1024 * 1000) #define DEFAULT_BANDWIDTH_OP (1024 * 1000)
#define MAX_NICKNAME_LEN 19 #define MAX_NICKNAME_LEN 19
/* Hex digest plus dollar sign. */ /* Hex digest plus dollar sign. */