mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-27 22:03:31 +01:00
wrap strdup; prefer time() to gettimeofday()
svn:r538
This commit is contained in:
parent
f563bbd2f9
commit
be874358a4
@ -40,7 +40,7 @@ static INLINE void format_msg(char *buf, size_t buf_len,
|
|||||||
|
|
||||||
buf_len -= 2; /* subtract 2 characters so we have room for \n\0 */
|
buf_len -= 2; /* subtract 2 characters so we have room for \n\0 */
|
||||||
|
|
||||||
my_gettimeofday(&now);
|
tor_gettimeofday(&now);
|
||||||
t = (time_t)now.tv_sec;
|
t = (time_t)now.tv_sec;
|
||||||
|
|
||||||
n = strftime(buf, buf_len, "%b %d %H:%M:%S", localtime(&t));
|
n = strftime(buf, buf_len, "%b %d %H:%M:%S", localtime(&t));
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Memory
|
* Memory wrappers
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void *tor_malloc(size_t size) {
|
void *tor_malloc(size_t size) {
|
||||||
@ -22,17 +22,26 @@ void *tor_malloc(size_t size) {
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
memset(result,'X',size); /* XXX deadbeef to encourage bugs */
|
memset(result,'X',size); /* XXX deadbeef to encourage bugs */
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *tor_strdup(const char *s) {
|
||||||
|
char *dup;
|
||||||
|
assert(s);
|
||||||
|
|
||||||
|
dup = strdup(s);
|
||||||
|
if(!dup) {
|
||||||
|
log_fn(LOG_ERR,"Out of memory. Dying.");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
return dup;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Time
|
* Time
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void
|
void tor_gettimeofday(struct timeval *timeval) {
|
||||||
my_gettimeofday(struct timeval *timeval)
|
|
||||||
{
|
|
||||||
#ifdef HAVE_GETTIMEOFDAY
|
#ifdef HAVE_GETTIMEOFDAY
|
||||||
if (gettimeofday(timeval, NULL)) {
|
if (gettimeofday(timeval, NULL)) {
|
||||||
log_fn(LOG_ERR, "gettimeofday failed.");
|
log_fn(LOG_ERR, "gettimeofday failed.");
|
||||||
@ -141,6 +150,10 @@ void set_socket_nonblocking(int socket)
|
|||||||
* Process control
|
* Process control
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* Minimalist interface to run a void function in the background. On
|
||||||
|
* unix calls fork, on win32 calls beginthread. Returns -1 on failure.
|
||||||
|
* func should not return, but rather should call spawn_exit.
|
||||||
|
*/
|
||||||
int spawn_func(int (*func)(void *), void *data)
|
int spawn_func(int (*func)(void *), void *data)
|
||||||
{
|
{
|
||||||
#ifdef MS_WINDOWS
|
#ifdef MS_WINDOWS
|
||||||
@ -294,6 +307,10 @@ int correct_socket_errno(int s)
|
|||||||
/*
|
/*
|
||||||
* Filesystem operations.
|
* Filesystem operations.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* Return FN_ERROR if filename can't be read, FN_NOENT if it doesn't
|
||||||
|
* exist, FN_FILE if it is a regular file, or FN_DIR if it's a
|
||||||
|
* directory. */
|
||||||
file_status_t file_status(const char *fname)
|
file_status_t file_status(const char *fname)
|
||||||
{
|
{
|
||||||
struct stat st;
|
struct stat st;
|
||||||
@ -311,6 +328,8 @@ file_status_t file_status(const char *fname)
|
|||||||
return FN_ERROR;
|
return FN_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Check whether dirname exists and is private. If yes returns
|
||||||
|
0. Else returns -1. */
|
||||||
int check_private_dir(const char *dirname, int create)
|
int check_private_dir(const char *dirname, int create)
|
||||||
{
|
{
|
||||||
struct stat st;
|
struct stat st;
|
||||||
|
@ -33,11 +33,9 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
void *tor_malloc(size_t size);
|
void *tor_malloc(size_t size);
|
||||||
|
char *tor_strdup(const char *s);
|
||||||
|
void tor_gettimeofday(struct timeval *timeval);
|
||||||
|
|
||||||
/* Same as gettimeofday, but no need to check exit value. */
|
|
||||||
void my_gettimeofday(struct timeval *timeval);
|
|
||||||
/* Returns the number of microseconds between start and end. Requires that
|
|
||||||
* end >= start, and that the number of microseconds < LONG_MAX. */
|
|
||||||
long tv_udiff(struct timeval *start, struct timeval *end);
|
long tv_udiff(struct timeval *start, struct timeval *end);
|
||||||
|
|
||||||
void tv_addms(struct timeval *a, long ms);
|
void tv_addms(struct timeval *a, long ms);
|
||||||
@ -51,22 +49,12 @@ void set_socket_nonblocking(int socket);
|
|||||||
|
|
||||||
typedef enum { FN_ERROR, FN_NOENT, FN_FILE, FN_DIR} file_status_t;
|
typedef enum { FN_ERROR, FN_NOENT, FN_FILE, FN_DIR} file_status_t;
|
||||||
|
|
||||||
/* Return FN_ERROR if filename can't be read, FN_NOENT if it doesn't
|
|
||||||
* exist, FN_FILE if it is a regular file, or FN_DIR if it's a
|
|
||||||
* directory. */
|
|
||||||
file_status_t file_status(const char *filename);
|
file_status_t file_status(const char *filename);
|
||||||
/* Check whether dirname exists and is private. If yes returns
|
|
||||||
* 0. Else returns -1.
|
|
||||||
*/
|
|
||||||
int check_private_dir(const char *dirname, int create);
|
int check_private_dir(const char *dirname, int create);
|
||||||
int write_str_to_file(const char *fname, const char *str);
|
int write_str_to_file(const char *fname, const char *str);
|
||||||
char *read_file_to_str(const char *filename);
|
char *read_file_to_str(const char *filename);
|
||||||
int parse_line_from_file(char *line, int maxlen, FILE *f, char **key_out, char **value_out);
|
int parse_line_from_file(char *line, int maxlen, FILE *f, char **key_out, char **value_out);
|
||||||
|
|
||||||
/* Minimalist interface to run a void function in the background. On
|
|
||||||
unix calls fork, on win32 calls beginthread. Returns -1 on failure.
|
|
||||||
func should not return, but rather should call spawn_exit.
|
|
||||||
*/
|
|
||||||
int spawn_func(int (*func)(void *), void *data);
|
int spawn_func(int (*func)(void *), void *data);
|
||||||
void spawn_exit();
|
void spawn_exit();
|
||||||
|
|
||||||
|
@ -58,14 +58,11 @@ void circuit_remove(circuit_t *circ) {
|
|||||||
|
|
||||||
circuit_t *circuit_new(aci_t p_aci, connection_t *p_conn) {
|
circuit_t *circuit_new(aci_t p_aci, connection_t *p_conn) {
|
||||||
circuit_t *circ;
|
circuit_t *circ;
|
||||||
struct timeval now;
|
|
||||||
|
|
||||||
my_gettimeofday(&now);
|
|
||||||
|
|
||||||
circ = (circuit_t *)tor_malloc(sizeof(circuit_t));
|
circ = (circuit_t *)tor_malloc(sizeof(circuit_t));
|
||||||
memset(circ,0,sizeof(circuit_t)); /* zero it out */
|
memset(circ,0,sizeof(circuit_t)); /* zero it out */
|
||||||
|
|
||||||
circ->timestamp_created = now.tv_sec;
|
circ->timestamp_created = time(NULL);
|
||||||
|
|
||||||
circ->p_aci = p_aci;
|
circ->p_aci = p_aci;
|
||||||
circ->p_conn = p_conn;
|
circ->p_conn = p_conn;
|
||||||
|
@ -25,11 +25,11 @@ static void command_time_process_cell(cell_t *cell, connection_t *conn,
|
|||||||
|
|
||||||
*num += 1;
|
*num += 1;
|
||||||
|
|
||||||
my_gettimeofday(&start);
|
tor_gettimeofday(&start);
|
||||||
|
|
||||||
(*func)(cell, conn);
|
(*func)(cell, conn);
|
||||||
|
|
||||||
my_gettimeofday(&end);
|
tor_gettimeofday(&end);
|
||||||
time_passed = tv_udiff(&start, &end) ;
|
time_passed = tv_udiff(&start, &end) ;
|
||||||
|
|
||||||
if (time_passed > 5000) { /* more than 5ms */
|
if (time_passed > 5000) { /* more than 5ms */
|
||||||
@ -38,17 +38,13 @@ static void command_time_process_cell(cell_t *cell, connection_t *conn,
|
|||||||
*time += time_passed;
|
*time += time_passed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void command_process_cell(cell_t *cell, connection_t *conn) {
|
void command_process_cell(cell_t *cell, connection_t *conn) {
|
||||||
static int num_create=0, num_created=0, num_relay=0, num_destroy=0;
|
static int num_create=0, num_created=0, num_relay=0, num_destroy=0;
|
||||||
static int create_time=0, created_time=0, relay_time=0, destroy_time=0;
|
static int create_time=0, created_time=0, relay_time=0, destroy_time=0;
|
||||||
static long current_second = 0; /* from previous calls to gettimeofday */
|
static time_t current_second = 0; /* from previous calls to time */
|
||||||
struct timeval now;
|
time_t now = time(NULL);
|
||||||
|
|
||||||
my_gettimeofday(&now);
|
if(now > current_second) { /* the second has rolled over */
|
||||||
|
|
||||||
if(now.tv_sec > current_second) { /* the second has rolled over */
|
|
||||||
/* print stats */
|
/* print stats */
|
||||||
log(LOG_INFO,"At end of second:");
|
log(LOG_INFO,"At end of second:");
|
||||||
log(LOG_INFO,"Create: %d (%d ms)", num_create, create_time/1000);
|
log(LOG_INFO,"Create: %d (%d ms)", num_create, create_time/1000);
|
||||||
@ -61,7 +57,7 @@ void command_process_cell(cell_t *cell, connection_t *conn) {
|
|||||||
create_time = created_time = relay_time = destroy_time = 0;
|
create_time = created_time = relay_time = destroy_time = 0;
|
||||||
|
|
||||||
/* remember which second it is, for next time */
|
/* remember which second it is, for next time */
|
||||||
current_second = now.tv_sec;
|
current_second = now;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(cell->command) {
|
switch(cell->command) {
|
||||||
|
@ -61,8 +61,8 @@ static struct config_line *config_get_commandlines(int argc, char **argv) {
|
|||||||
s = argv[i];
|
s = argv[i];
|
||||||
while(*s == '-')
|
while(*s == '-')
|
||||||
s++;
|
s++;
|
||||||
new->key = strdup(s);
|
new->key = tor_strdup(s);
|
||||||
new->value = strdup(argv[i+1]);
|
new->value = tor_strdup(argv[i+1]);
|
||||||
|
|
||||||
log(LOG_DEBUG,"Commandline: parsed keyword '%s', value '%s'",
|
log(LOG_DEBUG,"Commandline: parsed keyword '%s', value '%s'",
|
||||||
new->key, new->value);
|
new->key, new->value);
|
||||||
@ -85,8 +85,8 @@ static struct config_line *config_get_lines(FILE *f) {
|
|||||||
|
|
||||||
while( (result=parse_line_from_file(line,sizeof(line),f,&key,&value)) > 0) {
|
while( (result=parse_line_from_file(line,sizeof(line),f,&key,&value)) > 0) {
|
||||||
new = tor_malloc(sizeof(struct config_line));
|
new = tor_malloc(sizeof(struct config_line));
|
||||||
new->key = strdup(key);
|
new->key = tor_strdup(key);
|
||||||
new->value = strdup(value);
|
new->value = tor_strdup(value);
|
||||||
|
|
||||||
new->next = front;
|
new->next = front;
|
||||||
front = new;
|
front = new;
|
||||||
@ -131,7 +131,7 @@ static int config_compare(struct config_line *c, char *key, int type, void *arg)
|
|||||||
*(int *)arg = i;
|
*(int *)arg = i;
|
||||||
break;
|
break;
|
||||||
case CONFIG_TYPE_STRING:
|
case CONFIG_TYPE_STRING:
|
||||||
*(char **)arg = strdup(c->value);
|
*(char **)arg = tor_strdup(c->value);
|
||||||
break;
|
break;
|
||||||
case CONFIG_TYPE_DOUBLE:
|
case CONFIG_TYPE_DOUBLE:
|
||||||
*(double *)arg = atof(c->value);
|
*(double *)arg = atof(c->value);
|
||||||
|
@ -73,9 +73,7 @@ static int connection_init_accepted_conn(connection_t *conn);
|
|||||||
|
|
||||||
connection_t *connection_new(int type) {
|
connection_t *connection_new(int type) {
|
||||||
connection_t *conn;
|
connection_t *conn;
|
||||||
struct timeval now;
|
time_t now = time(NULL);
|
||||||
|
|
||||||
my_gettimeofday(&now);
|
|
||||||
|
|
||||||
conn = (connection_t *)tor_malloc(sizeof(connection_t));
|
conn = (connection_t *)tor_malloc(sizeof(connection_t));
|
||||||
memset(conn,0,sizeof(connection_t)); /* zero it out to start */
|
memset(conn,0,sizeof(connection_t)); /* zero it out to start */
|
||||||
@ -84,9 +82,9 @@ connection_t *connection_new(int type) {
|
|||||||
conn->inbuf = buf_new();
|
conn->inbuf = buf_new();
|
||||||
conn->outbuf = buf_new();
|
conn->outbuf = buf_new();
|
||||||
|
|
||||||
conn->timestamp_created = now.tv_sec;
|
conn->timestamp_created = now;
|
||||||
conn->timestamp_lastread = now.tv_sec;
|
conn->timestamp_lastread = now;
|
||||||
conn->timestamp_lastwritten = now.tv_sec;
|
conn->timestamp_lastwritten = now;
|
||||||
|
|
||||||
return conn;
|
return conn;
|
||||||
}
|
}
|
||||||
@ -195,7 +193,7 @@ int connection_handle_listener_read(connection_t *conn, int new_type) {
|
|||||||
newconn = connection_new(new_type);
|
newconn = connection_new(new_type);
|
||||||
newconn->s = news;
|
newconn->s = news;
|
||||||
|
|
||||||
newconn->address = strdup(inet_ntoa(remote.sin_addr)); /* remember the remote address */
|
newconn->address = tor_strdup(inet_ntoa(remote.sin_addr)); /* remember the remote address */
|
||||||
newconn->addr = ntohl(remote.sin_addr.s_addr);
|
newconn->addr = ntohl(remote.sin_addr.s_addr);
|
||||||
newconn->port = ntohs(remote.sin_port);
|
newconn->port = ntohs(remote.sin_port);
|
||||||
|
|
||||||
@ -309,10 +307,8 @@ int retry_all_connections(uint16_t or_listenport, uint16_t ap_listenport, uint16
|
|||||||
}
|
}
|
||||||
|
|
||||||
int connection_handle_read(connection_t *conn) {
|
int connection_handle_read(connection_t *conn) {
|
||||||
struct timeval now;
|
|
||||||
|
|
||||||
my_gettimeofday(&now);
|
conn->timestamp_lastread = time(NULL);
|
||||||
conn->timestamp_lastread = now.tv_sec;
|
|
||||||
|
|
||||||
switch(conn->type) {
|
switch(conn->type) {
|
||||||
case CONN_TYPE_OR_LISTENER:
|
case CONN_TYPE_OR_LISTENER:
|
||||||
@ -433,15 +429,13 @@ int connection_flush_buf(connection_t *conn) {
|
|||||||
|
|
||||||
/* return -1 if you want to break the conn, else return 0 */
|
/* return -1 if you want to break the conn, else return 0 */
|
||||||
int connection_handle_write(connection_t *conn) {
|
int connection_handle_write(connection_t *conn) {
|
||||||
struct timeval now;
|
|
||||||
|
|
||||||
if(connection_is_listener(conn)) {
|
if(connection_is_listener(conn)) {
|
||||||
log_fn(LOG_WARNING,"Got a listener socket. Can't happen!");
|
log_fn(LOG_WARNING,"Got a listener socket. Can't happen!");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
my_gettimeofday(&now);
|
conn->timestamp_lastwritten = time(NULL);
|
||||||
conn->timestamp_lastwritten = now.tv_sec;
|
|
||||||
|
|
||||||
if(connection_speaks_cells(conn) && conn->state != OR_CONN_STATE_CONNECTING) {
|
if(connection_speaks_cells(conn) && conn->state != OR_CONN_STATE_CONNECTING) {
|
||||||
if(conn->state == OR_CONN_STATE_HANDSHAKING) {
|
if(conn->state == OR_CONN_STATE_HANDSHAKING) {
|
||||||
|
@ -577,7 +577,7 @@ static int connection_ap_handshake_socks_reply(connection_t *conn, char *reply,
|
|||||||
n_stream = connection_new(CONN_TYPE_EXIT);
|
n_stream = connection_new(CONN_TYPE_EXIT);
|
||||||
|
|
||||||
memcpy(n_stream->stream_id, cell->payload + RELAY_HEADER_SIZE, STREAM_ID_SIZE);
|
memcpy(n_stream->stream_id, cell->payload + RELAY_HEADER_SIZE, STREAM_ID_SIZE);
|
||||||
n_stream->address = strdup(cell->payload + RELAY_HEADER_SIZE + STREAM_ID_SIZE);
|
n_stream->address = tor_strdup(cell->payload + RELAY_HEADER_SIZE + STREAM_ID_SIZE);
|
||||||
n_stream->port = atoi(colon+1);
|
n_stream->port = atoi(colon+1);
|
||||||
n_stream->state = EXIT_CONN_STATE_RESOLVING;
|
n_stream->state = EXIT_CONN_STATE_RESOLVING;
|
||||||
n_stream->s = -1; /* not yet valid */
|
n_stream->s = -1; /* not yet valid */
|
||||||
|
@ -83,10 +83,10 @@ void connection_or_init_conn_from_router(connection_t *conn, routerinfo_t *route
|
|||||||
conn->onion_pkey = crypto_pk_dup_key(router->onion_pkey);
|
conn->onion_pkey = crypto_pk_dup_key(router->onion_pkey);
|
||||||
conn->link_pkey = crypto_pk_dup_key(router->link_pkey);
|
conn->link_pkey = crypto_pk_dup_key(router->link_pkey);
|
||||||
conn->identity_pkey = crypto_pk_dup_key(router->identity_pkey);
|
conn->identity_pkey = crypto_pk_dup_key(router->identity_pkey);
|
||||||
conn->nickname = strdup(router->nickname);
|
conn->nickname = tor_strdup(router->nickname);
|
||||||
if(conn->address)
|
if(conn->address)
|
||||||
free(conn->address);
|
free(conn->address);
|
||||||
conn->address = strdup(router->address);
|
conn->address = tor_strdup(router->address);
|
||||||
}
|
}
|
||||||
|
|
||||||
connection_t *connection_or_connect(routerinfo_t *router) {
|
connection_t *connection_or_connect(routerinfo_t *router) {
|
||||||
|
@ -184,7 +184,7 @@ static int spawn_cpuworker(void) {
|
|||||||
|
|
||||||
/* set up conn so it's got all the data we need to remember */
|
/* set up conn so it's got all the data we need to remember */
|
||||||
conn->s = fd[0];
|
conn->s = fd[0];
|
||||||
conn->address = strdup("localhost");
|
conn->address = tor_strdup("localhost");
|
||||||
|
|
||||||
if(connection_add(conn) < 0) { /* no space, forget it */
|
if(connection_add(conn) < 0) { /* no space, forget it */
|
||||||
log_fn(LOG_WARNING,"connection_add failed. Giving up.");
|
log_fn(LOG_WARNING,"connection_add failed. Giving up.");
|
||||||
|
@ -45,8 +45,8 @@ void directory_initiate_command(routerinfo_t *router, int command) {
|
|||||||
/* set up conn so it's got all the data we need to remember */
|
/* set up conn so it's got all the data we need to remember */
|
||||||
conn->addr = router->addr;
|
conn->addr = router->addr;
|
||||||
conn->port = router->dir_port;
|
conn->port = router->dir_port;
|
||||||
conn->address = strdup(router->address);
|
conn->address = tor_strdup(router->address);
|
||||||
conn->nickname = strdup(router->nickname);
|
conn->nickname = tor_strdup(router->nickname);
|
||||||
if (router->identity_pkey)
|
if (router->identity_pkey)
|
||||||
conn->identity_pkey = crypto_pk_dup_key(router->identity_pkey);
|
conn->identity_pkey = crypto_pk_dup_key(router->identity_pkey);
|
||||||
else {
|
else {
|
||||||
|
@ -29,12 +29,12 @@ add_fingerprint_to_dir(const char *nickname, const char *fp)
|
|||||||
for (i = 0; i < n_fingerprints; ++i) {
|
for (i = 0; i < n_fingerprints; ++i) {
|
||||||
if (!strcasecmp(fingerprint_list[i].nickname,nickname)) {
|
if (!strcasecmp(fingerprint_list[i].nickname,nickname)) {
|
||||||
free(fingerprint_list[i].fingerprint);
|
free(fingerprint_list[i].fingerprint);
|
||||||
fingerprint_list[i].fingerprint = strdup(fp);
|
fingerprint_list[i].fingerprint = tor_strdup(fp);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fingerprint_list[n_fingerprints].nickname = strdup(nickname);
|
fingerprint_list[n_fingerprints].nickname = tor_strdup(nickname);
|
||||||
fingerprint_list[n_fingerprints].fingerprint = strdup(fp);
|
fingerprint_list[n_fingerprints].fingerprint = tor_strdup(fp);
|
||||||
++n_fingerprints;
|
++n_fingerprints;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,8 +83,8 @@ dirserv_parse_fingerprint_file(const char *fname)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(i == n_fingerprints_tmp) { /* not a duplicate */
|
if(i == n_fingerprints_tmp) { /* not a duplicate */
|
||||||
fingerprint_list_tmp[n_fingerprints_tmp].nickname = strdup(nickname);
|
fingerprint_list_tmp[n_fingerprints_tmp].nickname = tor_strdup(nickname);
|
||||||
fingerprint_list_tmp[n_fingerprints_tmp].fingerprint = strdup(fingerprint);
|
fingerprint_list_tmp[n_fingerprints_tmp].fingerprint = tor_strdup(fingerprint);
|
||||||
++n_fingerprints_tmp;
|
++n_fingerprints_tmp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -427,7 +427,7 @@ size_t dirserv_get_directory(const char **directory)
|
|||||||
/* Now read the directory we just made in order to update our own
|
/* Now read the directory we just made in order to update our own
|
||||||
* router lists. This does more signature checking than is strictly
|
* router lists. This does more signature checking than is strictly
|
||||||
* necessary, but safe is better than sorry. */
|
* necessary, but safe is better than sorry. */
|
||||||
new_directory = strdup(the_directory);
|
new_directory = tor_strdup(the_directory);
|
||||||
/* use a new copy of the dir, since get_dir_from_string scribbles on it */
|
/* use a new copy of the dir, since get_dir_from_string scribbles on it */
|
||||||
if (router_get_dir_from_string(new_directory, get_identity_key())) {
|
if (router_get_dir_from_string(new_directory, get_identity_key())) {
|
||||||
log_fn(LOG_ERR, "We just generated a directory we can't parse. Dying.");
|
log_fn(LOG_ERR, "We just generated a directory we can't parse. Dying.");
|
||||||
|
@ -165,7 +165,7 @@ static int assign_to_dnsworker(connection_t *exitconn) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
dnsconn->address = strdup(exitconn->address);
|
dnsconn->address = tor_strdup(exitconn->address);
|
||||||
dnsconn->state = DNSWORKER_STATE_BUSY;
|
dnsconn->state = DNSWORKER_STATE_BUSY;
|
||||||
num_dnsworkers_busy++;
|
num_dnsworkers_busy++;
|
||||||
|
|
||||||
@ -381,7 +381,7 @@ static int spawn_dnsworker(void) {
|
|||||||
|
|
||||||
/* set up conn so it's got all the data we need to remember */
|
/* set up conn so it's got all the data we need to remember */
|
||||||
conn->s = fd[0];
|
conn->s = fd[0];
|
||||||
conn->address = strdup("localhost");
|
conn->address = tor_strdup("localhost");
|
||||||
|
|
||||||
if(connection_add(conn) < 0) { /* no space, forget it */
|
if(connection_add(conn) < 0) { /* no space, forget it */
|
||||||
log_fn(LOG_WARNING,"connection_add failed. Giving up.");
|
log_fn(LOG_WARNING,"connection_add failed. Giving up.");
|
||||||
|
@ -270,7 +270,7 @@ static int prepare_for_poll(void) {
|
|||||||
cell_t cell;
|
cell_t cell;
|
||||||
circuit_t *circ;
|
circuit_t *circ;
|
||||||
|
|
||||||
my_gettimeofday(&now);
|
tor_gettimeofday(&now);
|
||||||
|
|
||||||
if(now.tv_sec > current_second) { /* the second has rolled over. check more stuff. */
|
if(now.tv_sec > current_second) { /* the second has rolled over. check more stuff. */
|
||||||
|
|
||||||
@ -656,23 +656,22 @@ static void catch(int the_signal) {
|
|||||||
static void dumpstats(void) { /* dump stats to stdout */
|
static void dumpstats(void) { /* dump stats to stdout */
|
||||||
int i;
|
int i;
|
||||||
connection_t *conn;
|
connection_t *conn;
|
||||||
struct timeval now;
|
time_t now = time(NULL);
|
||||||
|
|
||||||
printf("Dumping stats:\n");
|
printf("Dumping stats:\n");
|
||||||
my_gettimeofday(&now);
|
|
||||||
|
|
||||||
for(i=0;i<nfds;i++) {
|
for(i=0;i<nfds;i++) {
|
||||||
conn = connection_array[i];
|
conn = connection_array[i];
|
||||||
printf("Conn %d (socket %d) type %d (%s), state %d (%s), created %ld secs ago\n",
|
printf("Conn %d (socket %d) type %d (%s), state %d (%s), created %ld secs ago\n",
|
||||||
i, conn->s, conn->type, conn_type_to_string[conn->type],
|
i, conn->s, conn->type, conn_type_to_string[conn->type],
|
||||||
conn->state, conn_state_to_string[conn->type][conn->state], now.tv_sec - conn->timestamp_created);
|
conn->state, conn_state_to_string[conn->type][conn->state], now - conn->timestamp_created);
|
||||||
if(!connection_is_listener(conn)) {
|
if(!connection_is_listener(conn)) {
|
||||||
printf("Conn %d is to '%s:%d'.\n",i,conn->address, conn->port);
|
printf("Conn %d is to '%s:%d'.\n",i,conn->address, conn->port);
|
||||||
printf("Conn %d: %d bytes waiting on inbuf (last read %ld secs ago)\n",i,
|
printf("Conn %d: %d bytes waiting on inbuf (last read %ld secs ago)\n",i,
|
||||||
(int)buf_datalen(conn->inbuf),
|
(int)buf_datalen(conn->inbuf),
|
||||||
now.tv_sec - conn->timestamp_lastread);
|
now - conn->timestamp_lastread);
|
||||||
printf("Conn %d: %d bytes waiting on outbuf (last written %ld secs ago)\n",i,(int)buf_datalen(conn->outbuf),
|
printf("Conn %d: %d bytes waiting on outbuf (last written %ld secs ago)\n",i,
|
||||||
now.tv_sec - conn->timestamp_lastwritten);
|
(int)buf_datalen(conn->outbuf), now - conn->timestamp_lastwritten);
|
||||||
}
|
}
|
||||||
circuit_dump_by_conn(conn); /* dump info about all the circuits using this conn */
|
circuit_dump_by_conn(conn); /* dump info about all the circuits using this conn */
|
||||||
printf("\n");
|
printf("\n");
|
||||||
@ -703,7 +702,6 @@ static void dumpstats(void) { /* dump stats to stdout */
|
|||||||
if (stats_n_seconds_reading)
|
if (stats_n_seconds_reading)
|
||||||
printf("Average bandwidth used: %d bytes/sec\n",
|
printf("Average bandwidth used: %d bytes/sec\n",
|
||||||
(int) (stats_n_bytes_read/stats_n_seconds_reading));
|
(int) (stats_n_bytes_read/stats_n_seconds_reading));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void daemonize(void) {
|
void daemonize(void) {
|
||||||
|
@ -606,7 +606,7 @@ int router_get_dir_from_string_impl(char *s, directory_t **dest,
|
|||||||
log_fn(LOG_WARNING, "Invalid recommended-software line");
|
log_fn(LOG_WARNING, "Invalid recommended-software line");
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
versions = strdup(tok.val.cmd.args[0]);
|
versions = tor_strdup(tok.val.cmd.args[0]);
|
||||||
|
|
||||||
NEXT_TOK();
|
NEXT_TOK();
|
||||||
TOK_IS(K_RUNNING_ROUTERS, "running-routers");
|
TOK_IS(K_RUNNING_ROUTERS, "running-routers");
|
||||||
@ -801,8 +801,7 @@ routerinfo_t *router_get_entry_from_string(char**s) {
|
|||||||
log_fn(LOG_WARNING,"Wrong # of arguments to \"router\"");
|
log_fn(LOG_WARNING,"Wrong # of arguments to \"router\"");
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
if (!(router->nickname = strdup(ARGS[0])))
|
router->nickname = tor_strdup(ARGS[0]);
|
||||||
goto err;
|
|
||||||
if (strlen(router->nickname) > MAX_NICKNAME_LEN) {
|
if (strlen(router->nickname) > MAX_NICKNAME_LEN) {
|
||||||
log_fn(LOG_WARNING,"Router nickname too long.");
|
log_fn(LOG_WARNING,"Router nickname too long.");
|
||||||
goto err;
|
goto err;
|
||||||
@ -814,8 +813,7 @@ routerinfo_t *router_get_entry_from_string(char**s) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* read router.address */
|
/* read router.address */
|
||||||
if (!(router->address = strdup(ARGS[1])))
|
router->address = tor_strdup(ARGS[1]);
|
||||||
goto err;
|
|
||||||
router->addr = 0;
|
router->addr = 0;
|
||||||
|
|
||||||
/* Read router->or_port */
|
/* Read router->or_port */
|
||||||
@ -975,8 +973,8 @@ static int router_add_exit_policy(routerinfo_t *router,
|
|||||||
if(!colon)
|
if(!colon)
|
||||||
goto policy_read_failed;
|
goto policy_read_failed;
|
||||||
*colon = 0;
|
*colon = 0;
|
||||||
newe->address = strdup(arg);
|
newe->address = tor_strdup(arg);
|
||||||
newe->port = strdup(colon+1);
|
newe->port = tor_strdup(colon+1);
|
||||||
|
|
||||||
log_fn(LOG_DEBUG,"%s %s:%s",
|
log_fn(LOG_DEBUG,"%s %s:%s",
|
||||||
newe->policy_type == EXIT_POLICY_REJECT ? "reject" : "accept",
|
newe->policy_type == EXIT_POLICY_REJECT ? "reject" : "accept",
|
||||||
@ -1064,8 +1062,8 @@ int router_rebuild_descriptor(void) {
|
|||||||
address = localhostname;
|
address = localhostname;
|
||||||
}
|
}
|
||||||
ri = tor_malloc(sizeof(routerinfo_t));
|
ri = tor_malloc(sizeof(routerinfo_t));
|
||||||
ri->address = strdup(address);
|
ri->address = tor_strdup(address);
|
||||||
ri->nickname = strdup(options.Nickname);
|
ri->nickname = tor_strdup(options.Nickname);
|
||||||
/* No need to set addr. */
|
/* No need to set addr. */
|
||||||
ri->or_port = options.ORPort;
|
ri->or_port = options.ORPort;
|
||||||
ri->ap_port = options.APPort;
|
ri->ap_port = options.APPort;
|
||||||
@ -1205,7 +1203,7 @@ int router_dump_router_to_string(char *s, int maxlen, routerinfo_t *router,
|
|||||||
s[written+1] = 0;
|
s[written+1] = 0;
|
||||||
|
|
||||||
#ifdef DEBUG_ROUTER_DUMP_ROUTER_TO_STRING
|
#ifdef DEBUG_ROUTER_DUMP_ROUTER_TO_STRING
|
||||||
s_tmp = s_dup = strdup(s);
|
s_tmp = s_dup = tor_strdup(s);
|
||||||
ri_tmp = router_get_entry_from_string(&s_tmp);
|
ri_tmp = router_get_entry_from_string(&s_tmp);
|
||||||
if (!ri_tmp) {
|
if (!ri_tmp) {
|
||||||
log_fn(LOG_ERR, "We just generated a router descriptor we can't parse: <<%s>>",
|
log_fn(LOG_ERR, "We just generated a router descriptor we can't parse: <<%s>>",
|
||||||
|
Loading…
Reference in New Issue
Block a user