From f4acd5a27e4d03124d8a6923e3d016863a38cbf6 Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Fri, 25 Sep 2009 16:44:31 +0200 Subject: [PATCH] First batch of fixes for new debug and logging API usage. --- src/alert-unified2-alert.c | 2 -- src/counters.c | 2 +- src/decode-ethernet.c | 5 ++--- src/decode-ipv6.c | 2 +- src/decode.c | 3 ++- src/eidps.c | 6 ++++++ src/flow.c | 20 +++++++++----------- src/util-debug.c | 1 + src/util-time.c | 13 +++++-------- 9 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/alert-unified2-alert.c b/src/alert-unified2-alert.c index 1f58096e43..8b2f0e3e46 100644 --- a/src/alert-unified2-alert.c +++ b/src/alert-unified2-alert.c @@ -17,8 +17,6 @@ #include "alert-unified2-alert.h" #include "decode-ipv4.h" -#define DEBUG - /*prototypes*/ int Unified2Alert (ThreadVars *, Packet *, void *, PacketQueue *); int Unified2AlertThreadInit(ThreadVars *, void *, void **); diff --git a/src/counters.c b/src/counters.c index ac8dc104bb..92efb345a0 100644 --- a/src/counters.c +++ b/src/counters.c @@ -1042,7 +1042,7 @@ int PerfOutputCounterFileIface() fprintf(perf_op_ctx->fp, "%-25s | %-25s | %-" PRIu64 "\n", pc->name->cname, pc->name->tm_name, *ui64_cvalue); #ifdef DEBUG - printf("%-10" PRIuMAX " %-10" PRIu16 " %-10s %-" PRIu64 "\n", pc->name->tid, pc->id, + printf("%-10" PRIuMAX " %-10" PRIu16 " %-10s %-" PRIu64 "\n", (uintmax_t)pc->name->tid, pc->id, pc->name->cname, *ui64_cvalue); #endif pc = pc->next; diff --git a/src/decode-ethernet.c b/src/decode-ethernet.c index 967e5871bf..439e0bbede 100644 --- a/src/decode-ethernet.c +++ b/src/decode-ethernet.c @@ -6,6 +6,7 @@ #include "decode-events.h" #include "util-unittest.h" +#include "util-debug.h" void DecodeEthernet(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt, uint16_t len, PacketQueue *pq) { @@ -20,9 +21,7 @@ void DecodeEthernet(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *p if (ethh == NULL) return; -#ifdef DEBUG - printf("DecodeEthernet: p %p pkt %p ether type %04x\n", p, pkt, ntohs(ethh->eth_type)); -#endif + SCDebug("p %p pkt %p ether type %04x", p, pkt, ntohs(ethh->eth_type)); if (ntohs(ethh->eth_type) == ETHERNET_TYPE_IP) { //printf("DecodeEthernet ip4\n"); diff --git a/src/decode-ipv6.c b/src/decode-ipv6.c index e7ba5dea7d..a1e02b1327 100644 --- a/src/decode-ipv6.c +++ b/src/decode-ipv6.c @@ -408,7 +408,7 @@ void DecodeIPV6(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt, #ifdef DEBUG if (IPV6_EXTHDR_ISSET_FH(p)) { printf("IPV6 FRAG - HDRLEN: %" PRIuMAX " NH: %" PRIu32 " OFFSET: %" PRIu32 " ID: %" PRIu32 "\n", - IPV6_EXTHDR_GET_FH_HDRLEN(p), IPV6_EXTHDR_GET_FH_NH(p), + (uintmax_t)IPV6_EXTHDR_GET_FH_HDRLEN(p), IPV6_EXTHDR_GET_FH_NH(p), IPV6_EXTHDR_GET_FH_OFFSET(p), IPV6_EXTHDR_GET_FH_ID(p)); } if (IPV6_EXTHDR_ISSET_RH(p)) { diff --git a/src/decode.c b/src/decode.c index fdd8d6a7e9..dd1fe9c0a9 100644 --- a/src/decode.c +++ b/src/decode.c @@ -4,6 +4,7 @@ #include "eidps-common.h" #include "decode.h" +#include "util-debug.h" void DecodeTunnel(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt, uint16_t len, PacketQueue *pq) { @@ -16,7 +17,7 @@ void DecodeTunnel(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt case IPPROTO_IPV6: return DecodeIPV6(tv, dtv, p, pkt, len, pq); default: - printf("FIXME: DecodeTunnel: protocol %" PRIu32 " not supported.\n", p->tunnel_proto); + SCInfo("FIXME: DecodeTunnel: protocol %" PRIu32 " not supported.", p->tunnel_proto); break; } } diff --git a/src/eidps.c b/src/eidps.c index abbbba615a..0f61efe2f7 100644 --- a/src/eidps.c +++ b/src/eidps.c @@ -71,6 +71,9 @@ #include "runmodes.h" #include "util-debug.h" +#include "util-debug.h" +#include "util-error.h" + /* * we put this here, because we only use it here in main. */ @@ -249,6 +252,9 @@ int main(int argc, char **argv) char *conf_filename = NULL; int dump_config = 0; + /* initialize the logging subsys */ + SCLogInitLogModule(NULL); + /* Initialize the configuration module. */ ConfInit(); diff --git a/src/flow.c b/src/flow.c index 9e9aa8e063..d2d6bb253a 100644 --- a/src/flow.c +++ b/src/flow.c @@ -9,7 +9,6 @@ */ #include "eidps-common.h" -#include "debug.h" #include "decode.h" #include "threads.h" #include "tm-modules.h" @@ -26,6 +25,8 @@ #include "flow-private.h" #include "util-unittest.h" +#include "util-debug.h" + //#define FLOW_DEFAULT_HASHSIZE 262144 #define FLOW_DEFAULT_HASHSIZE 65536 //#define FLOW_DEFAULT_MEMCAP 128 * 1024 * 1024 /* 128 MB */ @@ -170,8 +171,8 @@ static int FlowPrune (FlowQueue *q, struct timeval *ts) } } - DEBUGPRINT("got lock, now check: %" PRId64 "+%" PRIu32 "=(%" PRId64 ") < %" PRId64 "", f->lastts.tv_sec, - timeout, f->lastts.tv_sec + timeout, ts->tv_sec); + SCDebug("got lock, now check: %" PRIdMAX "+%" PRIu32 "=(%" PRIdMAX ") < %" PRIdMAX "", (intmax_t)f->lastts.tv_sec, + timeout, (intmax_t)f->lastts.tv_sec + timeout, (intmax_t)ts->tv_sec); /* do the timeout check */ if ((f->lastts.tv_sec + timeout) >= ts->tv_sec) { @@ -183,15 +184,12 @@ static int FlowPrune (FlowQueue *q, struct timeval *ts) /** never prune a flow that is used by a packet or stream msg * we are currently processing in one of the threads */ if (f->use_cnt > 0) { - printf("FlowPrune: timed out but use_cnt > 0: %"PRIu16", %p, proto %"PRIu8"\n", f->use_cnt, f, f->proto); + SCDebug("timed out but use_cnt > 0: %"PRIu16", %p, proto %"PRIu8"", f->use_cnt, f, f->proto); mutex_unlock(&f->fb->m); mutex_unlock(&f->m); return 0; } - //printf("timed out %" PRIuMAX "+%" PRIu32 "=(%" PRIuMAX ") < %" PRIuMAX ": %p, proto %"PRIu8"\n", (uintmax_t)f->lastts.tv_sec, - // timeout, (uintmax_t)(f->lastts.tv_sec + timeout), (uintmax_t)ts->tv_sec, f, f->proto); - /* remove from the hash */ if (f->hprev) f->hprev->hnext = f->hnext; @@ -515,7 +513,7 @@ void *FlowManagerThread(void *td) /* Get the time */ memset(&ts, 0, sizeof(ts)); TimeGet(&ts); - DEBUGPRINT("ts %" PRId64 "", ts.tv_sec); + SCDebug("ts %" PRIdMAX "", (intmax_t)ts.tv_sec); /* see if we still have enough spare flows */ FlowUpdateSpareFlows(); @@ -525,21 +523,21 @@ void *FlowManagerThread(void *td) /* prune closing list */ nowcnt = FlowPruneFlows(&flow_close_q[i], &ts); if (nowcnt) { - DEBUGPRINT("Pruned %" PRIu32 " closing flows...\n", nowcnt); + SCDebug("Pruned %" PRIu32 " closing flows...", nowcnt); closing_cnt += nowcnt; } /* prune new list */ nowcnt = FlowPruneFlows(&flow_new_q[i], &ts); if (nowcnt) { - DEBUGPRINT("Pruned %" PRIu32 " new flows...\n", nowcnt); + SCDebug("Pruned %" PRIu32 " new flows...", nowcnt); new_cnt += nowcnt; } /* prune established list */ nowcnt = FlowPruneFlows(&flow_est_q[i], &ts); if (nowcnt) { - DEBUGPRINT("Pruned %" PRIu32 " established flows...\n", nowcnt); + SCDebug("Pruned %" PRIu32 " established flows...", nowcnt); established_cnt += nowcnt; } } diff --git a/src/util-debug.c b/src/util-debug.c index e44ec84f8e..1c5f33ba45 100644 --- a/src/util-debug.c +++ b/src/util-debug.c @@ -146,6 +146,7 @@ static inline void SCLogPrintToStream(FILE *fd, char *msg) if (fprintf(fd, "%s", msg) < 0) printf("Error writing to stream using fprintf\n"); + fflush(fd); return; } diff --git a/src/util-time.c b/src/util-time.c index 46485ae9de..d55328880d 100644 --- a/src/util-time.c +++ b/src/util-time.c @@ -3,8 +3,7 @@ #include "eidps-common.h" #include "detect.h" #include "threads.h" - -//#define DEBUG +#include "util-debug.h" static struct timeval current_time = { 0,0 }; static pthread_mutex_t current_time_mutex = PTHREAD_MUTEX_INITIALIZER; @@ -12,10 +11,12 @@ static char live = TRUE; void TimeModeSetLive(void) { live = TRUE; + SCDebug("live time mode enabled"); } void TimeModeSetOffline (void) { live = FALSE; + SCDebug("offline time mode enabled"); } void TimeSet(struct timeval *tv) { @@ -29,10 +30,8 @@ void TimeSet(struct timeval *tv) { current_time.tv_sec = tv->tv_sec; current_time.tv_usec = tv->tv_usec; -#ifdef DEBUG - printf("TimeSet: time set to %" PRIuMAX " sec, %" PRIuMAX " usec\n", + SCDebug("time set to %" PRIuMAX " sec, %" PRIuMAX " usec", (uintmax_t)current_time.tv_sec, (uintmax_t)current_time.tv_usec); -#endif mutex_unlock(¤t_time_mutex); } @@ -50,9 +49,7 @@ void TimeGet(struct timeval *tv) { mutex_unlock(¤t_time_mutex); } -#ifdef DEBUG - printf("TimeGet: time we got is %" PRIuMAX " sec, %" PRIuMAX " usec\n", + SCDebug("time we got is %" PRIuMAX " sec, %" PRIuMAX " usec", (uintmax_t)tv->tv_sec, (uintmax_t)tv->tv_usec); -#endif }