Clean up debugging code

Only use DEBUG inside "if (debug & DEBUG_BLAH)", not INFO or WARN or WHY!
INFO messages for starting/stopping servald server.
This commit is contained in:
Andrew Bettison 2012-06-28 15:37:36 +09:30
parent 9625190c6a
commit a5ba1ecacd
4 changed files with 51 additions and 46 deletions

20
lsif.c
View File

@ -71,7 +71,7 @@
*/
int scrapeProcNetRoute()
{
if (debug & DEBUG_OVERLAYINTERFACES) INFO("called");
if (debug & DEBUG_OVERLAYINTERFACES) DEBUG("called");
FILE *f=fopen("/proc/net/route","r");
if (!f) return fprintf(stderr,"Can't read from /proc/net/route\n");
@ -118,7 +118,7 @@ lsif(void) {
struct ifreq *ifr;
struct sockaddr_in local, broadcast;
if (debug & DEBUG_OVERLAYINTERFACES) INFO("called");
if (debug & DEBUG_OVERLAYINTERFACES) DEBUG("called");
/* Get a socket handle. */
sck = socket(PF_INET, SOCK_DGRAM, 0);
@ -144,7 +144,7 @@ lsif(void) {
/* We're only interested in IPv4 addresses */
if (ifr->ifr_ifru.ifru_addr.sa_family != AF_INET) {
if (debug & DEBUG_OVERLAYINTERFACES) INFOF("Skipping non-AF_INET address on %s", ifr->ifr_name);
if (debug & DEBUG_OVERLAYINTERFACES) DEBUGF("Skipping non-AF_INET address on %s", ifr->ifr_name);
continue;
}
@ -154,7 +154,7 @@ lsif(void) {
/* Not broadcast? Not interested.. */
if ((ifr->ifr_ifru.ifru_flags & IFF_BROADCAST) == 0) {
if (debug & DEBUG_OVERLAYINTERFACES) INFOF("Skipping non-broadcast address on %s", ifr->ifr_name);
if (debug & DEBUG_OVERLAYINTERFACES) DEBUGF("Skipping non-broadcast address on %s", ifr->ifr_name);
continue;
}
@ -169,7 +169,7 @@ lsif(void) {
char addrtxt[INET_ADDRSTRLEN], bcasttxt[INET_ADDRSTRLEN];
assert(inet_ntop(AF_INET, (const void *)&local.sin_addr, addrtxt, INET_ADDRSTRLEN) != NULL);
assert(inet_ntop(AF_INET, (const void *)&broadcast.sin_addr, bcasttxt, INET_ADDRSTRLEN) != NULL);
INFOF("name=%s addr=%s, broad=%s\n",
DEBUGF("name=%s addr=%s, broad=%s\n",
ifr->ifr_name,
addrtxt, bcasttxt);
}
@ -177,7 +177,7 @@ lsif(void) {
nInterfaces++;
}
if (debug & DEBUG_OVERLAYINTERFACES) INFOF("Examined %d interface addresses\n", nInterfaces);
if (debug & DEBUG_OVERLAYINTERFACES) DEBUGF("Examined %d interface addresses\n", nInterfaces);
close(sck);
return 0;
@ -192,7 +192,7 @@ doifaddrs(void) {
char *name;
struct sockaddr_in local, netmask, broadcast;
if (debug & DEBUG_OVERLAYINTERFACES) INFOF("called");
if (debug & DEBUG_OVERLAYINTERFACES) DEBUGF("called");
if (getifaddrs(&ifaddr) == -1)
return WHY_perror("getifaddr()");
@ -200,13 +200,13 @@ doifaddrs(void) {
for (ifa = ifaddr; ifa != NULL ; ifa = ifa->ifa_next) {
/* We're only interested in IPv4 addresses */
if (ifa->ifa_addr->sa_family != AF_INET) {
if (debug & DEBUG_OVERLAYINTERFACES) INFOF("Skipping non-AF_INET address on %s", ifa->ifa_name);
if (debug & DEBUG_OVERLAYINTERFACES) DEBUGF("Skipping non-AF_INET address on %s", ifa->ifa_name);
continue;
}
/* Not broadcast? Not interested.. */
if ((ifa->ifa_flags & IFF_BROADCAST) == 0) {
if (debug & DEBUG_OVERLAYINTERFACES) INFOF("Skipping non-broadcast address on %s", ifa->ifa_name);
if (debug & DEBUG_OVERLAYINTERFACES) DEBUGF("Skipping non-broadcast address on %s", ifa->ifa_name);
continue;
}
@ -222,7 +222,7 @@ doifaddrs(void) {
char addrtxt[INET_ADDRSTRLEN], bcasttxt[INET_ADDRSTRLEN];
assert(inet_ntop(AF_INET, (const void *)&local.sin_addr, addrtxt, INET_ADDRSTRLEN) != NULL);
assert(inet_ntop(AF_INET, (const void *)&broadcast.sin_addr, bcasttxt, INET_ADDRSTRLEN) != NULL);
INFOF("name=%s addr=%s broad=%s", name, addrtxt, bcasttxt);
DEBUGF("name=%s addr=%s broad=%s", name, addrtxt, bcasttxt);
}
overlay_interface_register(name,local,broadcast);

View File

@ -116,7 +116,7 @@ int monitor_setup_sockets()
if(setsockopt(monitor_named_socket, SOL_SOCKET, SO_RCVBUF,
&send_buffer_size, sizeof(send_buffer_size))==-1)
WHY_perror("setsockopt");
if (debug&(DEBUG_IO|DEBUG_VERBOSE_IO)) WHY("Monitor server socket setup");
if (debug&(DEBUG_IO|DEBUG_VERBOSE_IO)) DEBUG("Monitor server socket setup");
return 0;
@ -139,7 +139,7 @@ int monitor_get_fds(struct pollfd *fds,int *fdcount,int fdmax)
if (monitor_named_socket>-1)
{
if (debug&(DEBUG_IO|DEBUG_VERBOSE_IO)) {
WHYF("Monitor named unix domain socket is poll() slot #%d (fd %d)\n",
DEBUGF("Monitor named unix domain socket is poll() slot #%d (fd %d)\n",
*fdcount,monitor_named_socket);
}
fds[*fdcount].fd=monitor_named_socket;
@ -149,11 +149,11 @@ int monitor_get_fds(struct pollfd *fds,int *fdcount,int fdmax)
int i;
if (debug&(DEBUG_IO|DEBUG_VERBOSE_IO))
WHYF("looking at %d monitor clients",monitor_socket_count);
DEBUGF("looking at %d monitor clients",monitor_socket_count);
for(i=0;i<monitor_socket_count;i++) {
if ((*fdcount)>=fdmax) return -1;
if (debug&(DEBUG_IO|DEBUG_VERBOSE_IO)) {
WHYF("Monitor named unix domain client socket is poll() slot #%d (fd %d)\n",
DEBUGF("Monitor named unix domain client socket is poll() slot #%d (fd %d)\n",
*fdcount,monitor_sockets[i].socket);
}
fds[*fdcount].fd=monitor_sockets[i].socket;
@ -175,17 +175,17 @@ monitor_poll(void) {
/* tell all monitor clients about status of all calls periodically */
now = overlay_gettime_ms();
if (monitor_last_update_time > (now + 1000)) {
WHY("Fixed run away monitor_last_update_time");
INFO("Fixed run away monitor_last_update_time");
monitor_last_update_time = now + 1000;
}
if (now > (monitor_last_update_time + 1000)) {
// WHY("Send keep alives");
// DEBUG("Send keep alives");
monitor_last_update_time = now;
for(i = 0; i < vomp_call_count; i++) {
/* Push out any undelivered status changes */
monitor_call_status(&vomp_call_states[i]);
WHYF("Sending keepalives for call #%d",i);
INFOF("Sending keepalives for call #%d",i);
/* And let far-end know that call is still alive */
snprintf(msg,sizeof(msg) -1,"\nKEEPALIVE:%06x\n", vomp_call_states[i].local.session);
@ -207,12 +207,16 @@ monitor_poll(void) {
#endif
!= -1
) {
addrlen = 0;
addrlen = 0;
monitor_new_socket(s);
}
if (errno != EAGAIN)
if (errno != EAGAIN) {
#ifdef HAVE_LINUX_IF_H
WHY_perror("accept4(O_NONBLOCK)");
#else
WHY_perror("accept");
#endif
}
/* Read from any open connections */
for(i = 0;i < monitor_socket_count; i++) {
@ -307,7 +311,7 @@ monitor_poll(void) {
break;
default:
c->state = MONITOR_STATE_COMMAND;
WHY("fixed monitor connection state");
INFO("fixed monitor connection state");
}
}
@ -447,7 +451,7 @@ int monitor_process_command(int index,char *cmd)
}
}
else if (sscanf(cmd,"call %s %s %s",sid,localDid,remoteDid)==3) {
WHY("here");
DEBUG("here");
if (sid[0]=='*') {
/* For testing, pick a peer and call them */
int bin,slot;
@ -474,7 +478,7 @@ int monitor_process_command(int index,char *cmd)
stowSid(&mdp.vompevent.remote_sid[0],0,sid);
vomp_mdp_event(&mdp,NULL,0);
}
WHY("here");
DEBUG("here");
}
else if (sscanf(cmd,"status %x",&callSessionToken)==1) {
int i;
@ -532,10 +536,11 @@ int monitor_process_data(int index)
struct monitor_context *c=&monitor_sockets[index];
c->state=MONITOR_STATE_COMMAND;
if (vomp_sample_size(c->sample_codec)!=c->data_offset)
return
WHYF("Ignoring sample block of incorrect size (expected %d, got %d bytes for codec %d)",
if (vomp_sample_size(c->sample_codec)!=c->data_offset) {
WARNF("Ignoring sample block of incorrect size (expected %d, got %d bytes for codec %d)",
vomp_sample_size(c->sample_codec), c->data_offset, c->sample_codec);
return -1;
}
fcntl(c->socket,F_SETFL,
fcntl(c->socket, F_GETFL, NULL)|O_NONBLOCK);
@ -555,7 +560,7 @@ int monitor_process_data(int index)
vomp_sample_size(c->sample_codec));
mdp.vompevent.audio_sample_bytes=vomp_sample_size(c->sample_codec);
if (overlay_mdp_send(&mdp,0,0)) WHY("Send audio failed.");
if (overlay_mdp_send(&mdp,0,0)) WARN("Send audio failed.");
return 0;
}
@ -587,8 +592,8 @@ int monitor_announce_bundle(rhizome_manifest *m)
WRITE_STR(monitor_sockets[i].socket,msg);
if (errno&&(errno!=EINTR)&&(errno!=EAGAIN)) {
/* error sending update, so kill monitor socket */
WHYF("Tearing down monitor client #%d due to errno=%d",
i,errno);
WHY_perror("write");
INFOF("Tearing down monitor client #%d", i);
close(monitor_sockets[i].socket);
if (i==monitor_socket_count-1) {
monitor_socket_count--;
@ -615,7 +620,7 @@ int monitor_call_status(vomp_call_state *call)
call->local.last_state=call->local.state;
call->remote.last_state=call->remote.state;
if (show) {
if (0) WHYF("sending call status to monitor");
if (0) DEBUG("sending call status to monitor");
snprintf(msg,1024,"\nCALLSTATUS:%06x:%06x:%d:%d:%d:%s:%s:%s:%s\n",
call->local.session,call->remote.session,
call->local.state,call->remote.state,
@ -635,8 +640,8 @@ int monitor_call_status(vomp_call_state *call)
WRITE_STR(monitor_sockets[i].socket,msg);
if (errno&&(errno!=EINTR)&&(errno!=EAGAIN)) {
/* error sending update, so kill monitor socket */
WHYF("Tearing down monitor client #%d due to errno=%d",
i,errno);
WHY_perror("write");
INFOF("Tearing down monitor client #%d", i);
close(monitor_sockets[i].socket);
if (i==monitor_socket_count-1) {
monitor_socket_count--;
@ -664,7 +669,7 @@ int monitor_announce_peer(unsigned char *sid)
int monitor_send_audio(vomp_call_state *call,overlay_mdp_frame *audio)
{
if (0) WHYF("Tell call monitor about audio for call %06x:%06x",
if (0) DEBUGF("Tell call monitor about audio for call %06x:%06x",
call->local.session,call->remote.session);
int sample_bytes=vomp_sample_size(audio->vompevent.audio_sample_codec);
char msg[1024 + MAX_AUDIO_BYTES];
@ -698,11 +703,11 @@ int monitor_tell_clients(char *msg, int msglen, int mask)
fcntl(monitor_sockets[i].socket,F_SETFL,
fcntl(monitor_sockets[i].socket, F_GETFL, NULL)|O_NONBLOCK);
WRITE_STR(monitor_sockets[i].socket,msg);
// WHYF("Writing AUDIOPACKET to client");
// DEBUGF("Writing AUDIOPACKET to client");
if (errno&&(errno!=EINTR)&&(errno!=EAGAIN)) {
/* error sending update, so kill monitor socket */
WHYF("Tearing down monitor client #%d due to errno=%d",
i,errno);
WHY_perror("write");
INFOF("Tearing down monitor client #%d", i);
close(monitor_sockets[i].socket);
if (i==monitor_socket_count-1) {
monitor_socket_count--;

View File

@ -230,7 +230,7 @@ overlay_interface_init_socket(int interface, struct sockaddr_in src_addr, struct
goto error;
}
assert(inet_ntop(AF_INET, (const void *)&broadcast.sin_addr, srctxt, INET_ADDRSTRLEN) != NULL);
if (debug & (DEBUG_PACKETRX | DEBUG_IO)) INFOF("Bound to %s:%d", srctxt, ntohs(broadcast.sin_port));
if (debug & (DEBUG_PACKETRX | DEBUG_IO)) DEBUGF("Bound to %s:%d", srctxt, ntohs(broadcast.sin_port));
return 0;
@ -534,7 +534,7 @@ overlay_interface_register(char *name,
if (me == NULL || me->excludeP) {
if (debug & DEBUG_OVERLAYINTERFACES)
INFOF("Interface %s is not interesting.",name);
DEBUGF("Interface %s is not interesting.",name);
return 0;
}
@ -576,7 +576,7 @@ overlay_interface_register(char *name,
if (overlay_interface_init(name,local, broadcast, me->speed_in_bits, me->port, me->type))
WHYF("Could not initialise newly seen interface %s", name);
else
if (debug & DEBUG_OVERLAYINTERFACES) INFOF("Registered interface %s", name);
if (debug & DEBUG_OVERLAYINTERFACES) DEBUGF("Registered interface %s", name);
}
return 0;
@ -624,7 +624,7 @@ overlay_interface_discover(void) {
if (debug & DEBUG_OVERLAYINTERFACES) WHYF("Could not initialise newly seen interface %s", r->namespec);
}
else
if (debug & DEBUG_OVERLAYINTERFACES) INFOF("Registered interface %s",r->namespec);
if (debug & DEBUG_OVERLAYINTERFACES) DEBUGF("Registered interface %s",r->namespec);
}
}
@ -981,12 +981,12 @@ overlay_check_ticks(void) {
/* Now check if the next tick time for the interfaces is no later than that time.
If so, trigger a tick on the interface. */
if (debug & DEBUG_OVERLAYINTERFACES) INFOF("Examining %d interfaces.",overlay_interface_count);
if (debug & DEBUG_OVERLAYINTERFACES) DEBUGF("Examining %d interfaces.",overlay_interface_count);
for(i = 0; i < overlay_interface_count; i++) {
TIMING_CHECK();
/* Only tick live interfaces */
if (overlay_interfaces[i].observed > 0) {
if (debug & DEBUG_VERBOSE_IO) INFOF("Interface %s ticks every %dms, last at %lld.",
if (debug & DEBUG_VERBOSE_IO) DEBUGF("Interface %s ticks every %dms, last at %lld.",
overlay_interfaces[i].name,
overlay_interfaces[i].tick_ms,
overlay_interfaces[i].last_tick_ms);
@ -999,7 +999,7 @@ overlay_check_ticks(void) {
overlay_interfaces[i].last_tick_ms = now;
}
} else
if (debug & DEBUG_VERBOSE_IO) INFOF("Interface %s is awol.", overlay_interfaces[i].name);
if (debug & DEBUG_VERBOSE_IO) DEBUGF("Interface %s is awol.", overlay_interfaces[i].name);
TIMING_CHECK();
}

View File

@ -234,12 +234,12 @@ int server(char *backing_file)
void server_shutdown_check()
{
if (servalShutdown) {
WHY("Shutdown flag set -- terminating with cleanup");
INFO("Shutdown flag set -- terminating with cleanup");
serverCleanUp();
exit(0);
}
if (server_check_stopfile() == 1) {
WHY("Shutdown file exists -- terminating with cleanup");
INFO("Shutdown file exists -- terminating with cleanup");
serverCleanUp();
exit(0);
}
@ -251,7 +251,7 @@ void server_shutdown_check()
if (server_pid_time_ms == 0 || time_ms - server_pid_time_ms > 1000) {
server_pid_time_ms = time_ms;
if (server_pid() != server_getpid) {
WHYF("Server pid file no longer contains pid=%d -- shutting down without cleanup", server_getpid);
WARNF("Server pid file no longer contains pid=%d -- shutting down without cleanup", server_getpid);
exit(1);
}
}