|
From: <jn...@us...> - 2007-05-11 16:26:08
|
Revision: 29
http://opencalea.svn.sourceforge.net/opencalea/?rev=29&view=rev
Author: jnorell
Date: 2007-05-11 09:26:07 -0700 (Fri, 11 May 2007)
Log Message:
-----------
Enhancing debug/log messages with program name and pid.
Modified Paths:
--------------
trunk/src/common.h
trunk/src/df_collector.c
trunk/src/lea_collector.c
trunk/src/log_debug.c
trunk/src/tap.c
Modified: trunk/src/common.h
===================================================================
--- trunk/src/common.h 2007-05-11 14:22:35 UTC (rev 28)
+++ trunk/src/common.h 2007-05-11 16:26:07 UTC (rev 29)
@@ -132,8 +132,9 @@
#define DEF_TAP_USER DEF_USER
#define DEF_TAP_GROUP DEF_GROUP
-#define MAX_MSGSIZE 4096 /* max size of control message/response */
+#define MAX_MSGSIZE 4096 /* max size of control message/response */
#define MAX_LINE 512
+#define MAX_HOST 128 /* maximum size of hostname */
#define min(a,b) ((a) < (b) ? (a) : (b))
#define max(a,b) ((a) > (b) ? (a) : (b))
Modified: trunk/src/df_collector.c
===================================================================
--- trunk/src/df_collector.c 2007-05-11 14:22:35 UTC (rev 28)
+++ trunk/src/df_collector.c 2007-05-11 16:26:07 UTC (rev 29)
@@ -216,39 +216,39 @@
/* Get CmII_Path from config file */
if ((confptr = get_config(&config, "CmII_Path")) != NULL) {
cmii_path = Strdup(*confptr->nextval++);
- debug_4("df_collector: CmII_Path [%s]", cmii_path);
+ debug_4("CmII_Path [%s]", cmii_path);
}
/* Get CmC_Path from config file */
if ((confptr = get_config(&config, "CmC_Path")) != NULL) {
cmc_path = Strdup(*confptr->nextval++);
- debug_4("df_collector: CmC_Path [%s]", cmc_path);
+ debug_4("CmC_Path [%s]", cmc_path);
}
/* Get Log_Path from config file */
if ((confptr = get_config(&config, "Log_Path")) != NULL) {
log_path = Strdup(*confptr->nextval++);
- debug_4("df_collector: log_path [%s]", log_path);
+ debug_4("log_path [%s]", log_path);
}
if ( bind_addr == NULL ) {
if ((confptr = get_config(&config, "Bind_Addr"))) {
bind_addr = Strdup ( *confptr->nextval++ );
- debug_4("df_collector: bind address set from config file (%s)", bind_addr);
+ debug_4("bind address set from config file (%s)", bind_addr);
} else {
bind_addr = Strdup ( "127.0.0.1" );
- debug_4("df_collector: Using default bind address (%s)", bind_addr);
+ debug_4("Using default bind address (%s)", bind_addr);
}
}
if ( df_port == NULL ) {
if ((confptr = get_config(&config, "DF_Port"))) {
df_port = Strdup ( *confptr->nextval++ );
- debug_5 ( "df_collector: DF listener port set from config file (%d)", df_port );
+ debug_4 ( "DF listener port set from config file (%d)", df_port );
} else {
df_port = Calloc ( 64 );
snprintf ( df_port, 64, "%d", DF_PORT );
- debug_5 ( "df_collector: Using default DF listener port (%d)", df_port );
+ debug_4 ( "Using default DF listener port (%d)", df_port );
}
}
@@ -279,11 +279,11 @@
switch(msg->msgh.msgtype) {
case MSGTYPE_NONE:
- debug_2("df_collector: MSGTYPE_NONE uninitialized or not present");
+ debug_2("MSGTYPE_NONE uninitialized or not present");
break;
case MSGTYPE_CONTROL:
- //debug_3("df_collector: MSGTYPE_CONTROL OpenCALEA Control message");
+ debug_3("MSGTYPE_CONTROL OpenCALEA Control message");
ctrlmsg = (CtrlMsg *)((char *)msg + msg_len);
//print_hex((const u_char *)msg, msg_len);
@@ -292,7 +292,7 @@
switch (ctrlmsg->ctrlh.cmd) {
case CTRLCMD_ROUTE_ADD:
- debug_3("df_collector: ROUTE ADD Control message received");
+ debug_3("ROUTE ADD Control message received");
/* look for a free slot in the route[] table */
for (id=0; id<MAXROUTES; id++) {
@@ -301,8 +301,8 @@
}
if (id == MAXROUTES) {
- debug_1("df_collector: no available routes");
- log_2("df_collector: no available routes");
+ debug_1("no available routes");
+ log_2("no available routes");
return -1;
}
@@ -316,8 +316,8 @@
strncat(filename,(char *)ctrlmsg->ctrlh.intercept.CaseID,MAX_LINE - strlen(filename));
strncat(filename,".CmII",MAX_LINE - strlen(filename));
if (!(route[id].cmii_fp = fopen(filename, "wb"))) {
- error("df_collector: CmII_fp open failed for %s", filename);
- pdie("df_collector: CmII_fp fopen");
+ error("CmII_fp open failed for %s", filename);
+ pdie("CmII_fp fopen");
}
}
@@ -331,8 +331,8 @@
strncat(filename,(char *)ctrlmsg->ctrlh.intercept.CaseID,MAX_LINE - strlen(filename));
strncat(filename,".CmC",MAX_LINE - strlen(filename));
if (!(route[id].cmc_fp = fopen(filename, "wb"))) {
- error("df_collector: CmC_fp open failed for %s", filename);
- pdie("df_collector: CmC_fp fopen");
+ error("CmC_fp open failed for %s", filename);
+ pdie("CmC_fp fopen");
}
}
@@ -346,8 +346,8 @@
strncat(filename,(char *)ctrlmsg->ctrlh.intercept.CaseID,MAX_LINE - strlen(filename));
strncat(filename,".LOG",MAX_LINE - strlen(filename));
if (!(route[id].log_fp = fopen(filename, "w"))) {
- error("df_collector: Surveillance log file open failed for %s", filename);
- pdie("df_collector: Surveillance log fopen");
+ error("Surveillance log file open failed for %s", filename);
+ pdie("Surveillance log fopen");
}
}
@@ -356,20 +356,21 @@
/*****************************************/
sprintf(route_port, "%d", ntohs(ctrlmsg->ctrlh.dfhost.port));
if (strcmp((char *)ctrlmsg->ctrlh.dfhost.protocol,"udp") == 0) {
- debug_4("df_collector: route protocol is UDP");
+ debug_4("route protocol is UDP");
socktype = SOCK_DGRAM;
} else if (strcmp((char *)ctrlmsg->ctrlh.dfhost.protocol,"tcp") == 0) {
- error("df_collector: TCP is currently an unsupported route protocol");
+ error("TCP is currently an unsupported route protocol");
socktype = SOCK_STREAM;
} else {
- debug_2("df_collector: %s is currently an unsupported route protocol. Defaulting to UDP",
+ debug_2("%s is currently an unsupported route protocol. Defaulting to UDP",
ctrlmsg->ctrlh.dfhost.protocol);
socktype = SOCK_DGRAM;
}
res = Getaddrinfo1st((char *)ctrlmsg->ctrlh.dfhost.host, route_port, AF_INET, socktype);
if (!res) {
- debug_5("df_collector: ROUTE ADD Getaddrinfo1st failed");
+ debug_3("ROUTE ADD Getaddrinfo1st failed");
+ log_3("ROUTE ADD Getaddrinfo1st failed");
return -1;
}
@@ -381,17 +382,17 @@
route[id].lea_addr.sin_port = ((struct sockaddr_in *)res->ai_addr)->sin_port;
route[id].lea_addr.sin_addr.s_addr = ((struct sockaddr_in *)res->ai_addr)->sin_addr.s_addr;
if ((route[id].lea_fd = socket(res->ai_family, res->ai_socktype, res->ai_protocol)) < 0) {
- debug_2("df_collector: ipv4 route[%d]=%d socket failure", id, route[id].lea_fd);
+ debug_2("ipv4 route[%d]=%d socket failure", id, route[id].lea_fd);
break;
}
if (connect(route[id].lea_fd, res->ai_addr, res->ai_addrlen) < 0) {
- debug_2 ( "df_collector: connect error");
+ debug_2 ( "connect error");
Close(route[id].lea_fd);
route[id].lea_fd = -1;
}
- debug_3("df_collector: ROUTE[%d] created to %s://%s:%d [%s %s %s]",
+ debug_3("ROUTE[%d] created to %s://%s:%d [%s %s %s]",
id,
ctrlmsg->ctrlh.dfhost.protocol,
ctrlmsg->ctrlh.dfhost.host,
@@ -404,10 +405,10 @@
freeaddrinfo(res);
return DF_REPLY;
case AF_INET6:
- error("df_collector: we don't handle IPv6 yet.");
+ error("we don't handle IPv6 yet.");
break;
default:
- error("df_collector: we don't handle address family %d.", res->ai_family);
+ error("we don't handle address family %d.", res->ai_family);
break;
}
break;
@@ -417,7 +418,7 @@
}
case MSGTYPE_LOG:
- debug_4("df_collector: MSGTYPE_LOG Surveillance Log message");
+ debug_4("MSGTYPE_LOG Surveillance Log message");
//print_hex((const u_char *)msg, msg_len);
//print_hex((const u_char *)((char *)msg + msg_len), msg->msgh.msglen);
@@ -426,21 +427,24 @@
if (route[id].log_fp) {
ret = fwrite(((char *)msg + msg_len), msg->msgh.msglen, 1, route[id].log_fp);
if (ret != 1) {
- error("df_collector: error writing to Log file: %s", strerror(errno));
+ error("error writing to Log file: %s", strerror(errno));
}
} else {
- debug_2("df_collector: Warning Log file is not available");
+ debug_2("Warning Log file is not available");
}
break;
case MSGTYPE_CMII:
- debug_5("df_collector: MSGTYPE_CMII Communications Identifying Information message");
+ debug_5("MSGTYPE_CMII Communications Identifying Information message");
//print_hex((const u_char *)msg, msg_len);
//print_hex((const u_char *)((char *)msg + msg_len), msg->msgh.msglen);
id = ntohs(msg->msgh.routeid);
- inet_ntop (route[id].lea_addr.sin_family, &route[id].lea_addr.sin_addr.s_addr, addrstr, sizeof(addrstr));
+ if (inet_ntop (route[id].lea_addr.sin_family,
+ &route[id].lea_addr.sin_addr.s_addr, addrstr, sizeof(addrstr)) == NULL) {
+ error("inet_ntop: %s", strerror(errno));
+ }
/**************************/
/* Write packet to a file */
@@ -448,10 +452,10 @@
if (route[id].cmii_fp) {
ret = fwrite(((char *)msg + msg_len), msg->msgh.msglen, 1, route[id].cmii_fp);
if (ret != 1) {
- error("df_collector: error writing to CmII file: %s", strerror(errno));
+ error("error writing to CmII file: %s", strerror(errno));
}
} else {
- debug_5("df_collector: CmII capture file is not available");
+ debug_5("CmII capture file is not available");
}
num_sent = sendto (route[id].lea_fd,
@@ -469,7 +473,7 @@
/* GUARANTEE that the data was actually received at the remote end. */
/****************************************************************************/
if (num_sent == -1) {
- debug_5("df_collector: CmII packet -> route[%d] %s:%d failed saving to file",
+ debug_5("CmII packet -> route[%d] %s:%d failed, saving to file",
id,
addrstr,
ntohs(route[id].lea_addr.sin_port));
@@ -482,15 +486,15 @@
if (route[id].cmii_fp) {
ret = fwrite(((char *)msg + msg_len), msg->msgh.msglen, 1, route[id].cmii_fp);
if (ret != 1) {
- debug_5("df_collector: Error writing to CmII file");
+ error("Error writing to CmII file: %s", strerror(errno));
} else {
- debug_5("df_collector: Wrote %d bytes to CmII file", (ret * msg->msgh.msglen));
+ debug_5("Wrote %d bytes to CmII file", (ret * msg->msgh.msglen));
}
} else {
- debug_5("df_collector: Warning CmII capture file is not available");
+ debug_5("Warning CmII capture file is not available");
}
} else {
- debug_5("df_collector: CmII packet -> route[%d] %s:%d %d bytes sent ",
+ debug_5("CmII packet -> route[%d] %s:%d %d bytes sent ",
id,
addrstr,
ntohs(route[id].lea_addr.sin_port),
@@ -500,16 +504,19 @@
break;
case MSGTYPE_CII:
- debug_3("df_collector: MSGTYPE_CII Call Identifying Information message");
+ debug_3("MSGTYPE_CII Call Identifying Information message");
break;
case MSGTYPE_CMC:
- debug_5("df_collector: MSGTYPE_CMC Communications Content message");
+ debug_5("MSGTYPE_CMC Communications Content message");
//print_hex((const u_char *)msg, msg_len);
//print_hex((const u_char *)((char *)msg + msg_len), msg->msgh.msglen);
id = ntohs(msg->msgh.routeid);
- inet_ntop (route[id].lea_addr.sin_family, &route[id].lea_addr.sin_addr.s_addr, addrstr, sizeof(addrstr));
+ if (inet_ntop (route[id].lea_addr.sin_family,
+ &route[id].lea_addr.sin_addr.s_addr, addrstr, sizeof(addrstr)) == NULL) {
+ error("inet_ntop: %s", strerror(errno));
+ }
num_sent = sendto (route[id].lea_fd,
((char *)msg + msg_len),
@@ -526,7 +533,7 @@
/* GUARANTEE that the data was actually received at the remote end. */
/****************************************************************************/
if (num_sent == -1) {
- debug_5("df_collector: CmC packet -> route[%d] %s:%d failed saving to file",
+ debug_5("CmC packet -> route[%d] %s:%d failed, saving to file",
id,
addrstr,
ntohs(route[id].lea_addr.sin_port));
@@ -538,16 +545,16 @@
if (route[id].cmc_fp) {
ret = fwrite(((char *)msg + msg_len), msg->msgh.msglen, 1, route[id].cmc_fp);
if (ret != 1) {
- debug_5("df_collector: Error writing to CmC file");
+ error("Error writing to CmC file: %s", strerror(errno));
} else {
- debug_5("df_collector: Wrote %d bytes to CmC file", (ret * msg->msgh.msglen));
+ debug_5("Wrote %d bytes to CmC file", (ret * msg->msgh.msglen));
}
} else {
- debug_5("df_collector: Warning CmC capture file is not available");
+ debug_5("Warning CmC capture file is not available");
}
} else {
- debug_5("df_collector: CmC packet -> route[%d] %s:%d %d bytes sent ",
+ debug_5("CmC packet -> route[%d] %s:%d %d bytes sent ",
id,
addrstr,
ntohs(route[id].lea_addr.sin_port),
@@ -557,10 +564,10 @@
break;
case MSGTYPE_CC:
- debug_3("df_collector: MSGTYPE_CC Call Content message");
+ debug_3("MSGTYPE_CC Call Content message");
break;
default:
- debug_2("df_collector: Unknown MSGTYPE detected");
+ debug_2("Unknown MSGTYPE detected: %d", msg->msgh.msgtype);
break;
}
@@ -570,31 +577,31 @@
switch(msg->msgh.format) {
case MSGFMT_NONE:
- debug_5("df_collector: MSGFMT_NONE uninitialized or not present");
+ debug_5("MSGFMT_NONE uninitialized or not present");
break;
case MSGFMT_C:
- debug_5("df_collector: MSGFMT_C C structure");
+ debug_5("MSGFMT_C C structure");
break;
case MSGFMT_XML:
- debug_5("df_collector: MSGFMT_XML eXtensible Markup Language");
+ debug_5("MSGFMT_XML eXtensible Markup Language");
break;
case MSGFMT_BER:
- debug_5("df_collector: MSGFMT_BER Basic Encoding Rules");
+ debug_5("MSGFMT_BER Basic Encoding Rules");
break;
case MSGFMT_TXT:
- debug_5("df_collector: MSGFMT_TXT Plain Text");
+ debug_5("MSGFMT_TXT Plain Text");
break;
case MSGFMT_CSV:
- debug_5("df_collector: MSGFMT_CSV Comma Seperated Values");
+ debug_5("MSGFMT_CSV Comma Seperated Values");
break;
case MSGFMT_IAS_D31:
- debug_5("df_collector: MSGFMT_IAS_D31 IAS section D.3.1 CmC in UDP Encapsulation");
+ debug_5("MSGFMT_IAS_D31 IAS section D.3.1 CmC in UDP Encapsulation");
break;
case MSGFMT_IAS_D32:
- debug_5("df_collector: MSGFMT_IAS_D32 IAS section D.3.2 CmC in IC-APDU's");
+ debug_5("MSGFMT_IAS_D32 IAS section D.3.2 CmC in IC-APDU's");
break;
default:
- debug_5("df_collector: Unknown MSGFMT detected");
+ debug_5("Unknown MSGFMT detected");
break;
}
@@ -641,7 +648,7 @@
res = Getaddrinfo1st(bind_addr, df_port, AF_INET, SOCK_STREAM);
if (!res) {
- debug_5("df_collector: %s:%s TCP Gteaddrinfo1st failed", bind_addr, df_port);
+ error("%s:%s TCP Gteaddrinfo1st failed", bind_addr, df_port);
return -1;
}
@@ -652,15 +659,17 @@
servaddr.sin_port = ((struct sockaddr_in *)res->ai_addr)->sin_port;
servaddr.sin_addr.s_addr = ((struct sockaddr_in *)res->ai_addr)->sin_addr.s_addr;
if ((df_tcpfd = Socket(res->ai_family, res->ai_socktype, res->ai_protocol)) < 0) {
- error("df_collector: DF TCP socket error");
+ error("DF TCP socket error");
}
break;
default:
- die("df_collector: DF TCP unsupported family");
+ die("DF TCP unsupported family");
break;
}
- inet_ntop (servaddr.sin_family, &servaddr.sin_addr.s_addr, addrstr, sizeof(addrstr));
- debug_5("df_collector: DF TCP IPv%d address: %s (%s) port: %d",
+ if (inet_ntop (servaddr.sin_family, &servaddr.sin_addr.s_addr, addrstr, sizeof(addrstr)) == NULL) {
+ error("inet_ntop: %s", strerror(errno));
+ }
+ debug_5("DF TCP IPv%d address: %s (%s) port: %d",
res->ai_family == PF_INET6 ? 6 : 4, addrstr, res->ai_canonname, ntohs(servaddr.sin_port));
freeaddrinfo(res);
@@ -676,7 +685,7 @@
res = Getaddrinfo1st(bind_addr, ctrl_port, AF_INET, SOCK_STREAM);
if (!res) {
- debug_5("df_collector: Control %s:%s TCP Gteaddrinfo1st failed", bind_addr, ctrl_port);
+ error("Control %s:%s TCP Gteaddrinfo1st failed", bind_addr, ctrl_port);
return -1;
}
@@ -687,15 +696,17 @@
servaddr.sin_port = ((struct sockaddr_in *)res->ai_addr)->sin_port;
servaddr.sin_addr.s_addr = ((struct sockaddr_in *)res->ai_addr)->sin_addr.s_addr;
if ((controlfd = Socket(res->ai_family, res->ai_socktype, res->ai_protocol)) < 0) {
- pdie("df_collector: control TCP socket error");
+ pdie("control TCP socket error");
}
break;
default:
- die("df_collector: control TCP unsupported family");
+ die("control TCP unsupported family");
break;
}
- inet_ntop (servaddr.sin_family, &servaddr.sin_addr.s_addr, addrstr, sizeof(addrstr));
- debug_5("df_collector: control TCP IPv%d address: %s (%s) port: %d",
+ if (inet_ntop (servaddr.sin_family, &servaddr.sin_addr.s_addr, addrstr, sizeof(addrstr)) == NULL) {
+ error("inet_ntop: %s", strerror(errno));
+ }
+ debug_5("control TCP IPv%d address: %s (%s) port: %d",
res->ai_family == PF_INET6 ? 6 : 4, addrstr, res->ai_canonname, ntohs(servaddr.sin_port));
freeaddrinfo(res);
@@ -709,7 +720,7 @@
res = Getaddrinfo1st(bind_addr, df_port, AF_INET, SOCK_DGRAM);
if (!res) {
- debug_5("df_collector: %s:%s TCP Gteaddrinfo1st failed", bind_addr, df_port);
+ error("%s:%s TCP Gteaddrinfo1st failed", bind_addr, df_port);
return -1;
}
@@ -720,15 +731,17 @@
servaddr.sin_port = ((struct sockaddr_in *)res->ai_addr)->sin_port;
servaddr.sin_addr.s_addr = ((struct sockaddr_in *)res->ai_addr)->sin_addr.s_addr;
if ((df_udpfd = Socket(res->ai_family, res->ai_socktype, res->ai_protocol)) < 0) {
- error("df_collector: DF UDP socket error");
+ error("DF UDP socket error");
}
break;
default:
- die("df_collector: DF UDP unsupported family");
+ die("DF UDP unsupported family");
break;
}
- inet_ntop (servaddr.sin_family, &servaddr.sin_addr.s_addr, addrstr, sizeof(addrstr));
- debug_5("df_collector: DF UDP IPv%d address: %s (%s) port: %d",
+ if (inet_ntop (servaddr.sin_family, &servaddr.sin_addr.s_addr, addrstr, sizeof(addrstr)) == NULL) {
+ error("inet_ntop: %s", strerror(errno));
+ }
+ debug_5("DF UDP IPv%d address: %s (%s) port: %d",
res->ai_family == PF_INET6 ? 6 : 4, addrstr, res->ai_canonname, ntohs(servaddr.sin_port));
freeaddrinfo(res);
@@ -765,7 +778,7 @@
if (errno == EINTR)
continue;
else {
- pdie("df_collector: select error");
+ pdie("select error");
}
}
@@ -782,7 +795,7 @@
}
if (i == FD_SETSIZE) {
- debug_5("Too many clients", 1);
+ error("Too many clients", 1);
}
FD_SET(connfd, &allset); /* add new descriptor to the set */
@@ -812,7 +825,7 @@
if (FD_ISSET(sockfd, &rset)) {
if ((n=read(sockfd, buf, MAX_MSGSIZE)) <= 0) {
- debug_3("df_collector: client closed connection (fd: %d)", sockfd);
+ debug_3("client closed connection (fd: %d)", sockfd);
Close(sockfd);
FD_CLR(sockfd, &allset);
client[i] = -1;
Modified: trunk/src/lea_collector.c
===================================================================
--- trunk/src/lea_collector.c 2007-05-11 14:22:35 UTC (rev 28)
+++ trunk/src/lea_collector.c 2007-05-11 16:26:07 UTC (rev 29)
@@ -402,28 +402,28 @@
FD_SET( cmc_receiver_socket, &sock_fds );
num_sock_fds = select( max_fd+1 , &sock_fds, NULL, NULL, NULL);
if ( num_sock_fds < 0 ) {
- pdie ( "lea_collector: select " );
+ pdie ( "select " );
} else if ( num_sock_fds == 0 ) {
- debug_5 ( "lea_collector: select returned with 0 descriptors ready" );
+ debug_5 ( "select returned with 0 descriptors ready" );
} else {
/* read data on sockets */
if ( FD_ISSET( cmii_receiver_socket, &sock_fds )) {
- debug_5 ( "lea_collector: CmII socket ready" );
+ debug_5 ( "CmII socket ready" );
if ((n = recvfrom ( cmii_receiver_socket, buf, 10000, 0, (struct sockaddr*) &cmii_receiver_addr, &len)) == -1) {
- pdie ( "lea_collector: cmii recvfrom" );
+ pdie ( "cmii recvfrom" );
} else {
- debug_5 ( "lea_collector: cmii recvfrom returned %d bytes", n );
+ debug_5 ( "cmii recvfrom returned %d bytes", n );
}
fwrite( buf, n, 1, cmii_fp);
}
if ( FD_ISSET( cmc_receiver_socket, &sock_fds )) {
- debug_5 ( "lea_collector: CmC socket ready" );
+ debug_5 ( "CmC socket ready" );
if ((n = recvfrom ( cmc_receiver_socket, buf, 10000, 0, (struct sockaddr*) &cmc_receiver_addr, &len)) == -1) {
- pdie ( "lea_collector: cmc recvfrom " );
+ pdie ( "cmc recvfrom " );
} else {
- debug_5 ( "lea_collector: cmc recvfrom returned %d bytes", n );
+ debug_5 ( "cmc recvfrom returned %d bytes", n );
}
fwrite( buf, n, 1, cmc_fp);
Modified: trunk/src/log_debug.c
===================================================================
--- trunk/src/log_debug.c 2007-05-11 14:22:35 UTC (rev 28)
+++ trunk/src/log_debug.c 2007-05-11 16:26:07 UTC (rev 29)
@@ -49,6 +49,10 @@
int debug_with_newlines = 0;
int log_with_newlines = 0;
+char save_name[64];
+int save_facility;
+int save_pid;
+
/* we want a high performance "do nothing" */
static void my_nulllog ( char *msg, ... ) { }
@@ -68,7 +72,6 @@
va_list ap;
char msg[MAX_DEBUG_MSG_LEN];
char *append = NULL;
- char myname[64];
char *curtime;
time_t tim;
@@ -88,13 +91,11 @@
}
curtime = ctime ( &tim );
curtime[ strlen ( curtime ) - 1 ] = 0; // remove \n
- if ( fprintf ( debug_fp, "%s %s%s", curtime, msg, append ) == -1 ) {
+ if ( fprintf ( debug_fp, "%s %s[%d]: %s%s", curtime, save_name, save_pid, msg, append ) == -1 ) {
perror ( "fprintf" );
exit ( -1 );
}
} else {
- snprintf ( myname, 64, "%s debug", prog_name );
- openlog ( myname, LOG_PID, syslog_facility );
syslog ( LOG_DEBUG, "%s", msg );
}
}
@@ -122,13 +123,11 @@
}
curtime = ctime ( &tim );
curtime[ strlen ( curtime ) - 1 ] = 0; // remove \n
- if ( fprintf ( log_fp, "%s %s%s", curtime, msg, append ) == -1 ) {
+ if ( fprintf ( log_fp, "%s %s[%d]: %s%s", curtime, save_name, save_pid, msg, append ) == -1 ) {
perror ( "fprintf" );
exit ( -1 );
}
} else {
- openlog (prog_name, LOG_PID, syslog_facility);
-
switch ( log_level ) {
case 1:
syslog ( LOG_ALERT, "%s", msg );
@@ -161,7 +160,10 @@
* with_newlines: guarantee terminating newlines to file output,
*/
void setdebug ( int level, char *debug_to, int with_newlines ) {
-
+ if (save_pid == 0) {
+ save_pid = (int)getpid();
+ }
+
if ( ( debug_fd && debug_to_file )
&& ( debug_fp != stdout )
&& ( debug_fp != stderr )
@@ -230,6 +232,14 @@
* with_newlines: guarantee terminating newlines to file output
*/
void setlog ( int level, char *log_to, int with_newlines ) {
+ if (save_pid == 0) {
+ save_pid = (int)getpid();
+ }
+ if (strncmp(save_name, prog_name, 64) || (save_facility != syslog_facility)) {
+ strncpy(save_name, prog_name, 64);
+ save_facility = syslog_facility;
+ openlog(save_name, LOG_PID, save_facility);
+ }
if ( ( log_fd && log_to_file )
&& ( log_fp != stdout )
@@ -310,7 +320,7 @@
if ( ( debug_fp != stdout ) && ( debug_fp != stderr )
&& ( log_fp != stdout ) && ( log_fp != stderr ) ) {
- fprintf ( stderr, "%s%s", msg, append );
+ fprintf ( stderr, "%s: %s%s", save_name, msg, append );
}
}
@@ -338,7 +348,7 @@
if ( ( debug_fp != stdout ) && ( debug_fp != stderr )
&& ( log_fp != stdout ) && ( log_fp != stderr ) ) {
- fprintf ( stderr, "%s%s", msg, append );
+ fprintf ( stderr, "%s: %s%s", save_name, msg, append );
}
exit( -1 );
@@ -353,8 +363,8 @@
exit ( -1 );
}
- snprintf ( mymsg, MAX_LOG_DEBUG_MSG_LEN, "%s: %s\n",
- msg, strerror ( errno ) );
+ snprintf ( mymsg, MAX_LOG_DEBUG_MSG_LEN, "%s: %s: %s\n",
+ save_name, msg, strerror ( errno ) );
die ( mymsg );
free ( mymsg );
Modified: trunk/src/tap.c
===================================================================
--- trunk/src/tap.c 2007-05-11 14:22:35 UTC (rev 28)
+++ trunk/src/tap.c 2007-05-11 16:26:07 UTC (rev 29)
@@ -191,7 +191,7 @@
if ( cc_apdu(dfheader) == 0) {
debug_5("Encoded addr(size): %p(%Zd)", dfheader->encoded_size, dfheader->encoded);
} else {
- debug_5("tap: cc_apdu returned nonzero");
+ debug_5("cc_apdu returned nonzero");
return;
}
@@ -295,7 +295,7 @@
Msg *ctrlmsg;
int controlfd = 0;
char df_control_port[8];
- char addrstr[MAX_LINE];
+ char addrstr[MAX_HOST];
void *ptr = NULL;
CtrlMsg *temp;
@@ -708,7 +708,7 @@
}
for (res = res0; res; res = res->ai_next) {
- if (inet_ntop (res->ai_family, res->ai_addr->sa_data, addrstr, MAX_LINE) == NULL) {
+ if (inet_ntop (res->ai_family, res->ai_addr->sa_data, addrstr, MAX_HOST) == NULL) {
pdie("inet_ntop");
}
@@ -717,11 +717,11 @@
ptr = &((struct sockaddr_in *) res->ai_addr)->sin_addr;
controlfd = Socket(res->ai_family, res->ai_socktype, res->ai_protocol);
if (controlfd == -1) {
- debug_3("tap: ipv4 control socket failure");
+ debug_3("ipv4 control socket failure");
break;
}
if (Connect(controlfd, res->ai_addr, res->ai_addrlen) == -1) {
- debug_3("tap: ipv4 control connect failure");
+ debug_3("ipv4 control connect failure");
Close(controlfd);
controlfd = -1;
break;
@@ -731,10 +731,10 @@
ptr = &((struct sockaddr_in6 *) res->ai_addr)->sin6_addr;
break;
}
- if (inet_ntop (res->ai_family, ptr, addrstr, MAX_LINE) == NULL) {
+ if (inet_ntop (res->ai_family, ptr, addrstr, MAX_HOST) == NULL) {
pdie("inet_ntop");
}
- debug_5 ("tap: df_control IPv%d address: %s (%s)",
+ debug_5 ("df_control IPv%d address: %s (%s)",
res->ai_family == PF_INET6 ? 6 : 4, addrstr, res->ai_canonname);
}
freeaddrinfo(res0);
@@ -746,14 +746,14 @@
temp->ctrlh.dfhost.port = htons(CF_CmII_PORT);
i = tcp_write(controlfd, ctrlmsg, sizeof(Msg) + sizeof(CtrlMsg));
tcp_read(controlfd, ctrlmsg, i);
- debug_3("tap: df_collector returned route[%d]", ntohs(ctrlmsg->msgh.routeid));
+ debug_3("df_collector returned route[%d]", ntohs(ctrlmsg->msgh.routeid));
dfheader->cmii_routeid = ntohs(ctrlmsg->msgh.routeid);
ctrlmsg->msgh.routeid = htons(-1);
temp->ctrlh.dfhost.port = htons(CF_CmC_PORT);
i = tcp_write(controlfd, ctrlmsg, i);
tcp_read(controlfd, ctrlmsg, i);
- debug_3("tap: df_collector returned route[%d]", ntohs(ctrlmsg->msgh.routeid));
+ debug_3("df_collector returned route[%d]", ntohs(ctrlmsg->msgh.routeid));
dfheader->cmc_routeid = ntohs(ctrlmsg->msgh.routeid);
free(ctrlmsg);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|