Update of /cvsroot/sysfence/sysfence
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32516
Modified Files:
Makefile log.c
Log Message:
+ stat logging comes back 8)
Index: log.c
===================================================================
RCS file: /cvsroot/sysfence/sysfence/log.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- log.c 23 May 2004 20:52:22 -0000 1.7
+++ log.c 26 May 2004 04:15:41 -0000 1.8
@@ -25,51 +25,58 @@
#include "conditions.h"
#include "log.h"
-#if 0
-char * stats2str (int *sta)
+#define BIGSTRBUF 1024
+
+char * stats_2_string (sf_list *hd)
{
- char *res = xalloc (NULL, LOGLINEBUF);
- char *tmp = xalloc (NULL, LOGVARBUF);
- int i;
+ char *gluebuf, *thisbuf, *nextbuf, *defbuf;
+ sf_value val;
- *res = '\0';
+ if (!hd) return NULL;
- for (i = 0; i < STA_LAST; i++) {
- if (*(sta + i) == 1) {
- switch (stat[i].type) {
- case DOUBLE:
- snprintf (tmp,
- LOGVARBUF - 1,
- "%s = %0.2f, ",
- stat[i].label,
- stat[i].val.dbl
- );
- break;
- case SIZE:
- snprintf (tmp,
- LOGVARBUF - 1,
- "%s = %li, ",
- stat[i].label,
- stat[i].val.siz
- );
- break;
- }
+ thisbuf = (char *) xalloc (NULL, STRBUF + 1);
+ defbuf = def_2_string ((sf_stat_def *) hd->el);
+#ifdef DEBUG
+ val = get_stat_value ((sf_stat_def *) hd->el, "stats_2_string()");
+#else
+ val = get_stat_value ((sf_stat_def *) hd->el);
+#endif
+#ifdef DEBUG
+ syslog (LOG_DEBUG,
+ "%s = type: %x, ptr: %x",
+ defbuf,
+ val.type,
+ (long int) val.ptr);
+ syslog (LOG_DEBUG,
+ "+-- val: %x",
+ *((long int *) val.ptr));
+#endif
+ nextbuf = stats_2_string (hd->next);
- strcat (res, tmp);
- }
+ switch (val.type) {
+ case INTEGER:
+ snprintf (thisbuf, STRBUF, "%s = %d", defbuf, *((long int *) val.ptr));
+ break;
+ case DOUBLE:
+ snprintf (thisbuf, STRBUF, "%s = %.2f", defbuf, *((double *) val.ptr));
+ break;
+ default:
+#ifdef DEBUG
+ syslog (LOG_DEBUG, "stats_2_string(): invalid val type: %d", val.type);
+#endif
+ break; // to avoid warnings
}
- free (tmp);
-
- tmp = res + strlen (res) - 1;
- while ((*tmp == ',') || (*tmp == ' ')) {
- *tmp = '\0';
- tmp --;
- }
+ free (defbuf);
- return res;
+ if (nextbuf) {
+ gluebuf = (char *) xalloc (NULL, BIGSTRBUF + 1);
+ snprintf (gluebuf, BIGSTRBUF, "%s, %s", thisbuf, nextbuf);
+ free (thisbuf);
+ free (nextbuf);
+ return gluebuf;
+ } else return thisbuf;
}
-#endif
void log_start (int rules)
{
@@ -82,51 +89,10 @@
void log_rulehit (sf_rule *rule)
{
-// char *stattxt = stats2str (&(rule->showstat[0]));
- char *stattxt = "stat logging temporarily disabled";
+ char *stattxt = stats_2_string (rule->watchstats);
- if (rule->name != NULL)
- syslog (LOG_WARNING,
- "%s: %s",
- rule->name,
- stattxt
- );
- else
- syslog (LOG_WARNING,
- "rule hit: %s",
- stattxt
- );
-
+ syslog (LOG_WARNING, "%s: %s", rule->name, stattxt);
free (stattxt);
-
- /*
- if (rule->name != NULL) {
- syslog (LOG_WARNING,
- "%s: %s=%0.2f %s=%0.2f %s=%0.2f, "
- "%s=%d %s=%d, %s=%d %s=%d",
- rule->name,
- stat[STA_LA1].label, stat[STA_LA1].val.dbl,
- stat[STA_LA5].label, stat[STA_LA5].val.dbl,
- stat[STA_LA15].label, stat[STA_LA15].val.dbl,
- stat[STA_MFREE].label, stat[STA_MFREE].val.siz,
- stat[STA_MUSED].label, stat[STA_MUSED].val.siz,
- stat[STA_SFREE].label, stat[STA_SFREE].val.siz,
- stat[STA_SUSED].label, stat[STA_SUSED].val.siz
- );
- } else {
- syslog (LOG_WARNING,
- "rule hit: %s=%0.2f %s=%0.2f %s=%0.2f, "
- "%s=%d %s=%d, %s=%d %s=%d",
- stat[STA_LA1].label, stat[STA_LA1].val.dbl,
- stat[STA_LA5].label, stat[STA_LA5].val.dbl,
- stat[STA_LA15].label, stat[STA_LA15].val.dbl,
- stat[STA_MFREE].label, stat[STA_MFREE].val.siz,
- stat[STA_MUSED].label, stat[STA_MUSED].val.siz,
- stat[STA_SFREE].label, stat[STA_SFREE].val.siz,
- stat[STA_SUSED].label, stat[STA_SUSED].val.siz
- );
- }
- */
}
void log_end ()
Index: Makefile
===================================================================
RCS file: /cvsroot/sysfence/sysfence/Makefile,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- Makefile 24 May 2004 22:21:21 -0000 1.20
+++ Makefile 26 May 2004 04:15:41 -0000 1.21
@@ -2,7 +2,7 @@
LDFLAGS=
CFLAGS=-Wall -O2
objects=exit.o conditions.o xalloc.o getstats.o mainloop.o log.o communication.o \
- sighandlers.o sysfence.o cp2memory.o processtitle.o
+ sighandlers.o sysfence.o cp2memory.o processtitle.o datastruct.o
parseopt=parseopt/{confread,lex,parse}.o
%.o: %.c
@@ -17,6 +17,7 @@
debug:
gcc -DDEBUG -ggdb -c exit.c -o exit.o
+ gcc -DDEBUG -ggdb -c datastruct.c -o datastruct.o
gcc -DDEBUG -ggdb -c conditions.c -o conditions.o
gcc -DDEBUG -ggdb -c xalloc.c -o xalloc.o
gcc -DDEBUG -ggdb -c getstats.c -o getstats.o
@@ -31,7 +32,7 @@
gcc -ggdb sysfence.o exit.o xalloc.o getstats.o conditions.o mainloop.o log.o \
communication.o sighandlers.o cp2memory.o \
parseopt/lex.o parseopt/parse.o parseopt/confread.o \
- processtitle.o -o sysfence
+ processtitle.o datastruct.o -o sysfence
clean:
make -C parseopt/ clean
rm -f *.o sysfence
|