[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] Stop using stdout for non-debugging cases
Update of /home/or/cvsroot/src/or
In directory moria.mit.edu:/tmp/cvs-serv5280/or
Modified Files:
circuit.c connection.c cpuworker.c dns.c main.c
Log Message:
Stop using stdout for non-debugging cases
Index: circuit.c
===================================================================
RCS file: /home/or/cvsroot/src/or/circuit.c,v
retrieving revision 1.78
retrieving revision 1.79
diff -u -d -r1.78 -r1.79
--- circuit.c 10 Oct 2003 01:48:31 -0000 1.78
+++ circuit.c 15 Oct 2003 18:28:32 -0000 1.79
@@ -559,26 +559,26 @@
}
/* FIXME this now leaves some out */
-void circuit_dump_by_conn(connection_t *conn) {
+void circuit_dump_by_conn(connection_t *conn, int severity) {
circuit_t *circ;
connection_t *tmpconn;
for(circ=global_circuitlist;circ;circ = circ->next) {
if(circ->p_conn == conn)
- printf("Conn %d has App-ward circuit: aci %d (other side %d), state %d (%s)\n",
+ log(severity, "Conn %d has App-ward circuit: aci %d (other side %d), state %d (%s)",
conn->poll_index, circ->p_aci, circ->n_aci, circ->state, circuit_state_to_string[circ->state]);
for(tmpconn=circ->p_streams; tmpconn; tmpconn=tmpconn->next_stream) {
if(tmpconn == conn) {
- printf("Conn %d has App-ward circuit: aci %d (other side %d), state %d (%s)\n",
+ log(severity,"Conn %d has App-ward circuit: aci %d (other side %d), state %d (%s)",
conn->poll_index, circ->p_aci, circ->n_aci, circ->state, circuit_state_to_string[circ->state]);
}
}
if(circ->n_conn == conn)
- printf("Conn %d has Exit-ward circuit: aci %d (other side %d), state %d (%s)\n",
+ log(severity,"Conn %d has Exit-ward circuit: aci %d (other side %d), state %d (%s)",
conn->poll_index, circ->n_aci, circ->p_aci, circ->state, circuit_state_to_string[circ->state]);
for(tmpconn=circ->n_streams; tmpconn; tmpconn=tmpconn->next_stream) {
if(tmpconn == conn) {
- printf("Conn %d has Exit-ward circuit: aci %d (other side %d), state %d (%s)\n",
+ log(severity,"Conn %d has Exit-ward circuit: aci %d (other side %d), state %d (%s)",
conn->poll_index, circ->n_aci, circ->p_aci, circ->state, circuit_state_to_string[circ->state]);
}
}
Index: connection.c
===================================================================
RCS file: /home/or/cvsroot/src/or/connection.c,v
retrieving revision 1.120
retrieving revision 1.121
diff -u -d -r1.120 -r1.121
--- connection.c 14 Oct 2003 03:06:48 -0000 1.120
+++ connection.c 15 Oct 2003 18:28:32 -0000 1.121
@@ -138,13 +138,14 @@
setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (void*)&one, sizeof(one));
if(bind(s,(struct sockaddr *)bindaddr,sizeof(*bindaddr)) < 0) {
- perror("bind ");
- log(LOG_WARN,"Could not bind to port %u.",ntohs(bindaddr->sin_port));
+ log(LOG_WARN,"Could not bind to port %u: %s",ntohs(bindaddr->sin_port),
+ strerror(errno));
return -1;
}
if(listen(s,SOMAXCONN) < 0) {
- log(LOG_WARN,"Could not listen on port %u.",ntohs(bindaddr->sin_port));
+ log(LOG_WARN,"Could not listen on port %u: %s",ntohs(bindaddr->sin_port),
+ strerror(errno));
return -1;
}
Index: cpuworker.c
===================================================================
RCS file: /home/or/cvsroot/src/or/cpuworker.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- cpuworker.c 10 Oct 2003 01:48:32 -0000 1.12
+++ cpuworker.c 15 Oct 2003 18:28:32 -0000 1.13
@@ -170,7 +170,7 @@
connection_t *conn;
if(tor_socketpair(AF_UNIX, SOCK_STREAM, 0, fd) < 0) {
- perror("socketpair");
+ log(LOG_ERR, "Couldn't construct socketpair: %s", strerror(errno));
exit(1);
}
Index: dns.c
===================================================================
RCS file: /home/or/cvsroot/src/or/dns.c,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -d -r1.32 -r1.33
--- dns.c 10 Oct 2003 01:48:32 -0000 1.32
+++ dns.c 15 Oct 2003 18:28:32 -0000 1.33
@@ -367,7 +367,7 @@
connection_t *conn;
if(tor_socketpair(AF_UNIX, SOCK_STREAM, 0, fd) < 0) {
- perror("socketpair");
+ log(LOG_ERR, "Couldn't construct socketpair: %s", strerror(errno));
exit(1);
}
Index: main.c
===================================================================
RCS file: /home/or/cvsroot/src/or/main.c,v
retrieving revision 1.130
retrieving revision 1.131
diff -u -d -r1.130 -r1.131
--- main.c 10 Oct 2003 01:48:32 -0000 1.130
+++ main.c 15 Oct 2003 18:28:32 -0000 1.131
@@ -6,7 +6,7 @@
/********* START PROTOTYPES **********/
-static void dumpstats(void); /* dump stats to stdout */
+static void dumpstats(int severity); /* log stats */
/********* START VARIABLES **********/
@@ -601,7 +601,7 @@
for(;;) {
#ifndef MS_WIN32 /* do signal stuff only on unix */
if(please_dumpstats) {
- dumpstats();
+ dumpstats(LOG_INFO);
please_dumpstats = 0;
}
if(please_reset) {
@@ -630,13 +630,15 @@
/* poll until we have an event, or the second ends */
poll_result = poll(poll_array, nfds, timeout);
-#if 0 /* let catch() handle things like ^c, and otherwise don't worry about it */
+ /* let catch() handle things like ^c, and otherwise don't worry about it */
if(poll_result < 0) {
- log(LOG_ERR,"do_main_loop(): poll failed.");
- if(errno != EINTR) /* let the program survive things like ^z */
+ if(errno != EINTR) { /* let the program survive things like ^z */
+ log_fn(LOG_ERR,"poll failed.");
return -1;
+ } else {
+ log_fn(LOG_DEBUG,"poll interrupted."):
+ }
}
-#endif
/* do all the reads and errors first, so we can detect closed sockets */
for(i=0;i<nfds;i++)
@@ -683,36 +685,36 @@
#endif /* signal stuff */
}
-static void dumpstats(void) { /* dump stats to stdout */
+static void dumpstats(int severity) {
int i;
connection_t *conn;
time_t now = time(NULL);
- printf("Dumping stats:\n");
+ log(severity, "Dumping stats:");
for(i=0;i<nfds;i++) {
conn = connection_array[i];
- printf("Conn %d (socket %d) type %d (%s), state %d (%s), created %ld secs ago\n",
+ log(severity, "Conn %d (socket %d) type %d (%s), state %d (%s), created %ld secs ago",
i, conn->s, conn->type, conn_type_to_string[conn->type],
conn->state, conn_state_to_string[conn->type][conn->state], now - conn->timestamp_created);
if(!connection_is_listener(conn)) {
- 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,
+ log(severity,"Conn %d is to '%s:%d'.",i,conn->address, conn->port);
+ log(severity,"Conn %d: %d bytes waiting on inbuf (last read %ld secs ago)",i,
(int)buf_datalen(conn->inbuf),
now - conn->timestamp_lastread);
- printf("Conn %d: %d bytes waiting on outbuf (last written %ld secs ago)\n",i,
+ log(severity,"Conn %d: %d bytes waiting on outbuf (last written %ld secs ago)",i,
(int)buf_datalen(conn->outbuf), now - conn->timestamp_lastwritten);
}
- circuit_dump_by_conn(conn); /* dump info about all the circuits using this conn */
- printf("\n");
+ circuit_dump_by_conn(conn, severity); /* dump info about all the circuits using this conn */
}
- printf("Cells processed: %10lu padding\n"
+ log(severity,
+ "Cells processed: %10lu padding\n"
" %10lu create\n"
" %10lu created\n"
" %10lu relay\n"
" (%10lu relayed)\n"
" (%10lu delivered)\n"
- " %10lud destroy\n",
+ " %10lud destroy",
stats_n_padding_cells_processed,
stats_n_create_cells_processed,
stats_n_created_cells_processed,
@@ -721,16 +723,16 @@
stats_n_relay_cells_delivered,
stats_n_destroy_cells_processed);
if (stats_n_data_cells_packaged)
- printf("Average outgoing cell fullness: %2.3f%%\n",
+ log(severity,"Average outgoing cell fullness: %2.3f%%",
100*(((double)stats_n_data_bytes_packaged) /
(stats_n_data_cells_packaged*(CELL_PAYLOAD_SIZE-RELAY_HEADER_SIZE))) );
if (stats_n_data_cells_packaged)
- printf("Average incoming cell fullness: %2.3f%%\n",
+ log(severity,"Average incoming cell fullness: %2.3f%%",
100*(((double)stats_n_data_bytes_received) /
(stats_n_data_cells_received*(CELL_PAYLOAD_SIZE-RELAY_HEADER_SIZE))) );
if (stats_n_seconds_reading)
- printf("Average bandwidth used: %d bytes/sec\n",
+ log(severity,"Average bandwidth used: %d bytes/sec",
(int) (stats_n_bytes_read/stats_n_seconds_reading));
}
@@ -789,7 +791,7 @@
#ifndef MS_WINDOWS /* do signal stuff only on unix */
signal (SIGINT, catch); /* catch kills so we can exit cleanly */
signal (SIGTERM, catch);
- signal (SIGUSR1, catch); /* to dump stats to stdout */
+ signal (SIGUSR1, catch); /* to dump stats */
signal (SIGHUP, catch); /* to reload directory */
signal (SIGCHLD, catch); /* for exiting dns/cpu workers */
#endif /* signal stuff */