sysfence-commit Mailing List for sysfence (Page 5)
Status: Alpha
Brought to you by:
emes
You can subscribe to this list here.
| 2004 |
Jan
|
Feb
|
Mar
(2) |
Apr
(3) |
May
(99) |
Jun
(45) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2005 |
Jan
(2) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2006 |
Jan
|
Feb
|
Mar
|
Apr
(5) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|
From: mkoperto <mko...@us...> - 2004-05-26 17:55:10
|
Update of /cvsroot/sysfence/sysfence/parseopt In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15603 Modified Files: confread.c lex.c parse.c parseopt.c Log Message: + changes in 'include' Index: confread.c =================================================================== RCS file: /cvsroot/sysfence/sysfence/parseopt/confread.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- confread.c 23 May 2004 20:52:23 -0000 1.5 +++ confread.c 26 May 2004 17:54:53 -0000 1.6 @@ -14,8 +14,8 @@ */ -#include "../exit.h" -#include "../xalloc.h" +#include "../sys/exit.h" +#include "../sys/xalloc.h" #include "lex.h" #include "../datastruct.h" #include "../getstats.h" Index: lex.c =================================================================== RCS file: /cvsroot/sysfence/sysfence/parseopt/lex.c,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- lex.c 10 May 2004 13:53:17 -0000 1.9 +++ lex.c 26 May 2004 17:54:53 -0000 1.10 @@ -14,7 +14,7 @@ */ -#include "../exit.h" +#include "../sys/exit.h" #include "lex.h" #include <stdio.h> #include <stdlib.h> Index: parse.c =================================================================== RCS file: /cvsroot/sysfence/sysfence/parseopt/parse.c,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- parse.c 26 May 2004 04:14:13 -0000 1.14 +++ parse.c 26 May 2004 17:54:53 -0000 1.15 @@ -15,8 +15,8 @@ */ #include "lex.h" -#include "../exit.h" -#include "../xalloc.h" +#include "../sys/exit.h" +#include "../sys/xalloc.h" #include "../datastruct.h" #include "../getstats.h" #include "../conditions.h" @@ -25,7 +25,7 @@ #include <stdlib.h> #ifdef DEBUG #include <syslog.h> -#include "../log.h" +#include "../sys/log.h" #endif #define ERRMSGBUF 128 Index: parseopt.c =================================================================== RCS file: /cvsroot/sysfence/sysfence/parseopt/parseopt.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- parseopt.c 5 Feb 2004 18:56:24 -0000 1.4 +++ parseopt.c 26 May 2004 17:54:53 -0000 1.5 @@ -15,7 +15,7 @@ /* $Id$ */ #include "parseopt.h" -#include "../exit.h" +#include "../sys/exit.h" #include <stdio.h> #include <stdlib.h> #include <string.h> |
|
From: mkoperto <mko...@us...> - 2004-05-26 17:52:23
|
Update of /cvsroot/sysfence/sysfence/doc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15073 Modified Files: example.conf Log Message: it was mistake Index: example.conf =================================================================== RCS file: /cvsroot/sysfence/sysfence/doc/example.conf,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- example.conf 26 May 2004 17:39:13 -0000 1.6 +++ example.conf 26 May 2004 17:52:13 -0000 1.7 @@ -14,6 +14,18 @@ # # Here is an example: # + +if { + la1 >= 5.0 and + { + { la5 > 3.0 and la5 < 5.0 } + or + { la15 > 2.0 and la15 < 5.0 } + } +} +run once 'echo "system load is high and still growing" | mail me...@em...' +log + # # Notice the 'once' keyword. You may use it right after 'run' or 'log'. # It means that run/log action will take place only once after condition @@ -34,6 +46,16 @@ # freeswap - free swap space # usedswap - used swap # + +when { + freemem < 128M + or + swapused > 256M +} invoke once 'echo "go buy some memory" | mail me...@em...' +log once +step 60 + +# # The 'step' keyword specifies time interval (in seconds) between rule # checks. Default is 10. # |
|
From: mkoperto <mko...@us...> - 2004-05-26 17:39:23
|
Update of /cvsroot/sysfence/sysfence In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12611 Modified Files: conditions.c datastruct.c getstats.c mainloop.c sysfence.c Removed Files: communication.c communication.h exit.c exit.h log.c log.h processtitle.c processtitle.h sighandlers.c sighandlers.h xalloc.c xalloc.h Log Message: files moved to sys/ --- processtitle.c DELETED --- --- communication.h DELETED --- Index: getstats.c =================================================================== RCS file: /cvsroot/sysfence/sysfence/getstats.c,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- getstats.c 26 May 2004 04:11:09 -0000 1.11 +++ getstats.c 26 May 2004 17:39:12 -0000 1.12 @@ -14,7 +14,7 @@ /* $Id$ */ -#include "exit.h" +#include "sys/exit.h" #include "parseopt/lex.h" #include "datastruct.h" #include "getstats.h" @@ -27,7 +27,7 @@ #ifdef DEBUG #include <syslog.h> -#include "log.h" +#include "sys/log.h" #endif sf_value get_stat_fs (sf_stat_def *def, sf_list *fslist) Index: conditions.c =================================================================== RCS file: /cvsroot/sysfence/sysfence/conditions.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- conditions.c 23 May 2004 20:52:15 -0000 1.5 +++ conditions.c 26 May 2004 17:39:12 -0000 1.6 @@ -14,7 +14,7 @@ */ #include <stdio.h> -#include "exit.h" +#include "sys/exit.h" #include "parseopt/lex.h" #include "datastruct.h" #include "getstats.h" --- communication.c DELETED --- --- processtitle.h DELETED --- Index: datastruct.c =================================================================== RCS file: /cvsroot/sysfence/sysfence/datastruct.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- datastruct.c 26 May 2004 04:07:13 -0000 1.1 +++ datastruct.c 26 May 2004 17:39:12 -0000 1.2 @@ -17,7 +17,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#include "xalloc.h" +#include "sys/xalloc.h" #include "parseopt/lex.h" #include "datastruct.h" #ifdef DEBUG --- xalloc.c DELETED --- Index: mainloop.c =================================================================== RCS file: /cvsroot/sysfence/sysfence/mainloop.c,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- mainloop.c 26 May 2004 04:12:49 -0000 1.11 +++ mainloop.c 26 May 2004 17:39:13 -0000 1.12 @@ -21,10 +21,10 @@ #include "datastruct.h" #include "getstats.h" #include "conditions.h" -#include "log.h" -#include "communication.h" +#include "sys/log.h" +#include "sys/communication.h" #include "mainloop.h" -#include "processtitle.h" +#include "sys/processtitle.h" int step = 10; Index: sysfence.c =================================================================== RCS file: /cvsroot/sysfence/sysfence/sysfence.c,v retrieving revision 1.18 retrieving revision 1.19 diff -u -d -r1.18 -r1.19 --- sysfence.c 26 May 2004 04:15:16 -0000 1.18 +++ sysfence.c 26 May 2004 17:39:13 -0000 1.19 @@ -21,8 +21,8 @@ #include <sys/wait.h> #include <assert.h> #include <syslog.h> -#include "xalloc.h" -#include "exit.h" +#include "sys/xalloc.h" +#include "sys/exit.h" #include "parseopt/lex.h" #include "datastruct.h" #include "getstats.h" @@ -30,11 +30,11 @@ #include "parseopt/parse.h" #include "parseopt/confread.h" #include "mainloop.h" -#include "log.h" -#include "communication.h" -#include "sighandlers.h" +#include "sys/log.h" +#include "sys/communication.h" +#include "sys/sighandlers.h" #include "cp2memory.h" -#include "processtitle.h" +#include "sys/processtitle.h" const char *usage = "sysfence v0.11, 01-03-2004\n" --- log.c DELETED --- --- sighandlers.c DELETED --- --- xalloc.h DELETED --- --- exit.h DELETED --- --- log.h DELETED --- --- exit.c DELETED --- --- sighandlers.h DELETED --- |
|
From: mkoperto <mko...@us...> - 2004-05-26 17:39:23
|
Update of /cvsroot/sysfence/sysfence/doc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12611/doc Modified Files: example.conf Log Message: files moved to sys/ Index: example.conf =================================================================== RCS file: /cvsroot/sysfence/sysfence/doc/example.conf,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- example.conf 27 Feb 2004 11:16:52 -0000 1.5 +++ example.conf 26 May 2004 17:39:13 -0000 1.6 @@ -14,18 +14,6 @@ # # Here is an example: # - -if { - la1 >= 5.0 and - { - { la5 > 3.0 and la5 < 5.0 } - or - { la15 > 2.0 and la15 < 5.0 } - } -} -run once 'echo "system load is high and still growing" | mail me...@em...' -log - # # Notice the 'once' keyword. You may use it right after 'run' or 'log'. # It means that run/log action will take place only once after condition @@ -46,16 +34,6 @@ # freeswap - free swap space # usedswap - used swap # - -when { - freemem < 128M - or - swapused > 256M -} invoke once 'echo "go buy some memory" | mail me...@em...' -log once -step 60 - -# # The 'step' keyword specifies time interval (in seconds) between rule # checks. Default is 10. # |
|
From: mkoperto <mko...@us...> - 2004-05-26 17:30:54
|
Update of /cvsroot/sysfence/sysfence/sys In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11212 Added Files: Makefile communication.c communication.h exit.c exit.h log.c log.h processtitle.c processtitle.h sighandlers.c sighandlers.h xalloc.c xalloc.h Log Message: moved to new directory --- NEW FILE: processtitle.c --- /* copyright (c) 2004, Mirek Kopertowski <m.k...@po...> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2 as published by the Free Software Foundation (see file COPYING for details). You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. The idea is taken from sendmail. */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <stdarg.h> #include "processtitle.h" #define SPT_BUFSIZE 2048 #define max(A,B) ((A) > (B) ? (A) : (B)) extern char **environ; static char **arg; static int arglength; char buf[SPT_BUFSIZE]; int auxtitlelength; void initproctitle (int argc, char **argv) { int i; char **envp = environ; /* determine the size of environ */ for (i = 0; envp[i] != NULL; i++); /* copy environ to new place */ environ = (char **) malloc(sizeof(char *) * (i + 1)); for (i = 0; envp[i] != NULL; i++) environ[i] = strdup(envp[i]); environ[i] = NULL; /* determine the available space */ arg = argv; if (i > 0) arglength = envp[i-1] + strlen(envp[i-1]) - argv[0]; else arglength = argv[argc-1] + strlen(argv[argc-1]) - argv[0]; /* auxiliary title length */ auxtitlelength = max (strlen (STATE_STOPPED_NAME), strlen (STATE_EXEC_NAME)) + 3; } void setproctitle (int process, int state, const char *rulename) { static int length; switch (process) { case MAIN_PROCESS: length = strlen (MAIN_PROCESS_NAME); /* do nothing if title too long */ if (length + 1 > SPT_BUFSIZE) return; sprintf (buf, "%s", MAIN_PROCESS_NAME); break; case RULE_PROCESS: if (!rulename) return; length = auxtitlelength + strlen(rulename); /* do nothing if title too long */ if (length + 1 > SPT_BUFSIZE) return; switch (state) { case STATE_NORMAL: sprintf (buf, "%s '%s'", RULE_PROCESS_NAME, rulename); break; case STATE_STOPPED: sprintf (buf, "%s %s '%s'", RULE_PROCESS_NAME, STATE_STOPPED_NAME, rulename); break; case STATE_EXEC: sprintf (buf, "%s %s '%s'", RULE_PROCESS_NAME, STATE_EXEC_NAME, rulename); break; default: return; } break; default: return; } /* cut title if too long */ if (length > arglength - 2) { length = arglength - 2; buf[length] = '\0'; } /* clear the memory area */ memset (arg[0], '\0', arglength); strcpy (arg[0], buf); /* only one arg */ arg[1] = NULL; } --- NEW FILE: communication.h --- /* copyright (c) 2004, Mirek Kopertowski <m.k...@po...> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2 as published by the Free Software Foundation (see file COPYING for details). You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #define SEMAPHORE_SET 1 #define SEMAPHORE_RESET 0 int semaphore_init (int val); int semaphore_op (int semid, int sem_op); int semaphore_del (int semid); #define semaphore_wait(S) semaphore_op (S, -1) #define semaphore_post(S) semaphore_op (S, 1) int shared_mem_init (int memsize); void *shared_mem_attach (int shmid); void shared_mem_detach (void *shm); void shared_mem_del (int shmid); --- NEW FILE: communication.c --- /* copyright (c) 2004, Mirek Kopertowski <m.k...@po...> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2 as published by the Free Software Foundation (see file COPYING for details). You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include <stdio.h> #include <sys/shm.h> #include <sys/stat.h> #include <sys/ipc.h> #include <sys/sem.h> #include <sys/types.h> union semun { int val; struct semid_ds *buf; unsigned short int *array; struct seminfo *__buf; }; int semaphore_op (int semid, int sem_op) { static struct sembuf operation[1]; operation[0].sem_num = 0; operation[0].sem_op = sem_op; operation[0].sem_flg = SEM_UNDO; return semop (semid, operation, 1); } int semaphore_init (int val) { int semid; union semun argument; unsigned short values[1]; /* create semaphore */ semid = semget (IPC_PRIVATE, 1, IPC_CREAT | IPC_EXCL | S_IRUSR | S_IWUSR); values[0] = val; argument.array = values; /* set semaphore value */ semctl (semid, 0, SETALL, argument); return semid; } int semaphore_del (int semid) { union semun ignored_argument; /* delete semaphore - last process */ return semctl (semid, 1, IPC_RMID, ignored_argument); } int shared_mem_init (int memsize) { /* allocate shared memory */ return shmget (IPC_PRIVATE, memsize, IPC_CREAT | IPC_EXCL | S_IRUSR | S_IWUSR); } void *shared_mem_attach (int shmid) { return shmat (shmid, NULL, 0); } void shared_mem_detach (void *shm) { shmdt (shm); } void shared_mem_del (int shmid) { shmctl (shmid, IPC_RMID, NULL); } --- NEW FILE: processtitle.h --- /* copyright (c) 2004, Mirek Kopertowski <m.k...@po...> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2 as published by the Free Software Foundation (see file COPYING for details). You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. The idea is taken from sendmail. */ #define STATE_NORMAL 0 #define STATE_EXEC 1 #define STATE_STOPPED 2 #define MAIN_PROCESS 1 #define RULE_PROCESS 2 #define MAIN_PROCESS_NAME "sffetch" #define RULE_PROCESS_NAME "sfwatch" #define STATE_EXEC_NAME "EXEC" #define STATE_STOPPED_NAME "STOPPED" void initproctitle (int argc, char **argv); void setproctitle (int process, int state, const char *rulename); --- NEW FILE: Makefile --- CC=gcc CFLAGS=-Wall -O2 all: $(CC) -c $(CFLAGS) exit.c -o exit.o $(CC) -c $(CFLAGS) log.c -o log.o $(CC) -c $(CFLAGS) xalloc.c -o xalloc.o $(CC) -c $(CFLAGS) communication.c -o communication.o $(CC) -c $(CFLAGS) processtitle.c -o processtitle.o $(CC) -c $(CFLAGS) sighandlers.c -o sighandlers.o debug: gcc -c -ggdb -DDEBUG exit.c -o exit.o gcc -c -ggdb -DDEBUG log.c -o log.o gcc -c -ggdb -DDEBUG xalloc.c -o xalloc.o gcc -c -ggdb -DDEBUG communication.c -o communication.o gcc -c -ggdb -DDEBUG processtitle.c -o processtitle.o gcc -c -ggdb -DDEBUG sighandlers.c -o sighandlers.o clean: rm -f *.o --- NEW FILE: log.c --- /* copyright (c) 2004, Michal Salaban <em...@pl...> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2 as published by the Free Software Foundation (see file COPYING for details). You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. $Id: log.c,v 1.1 2004/05/26 17:30:42 mkoperto Exp $ */ #include <stdio.h> #include <string.h> #include <stdlib.h> #include <syslog.h> #include "xalloc.h" #include "../parseopt/lex.h" #include "../datastruct.h" #include "../getstats.h" #include "../conditions.h" #include "log.h" #define BIGSTRBUF 1024 char * stats_2_string (sf_list *hd) { char *gluebuf, *thisbuf, *nextbuf, *defbuf; sf_value val; if (!hd) return NULL; 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); 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 (defbuf); if (nextbuf) { gluebuf = (char *) xalloc (NULL, BIGSTRBUF + 1); snprintf (gluebuf, BIGSTRBUF, "%s, %s", thisbuf, nextbuf); free (thisbuf); free (nextbuf); return gluebuf; } else return thisbuf; } void log_start (int rules) { openlog ("sysfence", LOG_NDELAY | LOG_PID | LOG_CONS, LOG_DAEMON); syslog (LOG_INFO, "loaded %d rules", rules); } void log_rulehit (sf_rule *rule) { char *stattxt = stats_2_string (rule->watchstats); syslog (LOG_WARNING, "%s: %s", rule->name, stattxt); free (stattxt); } void log_end () { syslog (LOG_INFO, "exiting"); closelog (); } /* $Id: log.c,v 1.1 2004/05/26 17:30:42 mkoperto Exp $ */ --- NEW FILE: exit.h --- /* copyright (c) 2004, Michal Salaban <em...@pl...> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2 as published by the Free Software Foundation (see file COPYING for details). You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. $Id: exit.h,v 1.1 2004/05/26 17:30:42 mkoperto Exp $ */ #include <stdio.h> #define EXIT_OK 0 #define EXIT_IO 1 #define EXIT_MEM 2 #define EXIT_NOCONF 11 #define EXIT_NORULE 12 #define EXIT_PARSE 21 #define EXIT_VALUE 22 #define EXIT_OPTION 23 #define EXIT_SHM 31 #define EXIT_SEM 32 #define EXIT_BUG 41 void bail_out (int excode, const char *details); /* $Id: exit.h,v 1.1 2004/05/26 17:30:42 mkoperto Exp $ */ --- NEW FILE: xalloc.c --- /* copyright (c) 2004, Michal Salaban <em...@pl...> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2 as published by the Free Software Foundation (see file COPYING for details). You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. $Id: xalloc.c,v 1.1 2004/05/26 17:30:42 mkoperto Exp $ */ #include <stdlib.h> #include <stdio.h> #include "exit.h" void * xalloc (void * ptr, size_t size) { void *res; res = (void *) realloc (ptr, size); if (!res) bail_out (EXIT_MEM, NULL); return res; } /* $Id: xalloc.c,v 1.1 2004/05/26 17:30:42 mkoperto Exp $ */ --- NEW FILE: sighandlers.c --- /* copyright (c) 2004, Mirek Kopertowski <m.k...@po...> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2 as published by the Free Software Foundation (see file COPYING for details). You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include <signal.h> #include <sys/types.h> #include <sys/wait.h> #include <string.h> #include <stdlib.h> #include "exit.h" #include "../parseopt/lex.h" #include "../datastruct.h" #include "../getstats.h" #include "../conditions.h" #include "../mainloop.h" #include "communication.h" #include "sighandlers.h" #include "processtitle.h" struct sigaction schildact, stermact, susr1act; void schild_action (int snumber); void sterm_action (int snumber); void susr1_action (int snumber); void signal_init (int process) { switch (process) { case PARENT: memset (&schildact, 0, sizeof(schildact)); schildact.sa_handler = &schild_action; sigaction (SIGCHLD, &schildact, NULL); memset (&stermact, 0, sizeof(stermact)); stermact.sa_handler = &sterm_action; sigaction (SIGTERM, &stermact, NULL); return; case CHILD: memset (&susr1act, 0, sizeof(susr1act)); susr1act.sa_handler = &susr1_action; sigaction (SIGCHLD, &susr1act, NULL); memset (&stermact, 0, sizeof(stermact)); stermact.sa_handler = SIG_DFL; sigaction (SIGTERM, &stermact, NULL); return; default: return; } } void signals (int onoff) { switch (onoff) { case SIGON: susr1act.sa_handler = &susr1_action; sigaction (SIGUSR1, &susr1act, NULL); stermact.sa_handler = SIG_DFL; sigaction (SIGTERM, &stermact, NULL); return; case SIGOFF: susr1act.sa_handler = SIG_IGN; sigaction (SIGUSR1, &susr1act, NULL); stermact.sa_handler = SIG_IGN; sigaction (SIGTERM, &stermact, NULL); return; default: return; } } /* local functions -----------------------------------------------------------*/ void schild_action (int snumber) { int exitstatus, pid, i=0; pid = (int)wait (&exitstatus); while (*(ruleprocesses + i)!=pid) i++; *(ruleprocesses + i) = 0; } void sterm_action (int snumber) { int i; /* deactive handling SIGCHLD */ memset (&schildact, 0, sizeof(schildact)); schildact.sa_handler = SIG_IGN; sigaction (SIGCHLD, &schildact, NULL); /* terminate child processes */ for (i=0; i<rulecount; i++) if (*(ruleprocesses + i)) kill ((pid_t)*(ruleprocesses + i), SIGTERM); /* detach, deallocate shared memory */ shared_mem_detach (db_shm); shared_mem_del (db_shmid); shared_mem_detach (fs_shm); shared_mem_del (fs_shmid); shared_mem_detach (proc_shm); shared_mem_del (proc_shmid); shared_mem_detach (rules_shm); shared_mem_del (rules_shmid); /* deallocate semaphore */ semaphore_del (semid); bail_out (EXIT_OK, NULL); } void susr1_action (int snumber) { //setproctitle (RULE_PROCESS, STATE_STOPPED, rule->name); raise (SIGSTOP); } --- NEW FILE: xalloc.h --- /* copyright (c) 2004, Michal Salaban <em...@pl...> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2 as published by the Free Software Foundation (see file COPYING for details). You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. $Id: xalloc.h,v 1.1 2004/05/26 17:30:42 mkoperto Exp $ */ void * xalloc (void * ptr, size_t size); /* $Id: xalloc.h,v 1.1 2004/05/26 17:30:42 mkoperto Exp $ */ --- NEW FILE: log.h --- /* copyright (c) 2004, Michal Salaban <em...@pl...> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2 as published by the Free Software Foundation (see file COPYING for details). You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. $Id: log.h,v 1.1 2004/05/26 17:30:42 mkoperto Exp $ */ #define LOGLINEBUF 256 #define LOGVARBUF 64 void log_start (int rules); void log_rulehit (sf_rule *rule); void log_end (); /* $Id: log.h,v 1.1 2004/05/26 17:30:42 mkoperto Exp $ */ --- NEW FILE: sighandlers.h --- /* copyright (c) 2004, Mirek Kopertowski <m.k...@po...> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2 as published by the Free Software Foundation (see file COPYING for details). You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #define PARENT 0 #define CHILD 1 #define SIGON 0 #define SIGOFF 1 void signal_init (); void signals (int onoff); --- NEW FILE: exit.c --- /* copyright (c) 2004, Michal Salaban <em...@pl...> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2 as published by the Free Software Foundation (see file COPYING for details). You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. $Id: exit.c,v 1.1 2004/05/26 17:30:42 mkoperto Exp $ */ #include "exit.h" #include <stdio.h> #include <stdlib.h> #include <syslog.h> char *errormessage[] = { [EXIT_IO] = "I/O error on %s", [EXIT_MEM] = "Out of memory", [EXIT_NOCONF] = "No configuration given", [EXIT_NORULE] = "No rules given", [EXIT_PARSE] = "Parse error: %s", [EXIT_VALUE] = "Invalid value: %s", [EXIT_OPTION] = "Invalid option: %s", [EXIT_SHM] = "Shared memory exists", [EXIT_SEM] = "Semaphore exists", [EXIT_BUG] = "Internal bug" }; extern char *usage; void bail_out (int excode, const char *details) { #ifdef DEBUG fprintf (stderr, "bail_out() exit code %d\n", excode); #endif if (excode == EXIT_OK) exit (EXIT_OK); if (details != NULL) fprintf (stderr, errormessage[excode], details); else fprintf (stderr, errormessage[excode]); fprintf (stderr, "\n"); if ((excode == EXIT_NOCONF) || (excode == EXIT_VALUE) || (excode == EXIT_OPTION)) fprintf (stderr, usage); if (excode == EXIT_BUG) syslog (LOG_DEBUG, "%s %s", errormessage[excode], details); exit (excode); } /* $Id: exit.c,v 1.1 2004/05/26 17:30:42 mkoperto Exp $ */ |
|
From: mkoperto <mko...@us...> - 2004-05-26 17:23:01
|
Update of /cvsroot/sysfence/sysfence/sys In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9570/sys Log Message: Directory /cvsroot/sysfence/sysfence/sys added to the repository |
|
From: mkoperto <mko...@us...> - 2004-05-26 17:21:04
|
Update of /cvsroot/sysfence/sysfence In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8721 Modified Files: Makefile Log Message: + new files structure Index: Makefile =================================================================== RCS file: /cvsroot/sysfence/sysfence/Makefile,v retrieving revision 1.21 retrieving revision 1.22 diff -u -d -r1.21 -r1.22 --- Makefile 26 May 2004 04:15:41 -0000 1.21 +++ Makefile 26 May 2004 17:20:52 -0000 1.22 @@ -1,40 +1,39 @@ CC=gcc 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 datastruct.o +objects=conditions.o getstats.o mainloop.o cp2memory.o datastruct.o sysfence.o parseopt=parseopt/{confread,lex,parse}.o +sys=sys/{exit,xalloc,log,communication,sighandlers,processtitle}.o %.o: %.c $(CC) -c $(CFLAGS) $< -o $@ sysfence: $(objects) make -C parseopt/ all - $(CC) $(CFLAGS) $(LDFLAGS) -o sysfence $(objects) $(parseopt) + make -C sys/ all + $(CC) $(CFLAGS) $(LDFLAGS) -o sysfence $(objects) $(parseopt) $(sys) strip sysfence all: sysfence 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 + gcc -DDEBUG -ggdb -c datastruct.c -o datasruct.o make -C parseopt/ debug + make -C sys/ debug gcc -DDEBUG -ggdb -c mainloop.c -o mainloop.o - gcc -DDEBUG -ggdb -c log.c -o log.o - gcc -DDEBUG -ggdb -c communication.c -o communication.o - gcc -DDEBUG -ggdb -c sighandlers.c -o sighandlers.o gcc -DDEBUG -ggdb -c cp2memory.c -o cp2memory.o - gcc -DDEBUG -ggdb -c processtitle.c -o processtitle.o gcc -DDEBUG -ggdb -c sysfence.c -o sysfence.o - gcc -ggdb sysfence.o exit.o xalloc.o getstats.o conditions.o mainloop.o log.o \ - communication.o sighandlers.o cp2memory.o \ + gcc -ggdb sysfence.o getstats.o conditions.o mainloop.o \ + cp2memory.o datastuct.o \ parseopt/lex.o parseopt/parse.o parseopt/confread.o \ - processtitle.o datastruct.o -o sysfence + sys/exit.o sys/xalloc.o sys/log.o \ + sys/communication.o sys/sighandlers.o sys/processtitle.o \ + -o sysfence clean: make -C parseopt/ clean + make -C sys/ clean rm -f *.o sysfence install: install -d $(DESTDIR)$(PREFIX)/bin |
|
From: Michal S. <em...@us...> - 2004-05-26 04:17:39
|
Update of /cvsroot/sysfence/sysfence In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32748 Modified Files: CREDITS Log Message: + i'm not alone! :)) Index: CREDITS =================================================================== RCS file: /cvsroot/sysfence/sysfence/CREDITS,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- CREDITS 1 Mar 2004 17:56:02 -0000 1.1 +++ CREDITS 26 May 2004 04:17:29 -0000 1.2 @@ -1,9 +1,10 @@ Author: - Michal Salaban <em...@pl...> + Michal Salaban <emes /at/ pld-linux.org> + Mirek Kopertowski <m.kopertowski /at/ post.pl> Contributors: - Juha Ulkoniemi <jul...@ma...> + Juha Ulkoniemi <julkonie /at/ mail.student.oulu.fi> - cleaned up the code, reduced gcc warnings, wrote new Makefile |
|
From: Michal S. <em...@us...> - 2004-05-26 04:16:07
|
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 |
|
From: Michal S. <em...@us...> - 2004-05-26 04:15:28
|
Update of /cvsroot/sysfence/sysfence In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32374 Modified Files: sysfence.c Log Message: + some debug info Index: sysfence.c =================================================================== RCS file: /cvsroot/sysfence/sysfence/sysfence.c,v retrieving revision 1.17 retrieving revision 1.18 diff -u -d -r1.17 -r1.18 --- sysfence.c 24 May 2004 22:23:05 -0000 1.17 +++ sysfence.c 26 May 2004 04:15:16 -0000 1.18 @@ -20,6 +20,7 @@ #include <sys/types.h> #include <sys/wait.h> #include <assert.h> +#include <syslog.h> #include "xalloc.h" #include "exit.h" #include "parseopt/lex.h" @@ -92,6 +93,9 @@ if (db_shmid < 0) bail_out (EXIT_SHM, NULL); db_shm = shared_mem_attach (db_shmid); main_db = (sf_database *) db_shm; +#ifdef DEBUG + syslog (LOG_DEBUG, "main_db created @ %x", main_db); +#endif /* initialize shared memory for fs database */ fs_shmid = shared_mem_init (FS_DATA_SIZE); |
|
From: Michal S. <em...@us...> - 2004-05-26 04:14:23
|
Update of /cvsroot/sysfence/sysfence/parseopt In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32209/parseopt Modified Files: parse.c Log Message: + collect_stats() comes back Index: parse.c =================================================================== RCS file: /cvsroot/sysfence/sysfence/parseopt/parse.c,v retrieving revision 1.13 retrieving revision 1.14 diff -u -d -r1.13 -r1.14 --- parse.c 23 May 2004 20:52:23 -0000 1.13 +++ parse.c 26 May 2004 04:14:13 -0000 1.14 @@ -23,6 +23,10 @@ #include "parse.h" #include <stdio.h> #include <stdlib.h> +#ifdef DEBUG +#include <syslog.h> +#include "../log.h" +#endif #define ERRMSGBUF 128 @@ -56,18 +60,20 @@ bail_out (EXIT_PARSE, buf); } -#if 0 -void collect_stats (expression *ex, int *tab) +void collect_stats (sf_expression *ex, sf_list **statlist) { - if (ex->type == ATOMIC) { - *(tab + ((atomic *) ex->arg1)->val_id) = 1; - } else { - collect_stats ((expression *) ex->arg1, tab); - collect_stats ((expression *) ex->arg2, tab); - } -} + sf_atomic *atmp = (sf_atomic *) ex->arg1; + +#ifdef DEBUG + syslog (LOG_DEBUG, "collect_stats (%x, %x)", ex, statlist); #endif + if (ex->type == RELATION) { + collect_stats ((sf_expression *) ex->arg1, statlist); + collect_stats ((sf_expression *) ex->arg2, statlist); + } else add_def_to_list (statlist, &atmp->stat); +} + parserdata * get_logdata (tokdata *tok) { /* grammar: @@ -430,6 +436,7 @@ rlst->log = NULL; rlst->hit = 0; rlst->prevhit = 0; + rlst->watchstats = NULL; /* ruleset begins with IF */ if (tok->type != KW_IF) @@ -505,7 +512,7 @@ rlst->step = *((unsigned int *) tmp->parsed); /* search expression tree for used stats */ -// collect_stats (rlst->expr, &(rlst->showstat[0])); + collect_stats (rlst->expr, &(rlst->watchstats)); /* ok, now we got full ruleset structure. * we need only to skip to next token. |
|
From: Michal S. <em...@us...> - 2004-05-26 04:12:59
|
Update of /cvsroot/sysfence/sysfence In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31935 Modified Files: mainloop.c Log Message: + logging requires access to shared data. use semaphore Index: mainloop.c =================================================================== RCS file: /cvsroot/sysfence/sysfence/mainloop.c,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- mainloop.c 24 May 2004 22:25:16 -0000 1.10 +++ mainloop.c 26 May 2004 04:12:49 -0000 1.11 @@ -46,7 +46,9 @@ /* first - log if neccessary */ if (rule->log != NULL) { if (! (rule->log->once && rule->prevhit)) { + semaphore_wait (semid); log_rulehit (rule); + semaphore_post (semid); #ifdef DEBUG printf ("rule logged\n"); #endif |
|
From: Michal S. <em...@us...> - 2004-05-26 04:11:19
|
Update of /cvsroot/sysfence/sysfence In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31696 Modified Files: getstats.c getstats.h Log Message: * get_stat_value() now uses pointer as argument Index: getstats.h =================================================================== RCS file: /cvsroot/sysfence/sysfence/getstats.h,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- getstats.h 23 May 2004 20:52:22 -0000 1.7 +++ getstats.h 26 May 2004 04:11:09 -0000 1.8 @@ -25,7 +25,7 @@ sf_database *main_db; -sf_value get_stat_value (sf_stat_def def); +sf_value get_stat_value (sf_stat_def *def); void stat_init (sf_database *db); void fetch_la (sf_database *db); Index: getstats.c =================================================================== RCS file: /cvsroot/sysfence/sysfence/getstats.c,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- getstats.c 23 May 2004 20:52:22 -0000 1.10 +++ getstats.c 26 May 2004 04:11:09 -0000 1.11 @@ -25,7 +25,12 @@ #include <string.h> #include <sys/vfs.h> -sf_value get_stat_fs (sf_stat_def def, sf_list *fslist) +#ifdef DEBUG +#include <syslog.h> +#include "log.h" +#endif + +sf_value get_stat_fs (sf_stat_def *def, sf_list *fslist) { sf_value res; @@ -33,7 +38,7 @@ return res; } -sf_value get_stat_proc (sf_stat_def def, void *proctab) +sf_value get_stat_proc (sf_stat_def *def, void *proctab) { sf_value res; @@ -41,12 +46,16 @@ return res; } -sf_value get_stat_value (sf_stat_def def) +sf_value get_stat_value (sf_stat_def *def) { sf_value res; - sf_res_state selector = def.arg[0].resstat; + sf_res_state selector = def->arg[0].resstat; - switch (def.label) { +#ifdef DEBUG + syslog (LOG_DEBUG, "get_stat_value(%s) called from %s", def_2_string(def), caller); +#endif + + switch (def->label) { case ST_PROC: res = get_stat_proc (def, main_db->proc); break; @@ -63,7 +72,7 @@ break; case ST_LOAD: res.type = DOUBLE; - switch (def.arg[0].laminutes) { + switch (def->arg[0].laminutes) { case 1: res.ptr = (void *) &(main_db->load[0]); break; @@ -164,7 +173,7 @@ db->mem[VA_FREE], db->mem[VA_USED], db->swap[VA_FREE], - db->swap[VA_USED], + db->swap[VA_USED] ); #endif } |
|
From: Michal S. <em...@us...> - 2004-05-26 04:08:28
|
Update of /cvsroot/sysfence/sysfence In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31147 Modified Files: exit.c Log Message: + bugs are reported to syslog Index: exit.c =================================================================== RCS file: /cvsroot/sysfence/sysfence/exit.c,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- exit.c 23 May 2004 20:52:22 -0000 1.6 +++ exit.c 26 May 2004 04:08:18 -0000 1.7 @@ -17,6 +17,7 @@ #include "exit.h" #include <stdio.h> #include <stdlib.h> +#include <syslog.h> char *errormessage[] = { @@ -55,6 +56,8 @@ (excode == EXIT_VALUE) || (excode == EXIT_OPTION)) fprintf (stderr, usage); + if (excode == EXIT_BUG) + syslog (LOG_DEBUG, "%s %s", errormessage[excode], details); exit (excode); } |
|
From: Michal S. <em...@us...> - 2004-05-26 04:07:23
|
Update of /cvsroot/sysfence/sysfence In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30999 Modified Files: datastruct.h Added Files: datastruct.c Log Message: + added functions that work on sf_* structures Index: datastruct.h =================================================================== RCS file: /cvsroot/sysfence/sysfence/datastruct.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- datastruct.h 23 May 2004 20:53:01 -0000 1.1 +++ datastruct.h 26 May 2004 04:07:13 -0000 1.2 @@ -14,14 +14,31 @@ */ +/*************************************************************************** + * * + * BIG RED WARNING! * + * * + * Changing anything? * + * Be sure that functions in... * + * datastruct.c * + * cp2memory.c * + * ...will work properly! * + * * + * Other source files may also require adjustment :( * + * * + ***************************************************************************/ + #include <sys/types.h> -#define STAT_MAX_ARGS 2 +#define STRBUF 256 -#define PROC_RUN 1 -#define PROC_SLEEP 2 -#define PROC_STOP 4 -#define PROC_ZOMBIE 8 +#define STAT_MAX_ARGS 2 + +#define PROC_RUN 1 +#define PROC_SLEEP 2 +#define PROC_STOP 4 +#define PROC_ZOMBIE 8 +#define PROC_ANY 15 /*************************************************************************** All-purpose list @@ -137,6 +154,9 @@ // indicate if expression was true after this check and previous one int hit, prevhit; + // All stats that are watched by this rule, organized in list + // (for fast logging) + sf_list *watchstats; } sf_rule; /*************************************************************************** @@ -158,4 +178,13 @@ void *proc; // NIY } sf_database; +/*************************************************************************** + Helper functions operating on sf_* structures + ***************************************************************************/ + +void add_def_to_list (sf_list **hd, sf_stat_def *def); +int equal_defs (sf_stat_def *d1, sf_stat_def *d2); +int uid_in_list (sf_list *hd, uid_t uid); +char * def_2_string (sf_stat_def *def); + /* $Id$ */ --- NEW FILE: datastruct.c --- /* copyright (c) 2004, Michal Salaban <em...@pl...> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2 as published by the Free Software Foundation (see file COPYING for details). You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. $Id: datastruct.c,v 1.1 2004/05/26 04:07:13 emes Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include "xalloc.h" #include "parseopt/lex.h" #include "datastruct.h" #ifdef DEBUG #include <syslog.h> #endif void add_def_to_list (sf_list **hd, sf_stat_def *def) { /* adds stat def to list, discarding duplicates */ #ifdef DEBUG syslog (LOG_DEBUG, "adding def: %s @ %x", def_2_string (def), *hd); #endif if (! *hd) { /* this is tail */ sf_list *new = (sf_list *) xalloc (NULL, sizeof (sf_list)); new->elsize = sizeof (sf_stat_def); new->el = (void *) def; new->next = NULL; *hd = new; } else { /* this is existing entry */ sf_stat_def *cur = (sf_stat_def *) (*hd)->el; /* if we're carrying a duplicate, drop it */ if (equal_defs (def, cur)) return; else add_def_to_list (&(*hd)->next, def); } } int uid_in_list (sf_list *hd, uid_t uid) { /* checks if uid is in the list */ if (!hd) return 0; if (*((uid_t *)hd->el) != uid) return 0; return uid_in_list (hd->next, uid); } int equal_uid_lists (sf_list *l1, sf_list *l2) { /* * This function works in 2 * |l1| * |l2| time * but is used during parsing process and for short lists (usually) * so, there is no need to code it better. am i right? ;> */ sf_list *lp1 = l1, *lp2 = l2; while (lp1) { if (! uid_in_list (l2, *((uid_t *)lp1->el))) return 0; lp1 = lp1->next; } while (lp2) { if (! uid_in_list (l1, *((uid_t *)lp2->el))) return 0; lp2 = lp2->next; } return 1; } int equal_defs (sf_stat_def *d1, sf_stat_def *d2) { /* checks if two defs describe the same stat */ #ifdef DEBUG syslog (LOG_DEBUG, "checking [%s] == [%s]", def_2_string (d1), def_2_string (d2) ); #endif if (d1->label != d2->label) return 0; switch (d1->label) { case ST_LOAD: return (d1->arg[0].laminutes == d2->arg[0].laminutes); case ST_MEM: case ST_SWAP: return (d1->arg[0].resstat == d2->arg[0].resstat); case ST_FS: return ((d1->arg[0].resstat == d2->arg[0].resstat) && strcmp (d1->arg[1].path, d2->arg[1].path)); case ST_PROC: return ((d1->arg[1].procstates == d2->arg[1].procstates) && equal_uid_lists (d1->arg[0].uids, d2->arg[0].uids)); default: return 1; } } char * res_state_2_string (sf_res_state sta) { switch (sta) { case VA_USED: return "used"; case VA_FREE: return "free"; case VA_AVAIL: return "available"; default: return ""; } } char * def_2_string (sf_stat_def *def) { char *buf = (char *) xalloc (NULL, STRBUF + 1); *buf = '\0'; switch (def->label) { case ST_LOAD: snprintf (buf, STRBUF, "loadavg(%d)", def->arg[0].laminutes ); break; case ST_MEM: snprintf (buf, STRBUF, "%s memory", res_state_2_string (def->arg[0].resstat) ); break; case ST_SWAP: snprintf (buf, STRBUF, "%s swap", res_state_2_string (def->arg[0].resstat) ); break; case ST_FS: snprintf (buf, STRBUF, "%s space in %s", res_state_2_string (def->arg[0].resstat), def->arg[1].path ); break; case ST_PROC: snprintf (buf, STRBUF, "nproc (uid: %s) (state: %s)", "NIY", "NIY" ); default: break; // to avoid warnings } return buf; } |
|
From: Michal S. <em...@us...> - 2004-05-26 04:06:34
|
Update of /cvsroot/sysfence/sysfence In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30928 Modified Files: cp2memory.c Log Message: * nasty bug fixed Index: cp2memory.c =================================================================== RCS file: /cvsroot/sysfence/sysfence/cp2memory.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- cp2memory.c 23 May 2004 20:52:22 -0000 1.2 +++ cp2memory.c 26 May 2004 04:06:26 -0000 1.3 @@ -137,10 +137,12 @@ /* copy list node */ l = (sf_list *) *buf; memcpy (*buf, (void *) list, sizeof (sf_list)); + *buf += sizeof (sf_list); /* copy element linked to node */ l->el = *buf; memcpy (*buf, list->el, list->elsize); + *buf += list->elsize; /* copy list tail */ l->next = (sf_list *) cp_list (buf, list->next); @@ -276,6 +278,10 @@ /* copy logdata */ if (r->log) r->log = (sf_logdata *) cp_logdata (buf, rule->log); + + /* copy watched stats list */ + if (r->watchstats) + r->watchstats = (sf_list *) cp_list (buf, rule->watchstats); return (void *)r; } |
|
From: mkoperto <mko...@us...> - 2004-05-24 22:30:31
|
Update of /cvsroot/sysfence/sysfence In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5351 Added Files: processtitle.h Log Message: you can change process title... --- NEW FILE: processtitle.h --- /* copyright (c) 2004, Mirek Kopertowski <m.k...@po...> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2 as published by the Free Software Foundation (see file COPYING for details). You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. The idea is taken from sendmail. */ #define STATE_NORMAL 0 #define STATE_EXEC 1 #define STATE_STOPPED 2 #define MAIN_PROCESS 1 #define RULE_PROCESS 2 #define MAIN_PROCESS_NAME "sffetch" #define RULE_PROCESS_NAME "sfwatch" #define STATE_EXEC_NAME "EXEC" #define STATE_STOPPED_NAME "STOPPED" void initproctitle (int argc, char **argv); void setproctitle (int process, int state, const char *rulename); |
|
From: mkoperto <mko...@us...> - 2004-05-24 22:28:35
|
Update of /cvsroot/sysfence/sysfence In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4761 Added Files: processtitle.c Log Message: you can change process title.... --- NEW FILE: processtitle.c --- /* copyright (c) 2004, Mirek Kopertowski <m.k...@po...> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2 as published by the Free Software Foundation (see file COPYING for details). You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. The idea is taken from sendmail. */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <stdarg.h> #include "processtitle.h" #define SPT_BUFSIZE 2048 #define max(A,B) ((A) > (B) ? (A) : (B)) extern char **environ; static char **arg; static int arglength; char buf[SPT_BUFSIZE]; int auxtitlelength; void initproctitle (int argc, char **argv) { int i; char **envp = environ; /* determine the size of environ */ for (i = 0; envp[i] != NULL; i++); /* copy environ to new place */ environ = (char **) malloc(sizeof(char *) * (i + 1)); for (i = 0; envp[i] != NULL; i++) environ[i] = strdup(envp[i]); environ[i] = NULL; /* determine the available space */ arg = argv; if (i > 0) arglength = envp[i-1] + strlen(envp[i-1]) - argv[0]; else arglength = argv[argc-1] + strlen(argv[argc-1]) - argv[0]; /* auxiliary title length */ auxtitlelength = max (strlen (STATE_STOPPED_NAME), strlen (STATE_EXEC_NAME)) + 3; } void setproctitle (int process, int state, const char *rulename) { static int length; switch (process) { case MAIN_PROCESS: length = strlen (MAIN_PROCESS_NAME); /* do nothing if title too long */ if (length + 1 > SPT_BUFSIZE) return; sprintf (buf, "%s", MAIN_PROCESS_NAME); break; case RULE_PROCESS: if (!rulename) return; length = auxtitlelength + strlen(rulename); /* do nothing if title too long */ if (length + 1 > SPT_BUFSIZE) return; switch (state) { case STATE_NORMAL: sprintf (buf, "%s %s", RULE_PROCESS_NAME, rulename); break; case STATE_STOPPED: sprintf (buf, "%s %s %s", RULE_PROCESS_NAME, STATE_STOPPED_NAME, rulename); break; case STATE_EXEC: sprintf (buf, "%s %s %s", RULE_PROCESS_NAME, STATE_EXEC_NAME, rulename); break; default: return; } break; default: return; } /* cut title if too long */ if (length > arglength - 2) { length = arglength - 2; buf[length] = '\0'; } /* clear the memory area */ memset (arg[0], '\0', arglength); strcpy (arg[0], buf); /* only one arg */ arg[1] = NULL; } |
|
From: mkoperto <mko...@us...> - 2004-05-24 22:25:26
|
Update of /cvsroot/sysfence/sysfence In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4438 Modified Files: mainloop.c Log Message: + processes titles Index: mainloop.c =================================================================== RCS file: /cvsroot/sysfence/sysfence/mainloop.c,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- mainloop.c 23 May 2004 20:52:22 -0000 1.9 +++ mainloop.c 24 May 2004 22:25:16 -0000 1.10 @@ -24,6 +24,7 @@ #include "log.h" #include "communication.h" #include "mainloop.h" +#include "processtitle.h" int step = 10; @@ -33,7 +34,7 @@ /* save result of this and previous hit */ rule->prevhit = rule->hit; - /* set semaphore while checking data */ + /* set semaphore while checking data */ semaphore_wait (semid); rule->hit = check_expression (rule->expr); semaphore_post (semid); @@ -55,7 +56,9 @@ /* second - run command */ if (rule->run != NULL) { if (! (rule->run->once && rule->prevhit)) { + setproctitle (RULE_PROCESS, STATE_EXEC, rule->name); system (rule->run->command); + setproctitle (RULE_PROCESS, STATE_NORMAL, rule->name); #ifdef DEBUG printf ("executed '%s'\n", rule->run->command); #endif |
|
From: mkoperto <mko...@us...> - 2004-05-24 22:23:17
|
Update of /cvsroot/sysfence/sysfence In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3923 Modified Files: sysfence.c Log Message: + process titles Index: sysfence.c =================================================================== RCS file: /cvsroot/sysfence/sysfence/sysfence.c,v retrieving revision 1.16 retrieving revision 1.17 diff -u -d -r1.16 -r1.17 --- sysfence.c 23 May 2004 20:52:22 -0000 1.16 +++ sysfence.c 24 May 2004 22:23:05 -0000 1.17 @@ -33,6 +33,7 @@ #include "communication.h" #include "sighandlers.h" #include "cp2memory.h" +#include "processtitle.h" const char *usage = "sysfence v0.11, 01-03-2004\n" @@ -134,6 +135,10 @@ /* child */ if (pid == 0) { + /* process title */ + initproctitle (argc, argv); + setproctitle (RULE_PROCESS, STATE_NORMAL, (*(shmruletab + i))->name); + /* one child process one ruleset */ rule_watch_loop (*(shmruletab + i)); } else /* parent */ @@ -141,6 +146,10 @@ /* start handling signals */ signal_init (); + /* process title */ + initproctitle (argc, argv); + setproctitle (MAIN_PROCESS, 0, NULL); + /* parent goes into data-providing loop */ res_probe_loop (main_db); } |
|
From: mkoperto <mko...@us...> - 2004-05-24 22:21:35
|
Update of /cvsroot/sysfence/sysfence In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3735 Modified Files: Makefile Log Message: + module processtitle Index: Makefile =================================================================== RCS file: /cvsroot/sysfence/sysfence/Makefile,v retrieving revision 1.19 retrieving revision 1.20 diff -u -d -r1.19 -r1.20 --- Makefile 20 May 2004 14:27:58 -0000 1.19 +++ Makefile 24 May 2004 22:21:21 -0000 1.20 @@ -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 + sighandlers.o sysfence.o cp2memory.o processtitle.o parseopt=parseopt/{confread,lex,parse}.o %.o: %.c @@ -26,11 +26,12 @@ gcc -DDEBUG -ggdb -c communication.c -o communication.o gcc -DDEBUG -ggdb -c sighandlers.c -o sighandlers.o gcc -DDEBUG -ggdb -c cp2memory.c -o cp2memory.o + gcc -DDEBUG -ggdb -c processtitle.c -o processtitle.o gcc -DDEBUG -ggdb -c sysfence.c -o sysfence.o 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 \ - -o sysfence + processtitle.o -o sysfence clean: make -C parseopt/ clean rm -f *.o sysfence |
|
From: Michal S. <em...@us...> - 2004-05-23 20:54:28
|
Update of /cvsroot/sysfence/sysfence/doc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14951/doc Added Files: data_structures.dia Log Message: + description of new data structures --- NEW FILE: data_structures.dia --- <?xml version="1.0" encoding="UTF-8"?> <dia:diagram xmlns:dia="http://www.lysator.liu.se/~alla/dia/"> <dia:diagramdata> <dia:attribute name="background"> <dia:color val="#ffffff"/> </dia:attribute> <dia:attribute name="pagebreak"> <dia:color val="#000099"/> </dia:attribute> <dia:attribute name="paper"> <dia:composite type="paper"> <dia:attribute name="name"> <dia:string>#A4#</dia:string> </dia:attribute> <dia:attribute name="tmargin"> <dia:real val="2.8222"/> </dia:attribute> <dia:attribute name="bmargin"> <dia:real val="2.8222"/> [...3971 lines suppressed...] </dia:attribute> <dia:attribute name="visibility"> <dia:enum val="3"/> </dia:attribute> <dia:attribute name="abstract"> <dia:boolean val="false"/> </dia:attribute> <dia:attribute name="class_scope"> <dia:boolean val="false"/> </dia:attribute> </dia:composite> </dia:attribute> <dia:attribute name="operations"/> <dia:attribute name="template"> <dia:boolean val="false"/> </dia:attribute> <dia:attribute name="templates"/> </dia:object> </dia:layer> </dia:diagram> |
|
From: Michal S. <em...@us...> - 2004-05-23 20:53:12
|
Update of /cvsroot/sysfence/sysfence In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14695 Added Files: datastruct.h Log Message: + new data structures, (almost) all in one file --- NEW FILE: datastruct.h --- /* copyright (c) 2004, Michal Salaban <em...@pl...> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2 as published by the Free Software Foundation (see file COPYING for details). You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. $Id: datastruct.h,v 1.1 2004/05/23 20:53:01 emes Exp $ */ #include <sys/types.h> #define STAT_MAX_ARGS 2 #define PROC_RUN 1 #define PROC_SLEEP 2 #define PROC_STOP 4 #define PROC_ZOMBIE 8 /*************************************************************************** All-purpose list ***************************************************************************/ typedef struct _sf_list { int elsize; void *el; struct _sf_list *next; } sf_list; /*************************************************************************** Stats ***************************************************************************/ typedef enum { // Label describing stat type ST_LOAD, ST_MEM, ST_SWAP, ST_FS, ST_PROC, ST_NONE } sf_stat_label; typedef enum { // Label describing data type (used with void* pointers) DOUBLE, INTEGER, PERCENT } sf_type; typedef enum { // Selector of value associated with resource VA_USED, VA_FREE, VA_AVAIL, VA_TOTAL, VA_LAST } sf_res_state; typedef union { // Selector or option describing stat int laminutes; // load sf_res_state resstat; // resources int procstates; // processes sf_list *uids; // processes char *path; // filesystem } sf_stat_arg; typedef struct { // Stat definition sf_stat_label label; sf_stat_arg arg[ STAT_MAX_ARGS ]; } sf_stat_def; typedef struct { // Value with known type sf_type type; void *ptr; } sf_value; typedef struct { // Full stat (definition and value) sf_stat_def stat; sf_value val; } sf_stat_value; /*************************************************************************** Rules ***************************************************************************/ typedef struct { // Node (relation) of an expression enum { RELATION, ATOMIC } type; void *arg1; void *arg2; token op; } sf_expression; typedef struct { // Atomic relation (between stat and threshold) sf_stat_def stat; sf_value thresh; token op; } sf_atomic; typedef struct { // Command to be run int once; char *command; } sf_rundata; typedef struct { // Log action int once; } sf_logdata; typedef struct { // One rule char *name; sf_expression *expr; sf_rundata *run; sf_logdata *log; unsigned int step; // indicate if expression was true after this check and previous one int hit, prevhit; } sf_rule; /*************************************************************************** Stat values database ***************************************************************************/ typedef struct { // Statistics of underlying filesystem in path char *path; long int val[ VA_LAST ]; } sf_fs_stats; typedef struct { // Main statistics database double load[3]; long int mem[ VA_LAST ]; long int swap[ VA_LAST ]; sf_list *fs; void *proc; // NIY } sf_database; /* $Id: datastruct.h,v 1.1 2004/05/23 20:53:01 emes Exp $ */ |
|
From: Michal S. <em...@us...> - 2004-05-23 20:52:38
|
Update of /cvsroot/sysfence/sysfence In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14456 Modified Files: conditions.c conditions.h cp2memory.c cp2memory.h exit.c exit.h getstats.c getstats.h log.c log.h mainloop.c mainloop.h sighandlers.c sysfence.c Log Message: * general redesign: moving to new, extensible data structures stat values logging is temporarily disabled Index: conditions.h =================================================================== RCS file: /cvsroot/sysfence/sysfence/conditions.h,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- conditions.h 27 Feb 2004 11:16:07 -0000 1.8 +++ conditions.h 23 May 2004 20:52:22 -0000 1.9 @@ -17,54 +17,11 @@ #define DEFAULTSTEP 10 -typedef struct { - enum { - RELATION, - ATOMIC - } type; - - void *arg1; - void *arg2; - token op; -} expression; - -typedef struct { - vartype type; - int val_id; - void *thresh; - token op; -} atomic; - -typedef struct { - int once; - char *runcmd; -} rundata; - -typedef struct { - int once; -} logdata; - -typedef struct { - char *name; - expression *expr; - rundata *run; - logdata *log; - unsigned int step; - - // indicate if expression was true after this check and previous one - int hit, - prevhit; - - // bool vector that shows which stats are used within this rule. - // used by logging functions to report only important values - int showstat[STA_LAST]; -} ruleset; - /* * Functions */ -int check_atomic (atomic *at); -int check_expression (expression *ex); +int check_atomic (sf_atomic *at); +int check_expression (sf_expression *ex); /* $Id$ */ Index: getstats.c =================================================================== RCS file: /cvsroot/sysfence/sysfence/getstats.c,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- getstats.c 20 May 2004 14:36:12 -0000 1.9 +++ getstats.c 23 May 2004 20:52:22 -0000 1.10 @@ -15,6 +15,8 @@ /* $Id$ */ #include "exit.h" +#include "parseopt/lex.h" +#include "datastruct.h" #include "getstats.h" #include <stdio.h> #include <stdlib.h> @@ -23,27 +25,72 @@ #include <string.h> #include <sys/vfs.h> -const char *lafile = "/proc/loadavg"; -int lafha; -const char *memfile = "/proc/meminfo"; -int memfha; +sf_value get_stat_fs (sf_stat_def def, sf_list *fslist) +{ + sf_value res; -char fbuf[ BUFSIZE ]; + bail_out (EXIT_BUG, "get_stat_fs(): NIY"); + return res; +} +sf_value get_stat_proc (sf_stat_def def, void *proctab) +{ + sf_value res; + + bail_out (EXIT_BUG, "get_stat_proc(): NIY"); + return res; +} -void stat_init (statval *stat) +sf_value get_stat_value (sf_stat_def def) { - strcpy (stat[STA_LA1].label, "la1"); stat[STA_LA1].type = DOUBLE; stat[STA_LA1].val.dbl = 0.0; - strcpy (stat[STA_LA5].label, "la5"); stat[STA_LA5].type = DOUBLE; stat[STA_LA5].val.dbl = 0.0; - strcpy (stat[STA_LA15].label, "la15"); stat[STA_LA15].type = DOUBLE; stat[STA_LA15].val.dbl = 0.0; + sf_value res; + sf_res_state selector = def.arg[0].resstat; - strcpy (stat[STA_MFREE].label, "memfree"); stat[STA_MFREE].type = SIZE; stat[STA_MFREE].val.siz = 0; - strcpy (stat[STA_MUSED].label, "memused"); stat[STA_MUSED].type = SIZE; stat[STA_MUSED].val.siz = 0; - strcpy (stat[STA_SFREE].label, "swapfree"); stat[STA_SFREE].type = SIZE; stat[STA_SFREE].val.siz = 0; - strcpy (stat[STA_SUSED].label, "swapused"); stat[STA_SUSED].type = SIZE; stat[STA_SUSED].val.siz = 0; + switch (def.label) { + case ST_PROC: + res = get_stat_proc (def, main_db->proc); + break; + case ST_FS: + res = get_stat_fs (def, main_db->fs); + break; + case ST_MEM: + res.type = INTEGER; + res.ptr = (void *) &(main_db->mem[selector]); + break; + case ST_SWAP: + res.type = INTEGER; + res.ptr = (void *) &(main_db->swap[selector]); + break; + case ST_LOAD: + res.type = DOUBLE; + switch (def.arg[0].laminutes) { + case 1: + res.ptr = (void *) &(main_db->load[0]); + break; + case 5: + res.ptr = (void *) &(main_db->load[1]); + break; + case 15: + res.ptr = (void *) &(main_db->load[2]); + break; + default: + bail_out (EXIT_BUG, "get_stat_value(): invalid minutes for LA"); + } + break; + default: + bail_out (EXIT_BUG, "get_stat_value(): invalid stat family"); + } + return res; } -void fetch_la () +const char *lafile = "/proc/loadavg"; +int lafha; +const char *memfile = "/proc/meminfo"; +int memfha; + +char fbuf[ BUFSIZE ]; + +void fetch_la (sf_database *db) { char *one, *two, *three; @@ -54,17 +101,17 @@ two = index (one, ' ') + 1; three = index (two, ' ') + 1; - stat[STA_LA1].val.dbl = atof (one); - stat[STA_LA5].val.dbl = atof (two); - stat[STA_LA15].val.dbl = atof (three); + db->load[0] = atof (one); + db->load[1] = atof (two); + db->load[2] = atof (three); #ifdef DEBUG printf ("fetch_la(): la1=%0.2f la5=%0.2f la15=%0.2f\n", - stat[STA_LA1], stat[STA_LA5], stat[STA_LA15]); + db->load[0], db->load[1], db->load[2]); #endif } -void fetch_mem () +void fetch_mem (sf_database *db) { char *ptr; long int vmtot, vmused, vmbuf, vmcache; @@ -93,65 +140,90 @@ ptr = fto_notspace (fto_space (ptr)); vmcache = atol (ptr); - /* 5. next line, swap values. first is 'Swap:', then total. - * next one is swap-used */ - ptr = fto_notspace (fto_space ( - fto_notspace (fto_space ( - fto_newline (ptr) - )) - )); - stat[STA_SUSED].val.siz = atol (ptr); - /* 6. swap-free */ + /* 5. next line, swap values. first is 'Swap:', then total. */ + ptr = fto_notspace (fto_space (fto_newline (ptr))); + db->swap[VA_TOTAL] = atol (ptr); + + /* 6. next one is swap-used */ ptr = fto_notspace (fto_space (ptr)); - stat[STA_SFREE].val.siz = atol (ptr); + db->swap[VA_USED] = atol (ptr); + + /* 7. swap-free */ + ptr = fto_notspace (fto_space (ptr)); + db->swap[VA_FREE] = atol (ptr); + db->swap[VA_AVAIL] = db->swap[VA_FREE]; /* calculate real values, i.e. substract buffers and cache size */ - stat[STA_MUSED].val.siz = vmused - (vmbuf + vmcache); - stat[STA_MFREE].val.siz = vmtot - stat[STA_MUSED].val.siz; + db->mem[VA_TOTAL] = vmtot; + db->mem[VA_USED] = vmused - (vmbuf + vmcache); + db->mem[VA_FREE] = vmtot - db->mem[VA_USED]; + db->mem[VA_AVAIL] = db->mem[VA_FREE]; #ifdef DEBUG printf ("fetch_mem(): memfree=%d memused=%d swapfree=%d swapused=%d\n", - stat[STA_MFREE].val.siz, - stat[STA_MUSED].val.siz, - stat[STA_SFREE].val.siz, - stat[STA_SUSED].val.siz + db->mem[VA_FREE], + db->mem[VA_USED], + db->swap[VA_FREE], + db->swap[VA_USED], ); #endif } -void open_files () -{ - lafha = open (lafile, O_RDONLY); - if (lafha < 0) bail_out (EXIT_IO, lafile); - - memfha = open (memfile, O_RDONLY); - if (memfha < 0) bail_out (EXIT_IO, memfile); -} - -void fetch_pathspace(pathspaceval *pathspace) +void fetch_pathspace (sf_fs_stats *fs) { - struct statfs buf; - long int bsizeKB; + struct statfs buf; + long int bsizeKB; - statfs(pathspace->path, &buf); + statfs (fs->path, &buf); /* block size in KB */ bsizeKB = buf.f_bsize / 1024; - pathspace->total = buf.f_blocks * bsizeKB; - pathspace->free = buf.f_bavail * bsizeKB; - pathspace->used = (buf.f_blocks - buf.f_bfree) * bsizeKB; + fs->val[VA_TOTAL] = buf.f_blocks * bsizeKB; + fs->val[VA_AVAIL] = buf.f_bavail * bsizeKB; + fs->val[VA_FREE] = buf.f_bfree * bsizeKB; + fs->val[VA_USED] = (buf.f_blocks - buf.f_bfree) * bsizeKB; #ifdef DEBUG - printf ("fetch_pathspace(): path %s total=%d used=%d free=%d\n", - pathspace->path, - pathspace->total, - pathspace->used, - pathspace->free + printf ("fetch_pathspace(): path %s total=%d used=%d free=%d available=%d\n", + fs->path, + fs->val[VA_TOTAL], + fs->val[VA_USED], + fs->val[VA_FREE], + fs->val[VA_AVAIL] ); #endif } +void fetch_fs (sf_database *db) +{ + sf_list *hd = db->fs; + sf_fs_stats *fs; + + // Iterate through list of watched paths + while (hd) { + fs = (sf_fs_stats *) hd->el; + if (fs) + fetch_pathspace (fs); + hd = hd->next; + } +} + +void fetch_proc (sf_database *db) +{ + return; +} + + +void open_files () +{ + lafha = open (lafile, O_RDONLY); + if (lafha < 0) bail_out (EXIT_IO, lafile); + + memfha = open (memfile, O_RDONLY); + if (memfha < 0) bail_out (EXIT_IO, memfile); +} + /* fast text parsing helpers */ char * fto_newline (char *b) Index: mainloop.h =================================================================== RCS file: /cvsroot/sysfence/sysfence/mainloop.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- mainloop.h 20 May 2004 14:39:43 -0000 1.3 +++ mainloop.h 23 May 2004 20:52:22 -0000 1.4 @@ -15,11 +15,11 @@ /* $Id$ */ int semid; -int shmid; +int rule_shmid; int *ruleprocesses; int rulecount; -void rule_watch_loop (ruleset *rule); -void res_probe_loop (); +void rule_watch_loop (sf_rule *rule); +void res_probe_loop (sf_database *db); /* $Id$ */ Index: cp2memory.c =================================================================== RCS file: /cvsroot/sysfence/sysfence/cp2memory.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- cp2memory.c 20 May 2004 14:47:53 -0000 1.1 +++ cp2memory.c 23 May 2004 20:52:22 -0000 1.2 @@ -13,61 +13,104 @@ */ #include <string.h> #include "parseopt/lex.h" -#include "getstats.h" -#include "conditions.h" +#include "datastruct.h" +#include "cp2memory.h" -int get_expression_size (expression *expr) +int get_data_size (sf_type label) { - int size=0; - atomic *a; + switch (label) { + case INTEGER: + return sizeof (long int); + case DOUBLE: + case PERCENT: + return sizeof (double); + } + return 0; +} - switch (expr->type) { - case ATOMIC: - a = (atomic *)expr->arg1; - if (a->type == DOUBLE) { - size += sizeof(double); - } else { - size += sizeof(long int); - } +int get_list_size (sf_list *list) +{ + int size = sizeof (sf_list); + + if (! list) return 0; - size += sizeof (atomic); - size += sizeof (expression); + size += list->elsize; + size += get_list_size (list->next); - return size ; - case RELATION: - /* copy expression */ - size += get_expression_size ((expression *)expr->arg1); - size += get_expression_size ((expression *)expr->arg2); - size += sizeof (expression); + return size; +} - return size; +int get_atomic_size (sf_atomic *atomic) +{ + int size = sizeof (sf_atomic); + + switch (atomic->stat.label) { + case ST_LOAD: + // arg[0] is integer in {1, 5, 15} + // arg[1] is ignored + size += sizeof (int); + break; + case ST_MEM: + case ST_SWAP: + // arg[0] is sf_res_state + // arg[1] is ignored + size += sizeof (sf_res_state); + break; + case ST_FS: + // arg[0] is sf_res_state + // arg[1] is path + size += sizeof (sf_res_state); + size += strlen (atomic->stat.arg[1].path); + break; + case ST_PROC: + // arg[0] is UID list + // arg[1] is state mask + size += get_list_size (atomic->stat.arg[0].uids); + size += sizeof (int); + break; default: - return 0; - } + break; + + } + return size; } -int get_rundata_size (rundata *run) +int get_expression_size (sf_expression *expr) { - int size=0; + int size = sizeof (sf_expression); - size += sizeof (rundata); - if (run->runcmd) - size += (int)strlen (run->runcmd) + 1; + switch (expr->type) { + case ATOMIC: + size += get_atomic_size ((sf_atomic *)expr->arg1); + break; + case RELATION: + size += get_expression_size ((sf_expression *)expr->arg1); + size += get_expression_size ((sf_expression *)expr->arg2); + break; + } + return size; +} + +int get_rundata_size (sf_rundata *run) +{ + int size = sizeof (sf_rundata); + + if (run->command) + size += (int)strlen (run->command) + 1; return size; } -int get_logdata_size (logdata *log) +int get_logdata_size (sf_logdata *log) { - return sizeof (logdata); + return sizeof (sf_logdata); } -int get_rule_size (ruleset *rule) +int get_rule_size (sf_rule *rule) { - int size=0; + int size = sizeof (sf_rule); - size += sizeof (ruleset); if (rule->name) size += (int)strlen (rule->name) + 1; @@ -85,48 +128,89 @@ return size; } -void *cp_expression (void **buf, expression *expr) +void *cp_list (void **buf, sf_list *list) { - void *b1, *b2; - atomic *a; - expression *e; + sf_list *l; - b1 = *buf; + if (! list) return NULL; + + /* copy list node */ + l = (sf_list *) *buf; + memcpy (*buf, (void *) list, sizeof (sf_list)); + + /* copy element linked to node */ + l->el = *buf; + memcpy (*buf, list->el, list->elsize); + + /* copy list tail */ + l->next = (sf_list *) cp_list (buf, list->next); + + return (void *) l; +} + +void *cp_atomic (void **buf, sf_atomic *atomic) +{ + sf_atomic *a; + int ds; + + a = (sf_atomic *) *buf; + memcpy (*buf, (void *) atomic, sizeof (sf_atomic)); + *buf += sizeof (sf_atomic); + + switch (atomic->stat.label) { + // Copy variable-size data from sf_stat_def + case ST_FS: + // arg[1] is pathname + a->stat.arg[1].path = (char *) *buf; + strcpy (*buf, atomic->stat.arg[1].path); + *buf += strlen (atomic->stat.arg[1].path) + 1; + break; + case ST_PROC: + // arg[0] is UID list + a->stat.arg[0].uids = (sf_list *) cp_list (buf, a->stat.arg[0].uids); + break; + default: + break; + } + + /* copy threshold */ + ds = get_data_size (atomic->thresh.type); + memcpy (*buf, (void *) atomic->thresh.ptr, ds); + buf += ds; + + return a; +} + + +void *cp_expression (void **buf, sf_expression *expr) +{ + void *b1, *b2; + sf_atomic *a = (sf_atomic *) expr->arg1; + sf_expression *e; switch (expr->type) { case ATOMIC: - /* copy thresh */ - a = (atomic *)expr->arg1; - if (a->type == DOUBLE) { - memcpy (*buf, (void *)a->thresh, sizeof (double)); - *buf += sizeof(double); - } else { - memcpy (*buf, (void *)a->thresh, sizeof (long int)); - *buf += sizeof(long int); - } - /* copy atomic */ - memcpy (*buf, (void *)a, sizeof(atomic)); - a = (atomic *) *buf; - a->thresh = b1; - *buf += sizeof (atomic); + a = (sf_atomic *) cp_atomic (buf, a); - /* copy expression */ - memcpy (*buf, (void *)expr, sizeof(expression)); - e = (expression *) *buf; - e->arg1 = (void *)a; - *buf += sizeof (expression); + /* copy expression itself */ + memcpy (*buf, (void *)expr, sizeof(sf_expression)); + e = (sf_expression *) *buf; + e->arg1 = (void *) a; + *buf += sizeof (sf_expression); return (void *)e ; case RELATION: - /* copy expression */ - b1 = cp_expression (buf, (expression *)expr->arg1); - b2 = cp_expression (buf, (expression *)expr->arg2); - memcpy (*buf, (void *)expr, sizeof (expression)); - e = (expression *) *buf; + /* copy child expressions */ + b1 = cp_expression (buf, (sf_expression *)expr->arg1); + b2 = cp_expression (buf, (sf_expression *)expr->arg2); + + /* copy expression itself */ + memcpy (*buf, (void *)expr, sizeof (sf_expression)); + e = (sf_expression *) *buf; e->arg1 = b1; e->arg2 = b2; - *buf += sizeof (expression); + *buf += sizeof (sf_expression); return (void *)e; default: @@ -134,48 +218,48 @@ } } -void *cp_rundata (void **buf, rundata *run) +void *cp_rundata (void **buf, sf_rundata *run) { - rundata *r; + sf_rundata *r; /* copy rundata */ - memcpy (*buf, (void *)run, sizeof (rundata)); - r = (rundata *) *buf; - *buf += sizeof (rundata); + memcpy (*buf, (void *)run, sizeof (sf_rundata)); + r = (sf_rundata *) *buf; + *buf += sizeof (sf_rundata); - /* copy runcmd */ - if (run->runcmd) { - strcpy (*buf, run->runcmd); - r->runcmd = (char *) *buf; - *buf += (int)strlen (run->runcmd) + 1; + /* copy command */ + if (run->command) { + strcpy (*buf, run->command); + r->command = (char *) *buf; + *buf += (int)strlen (run->command) + 1; } return (void *)r; } -void *cp_logdata (void **buf, logdata *log) +void *cp_logdata (void **buf, sf_logdata *log) { void *b; /* copy logdata */ - memcpy (*buf, (void *)log, sizeof (logdata)); + memcpy (*buf, (void *)log, sizeof (sf_logdata)); b = *buf; - *buf += sizeof (logdata); + *buf += sizeof (sf_logdata); return b; } -void *cp_rule (void **buf, ruleset *rule) +void *cp_rule (void **buf, sf_rule *rule) { - ruleset *r; + sf_rule *r; /* copy rule */ - memcpy (*buf, (void *)rule, sizeof (ruleset)); - r = (ruleset *) *buf; - *buf += sizeof (ruleset); + memcpy (*buf, (void *)rule, sizeof (sf_rule)); + r = (sf_rule *) *buf; + *buf += sizeof (sf_rule); - /* copy name*/ + /* copy name */ if (rule->name) { strcpy (*buf, rule->name); r->name = (char *) *buf; @@ -183,15 +267,19 @@ } /* copy expression */ - r->expr = (expression *) cp_expression (buf, rule->expr); + r->expr = (sf_expression *) cp_expression (buf, rule->expr); /* copy rundata */ if (r->run) - r->run = (rundata *) cp_rundata (buf, rule->run); + r->run = (sf_rundata *) cp_rundata (buf, rule->run); /* copy logdata */ if (r->log) - r->log = (logdata *) cp_logdata (buf, rule->log); + r->log = (sf_logdata *) cp_logdata (buf, rule->log); return (void *)r; } + +/* + $Id$ +*/ Index: getstats.h =================================================================== RCS file: /cvsroot/sysfence/sysfence/getstats.h,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- getstats.h 20 May 2004 14:34:33 -0000 1.6 +++ getstats.h 23 May 2004 20:52:22 -0000 1.7 @@ -16,49 +16,25 @@ #define BUFSIZE 512 -#define STA_LA1 0 -#define STA_LA5 1 -#define STA_LA15 2 -#define STA_MFREE 3 -#define STA_MUSED 4 -#define STA_SFREE 5 -#define STA_SUSED 6 -#define STA_LAST 7 - -typedef enum { - DOUBLE, - SIZE -} vartype; - -#define MAX_LABEL 10 - -typedef struct { - char label[MAX_LABEL]; - vartype type; +#define FS_DATA_SIZE 32768 // 32k +#define PROC_DATA_SIZE 524288 // 512k - union { - double dbl; - long int siz; - } val; - -} statval; +/* shared memory segments */ +int db_shmid, fs_shmid, proc_shmid, rules_shmid; +void *db_shm, *fs_shm, *proc_shm, *rules_shm; -typedef struct { - char *path; - long int total, used, free; - -} pathspaceval; +sf_database *main_db; -statval *stat; +sf_value get_stat_value (sf_stat_def def); -void stat_init (statval *stat); +void stat_init (sf_database *db); +void fetch_la (sf_database *db); +void fetch_mem (sf_database *db); +void fetch_fs (sf_database *db); +void fetch_proc (sf_database *db); -void fetch_la (); -void fetch_mem (); void open_files (); -void fetch_pathspace(pathspaceval *pathspace); - char * fto_newline (char *b); char * fto_notspace (char *b); char * fto_space (char *b); Index: conditions.c =================================================================== RCS file: /cvsroot/sysfence/sysfence/conditions.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- conditions.c 26 Feb 2004 20:11:09 -0000 1.4 +++ conditions.c 23 May 2004 20:52:15 -0000 1.5 @@ -14,7 +14,9 @@ */ #include <stdio.h> +#include "exit.h" #include "parseopt/lex.h" +#include "datastruct.h" #include "getstats.h" #include "conditions.h" @@ -50,43 +52,47 @@ } } -int check_atomic (atomic *at) +int check_atomic (sf_atomic *at) { - double dv = stat[at->val_id].val.dbl, - *dt = (double *) at->thresh; - long int iv = stat[at->val_id].val.siz, - *it = (long int *) at->thresh; + sf_value val = get_stat_value (at->stat); + double dv = *((double *) val.ptr), + dt = *((double *) at->thresh.ptr); + long int iv = *((long int *) val.ptr), + it = *((long int *) at->thresh.ptr); + + if (at->thresh.type != val.type) bail_out (EXIT_BUG, "check_atomic(): type mismatch!"); - switch (at->type) { + switch (at->thresh.type) { case DOUBLE: return ordcmp ( - (dv < *dt), - (dv == *dt), - (dv > *dt), + (dv < dt), + (dv == dt), + (dv > dt), at->op ); - case SIZE: + case INTEGER: return ordcmp ( - (iv < *it), - (iv == *it), - (iv > *it), + (iv < it), + (iv == it), + (iv > it), at->op ); default: - return 0; + bail_out (EXIT_BUG, " check_atomic(): used type that is not implemented yet"); + return 0; // to avoid warnings } } -int check_expression (expression *ex) +int check_expression (sf_expression *ex) { switch (ex->type) { case ATOMIC: - return check_atomic ((atomic *) ex->arg1); + return check_atomic ((sf_atomic *) ex->arg1); case RELATION: return logcmp ( - check_expression ((expression *) ex->arg1), + check_expression ((sf_expression *) ex->arg1), ex->op, - check_expression ((expression *) ex->arg2) + check_expression ((sf_expression *) ex->arg2) ); default: return 0; Index: cp2memory.h =================================================================== RCS file: /cvsroot/sysfence/sysfence/cp2memory.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- cp2memory.h 20 May 2004 14:48:59 -0000 1.1 +++ cp2memory.h 23 May 2004 20:52:22 -0000 1.2 @@ -12,5 +12,7 @@ */ -int get_rule_size (ruleset *rule); -void *cp_rule (void **buf, ruleset *rule); +int get_list_size (sf_list *list); +int get_rule_size (sf_rule *rule); +void *cp_list (void **buf, sf_list *list); +void *cp_rule (void **buf, sf_rule *rule); Index: mainloop.c =================================================================== RCS file: /cvsroot/sysfence/sysfence/mainloop.c,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- mainloop.c 20 May 2004 14:37:37 -0000 1.8 +++ mainloop.c 23 May 2004 20:52:22 -0000 1.9 @@ -18,6 +18,7 @@ #include <stdlib.h> #include <unistd.h> #include "parseopt/lex.h" +#include "datastruct.h" #include "getstats.h" #include "conditions.h" #include "log.h" @@ -26,7 +27,7 @@ int step = 10; -void rule_watch_loop (ruleset *rule) +void rule_watch_loop (sf_rule *rule) { while (1) { /* save result of this and previous hit */ @@ -54,9 +55,9 @@ /* second - run command */ if (rule->run != NULL) { if (! (rule->run->once && rule->prevhit)) { - system (rule->run->runcmd); + system (rule->run->command); #ifdef DEBUG - printf ("executed '%s'\n", rule->run->runcmd); + printf ("executed '%s'\n", rule->run->command); #endif } } @@ -71,14 +72,15 @@ } -void res_probe_loop () +void res_probe_loop (sf_database *db) { while (1) { /* set semaphore while changing data */ semaphore_wait (semid); - fetch_la (); - fetch_mem (); + fetch_la (db); + fetch_mem (db); + fetch_fs (db); semaphore_post (semid); sleep (step); Index: sysfence.c =================================================================== RCS file: /cvsroot/sysfence/sysfence/sysfence.c,v retrieving revision 1.15 retrieving revision 1.16 diff -u -d -r1.15 -r1.16 --- sysfence.c 22 May 2004 16:45:08 -0000 1.15 +++ sysfence.c 23 May 2004 20:52:22 -0000 1.16 @@ -23,6 +23,7 @@ #include "xalloc.h" #include "exit.h" #include "parseopt/lex.h" +#include "datastruct.h" #include "getstats.h" #include "conditions.h" #include "parseopt/parse.h" @@ -41,46 +42,18 @@ "Report bugs to <em...@pl...>\n" "\n"; -#ifdef DEBUG -void print_atomic (atomic *a) -{ - if (a->type == DOUBLE) { - printf ("(%0.2f ", stat[a->val_id].val.dbl); - printf (tok2string (a->op)); - printf (" %0.2f)", *((double *)a->thresh)); - } else if (a->type == SIZE) { - printf ("(%d ", stat[a->val_id].val.siz); - printf (tok2string (a->op)); - printf (" %d)", *((long int *)a->thresh)); - } -} - -void print_expr (expression *e) -{ - if (e->type == ATOMIC) { - print_atomic ((atomic *) e->arg1); - } else { - printf (" ("); - print_expr ((expression *) e->arg1); - printf (" %s ", tok2string (e->op)); - print_expr ((expression *) e->arg2); - printf (") "); - } -} -#endif - int main (int argc, char *argv[]) { - ruleset **ruletab, **ruleshm; + sf_rule **ruletab, **shmruletab; + void *shmruleptr; + int i; - int ruletabsize; + int total_rules_size = 0; int pid; - void *shm; - #ifdef DEBUG - ruleset *rl; + sf_rule *rl; #endif if (argc < 2) bail_out (EXIT_NOCONF, NULL); @@ -94,33 +67,6 @@ while (*(ruletab + rulecount) != NULL) rulecount ++; log_start (rulecount); - -#ifdef DEBUG - - printf ("read %d rules.\n", rulecount); - - i = 0; - rl = *(ruletab + i); - - while (rl != NULL) { - printf ("\nRULESET %d:\n", i); - print_expr (rl->expr); - printf (" == %d\n", check_expression (rl->expr)); - if (rl->log != NULL) { - printf ("log"); - if ((rl->log)->once) printf (" once"); - printf ("\n"); - } - if (rl->run != NULL) { - printf ("run '%s'", (rl->run)->runcmd); - if ((rl->run)->once) printf (" once"); - printf ("\n"); - } - printf ("RULESET-END\n\n"); - i ++; - rl = *(ruletab + i); - } -#endif /* open files for reading data and detach from console */ open_files (); @@ -132,34 +78,53 @@ if (semid < 0) bail_out (EXIT_SEM, NULL); /* count ruletab size */ - ruletabsize = 0; - for (i=0; i<rulecount; i++) - ruletabsize += get_rule_size (*(ruletab+i)); + for (i = 0; i < rulecount; i++) + total_rules_size += get_rule_size (*(ruletab + i)); + + /* initialize shared memory for rules */ + rules_shmid = shared_mem_init (total_rules_size + rulecount * sizeof (void *)); + if (rules_shmid < 0) bail_out (EXIT_SHM, NULL); + rules_shm = shared_mem_attach (rules_shmid); - /* initialize shared memory */ - shmid = shared_mem_init (STA_LAST * sizeof(statval) + - ruletabsize + - rulecount * sizeof (void *)); - if (shmid < 0) bail_out (EXIT_SHM, NULL); - shm = shared_mem_attach (shmid); + /* initialize shared memory for stats database */ + db_shmid = shared_mem_init (sizeof (sf_database)); + if (db_shmid < 0) bail_out (EXIT_SHM, NULL); + db_shm = shared_mem_attach (db_shmid); + main_db = (sf_database *) db_shm; - stat = (statval *)shm; + /* initialize shared memory for fs database */ + fs_shmid = shared_mem_init (FS_DATA_SIZE); + if (fs_shmid < 0) bail_out (EXIT_SHM, NULL); + fs_shm = shared_mem_attach (fs_shmid); - /* copy ruletab to shared memory */ - ruleshm = (ruleset **)(shm + STA_LAST * sizeof (statval)); - shm = (void *)(ruleshm + rulecount * sizeof (void *)); + /* initialize shared memory for proc database */ + proc_shmid = shared_mem_init (PROC_DATA_SIZE); + if (proc_shmid < 0) bail_out (EXIT_SHM, NULL); + proc_shm = shared_mem_attach (proc_shmid); - for (i=0; i<rulecount ;i++) { - *(ruleshm + i) = (ruleset *)cp_rule (&shm, *(ruletab + i)); + /* initialize database */ + main_db->fs = (sf_list *) fs_shm; + main_db->proc = proc_shm; + main_db->fs->elsize = -1; + main_db->fs->el = NULL; + main_db->fs->next = NULL; + + /* copy ruletab to shared memory */ + shmruletab = (sf_rule **) rules_shm; + shmruleptr = (rules_shm + rulecount * sizeof (void *)); + for (i = 0; i < rulecount; i++) { + *(shmruletab + i) = (sf_rule *) cp_rule (&shmruleptr, *(ruletab + i)); } /* rule-watching processes start before data provider, so we must get fresh * stats before starting them */ - fetch_la (); - fetch_mem (); + fetch_la (main_db); + fetch_mem (main_db); + fetch_fs (main_db); + fetch_proc (main_db); assert (rulecount); - ruleprocesses = (int *)xalloc (NULL, rulecount*sizeof(int)); + ruleprocesses = (int *) xalloc (NULL, rulecount * sizeof (int)); i = rulecount; do { pid = (int)fork (); @@ -170,14 +135,14 @@ /* child */ if (pid == 0) { /* one child process one ruleset */ - rule_watch_loop (*(ruleshm + i)); + rule_watch_loop (*(shmruletab + i)); } else /* parent */ { /* start handling signals */ signal_init (); /* parent goes into data-providing loop */ - res_probe_loop (); + res_probe_loop (main_db); } /* remove compilation warning */ Index: log.c =================================================================== RCS file: /cvsroot/sysfence/sysfence/log.c,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- log.c 1 Mar 2004 17:28:10 -0000 1.6 +++ log.c 23 May 2004 20:52:22 -0000 1.7 @@ -20,10 +20,12 @@ #include <syslog.h> #include "xalloc.h" #include "parseopt/lex.h" +#include "datastruct.h" #include "getstats.h" #include "conditions.h" #include "log.h" +#if 0 char * stats2str (int *sta) { char *res = xalloc (NULL, LOGLINEBUF); @@ -67,6 +69,7 @@ return res; } +#endif void log_start (int rules) { @@ -77,9 +80,10 @@ syslog (LOG_INFO, "loaded %d rules", rules); } -void log_rulehit (ruleset *rule) +void log_rulehit (sf_rule *rule) { - char *stattxt = stats2str (&(rule->showstat[0])); +// char *stattxt = stats2str (&(rule->showstat[0])); + char *stattxt = "stat logging temporarily disabled"; if (rule->name != NULL) syslog (LOG_WARNING, Index: sighandlers.c =================================================================== RCS file: /cvsroot/sysfence/sysfence/sighandlers.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- sighandlers.c 20 May 2004 14:43:21 -0000 1.1 +++ sighandlers.c 23 May 2004 20:52:22 -0000 1.2 @@ -18,6 +18,7 @@ #include <string.h> #include "exit.h" #include "parseopt/lex.h" +#include "datastruct.h" #include "getstats.h" #include "conditions.h" #include "mainloop.h" @@ -69,8 +70,14 @@ if (*(ruleprocesses + i)) kill ((pid_t)*(ruleprocesses + i), SIGTERM); /* detach, deallocate shared memory */ - shared_mem_detach ((void *)stat); - shared_mem_del (shmid); + shared_mem_detach (db_shm); + shared_mem_del (db_shmid); + shared_mem_detach (fs_shm); + shared_mem_del (fs_shmid); + shared_mem_detach (proc_shm); + shared_mem_del (proc_shmid); + shared_mem_detach (rules_shm); + shared_mem_del (rules_shmid); /* deallocate semaphore */ semaphore_del (semid); Index: log.h =================================================================== RCS file: /cvsroot/sysfence/sysfence/log.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- log.h 26 Feb 2004 20:11:09 -0000 1.2 +++ log.h 23 May 2004 20:52:22 -0000 1.3 @@ -18,7 +18,7 @@ #define LOGVARBUF 64 void log_start (int rules); -void log_rulehit (ruleset *rule); +void log_rulehit (sf_rule *rule); void log_end (); /* $Id$ */ Index: exit.h =================================================================== RCS file: /cvsroot/sysfence/sysfence/exit.h,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- exit.h 20 May 2004 14:31:35 -0000 1.5 +++ exit.h 23 May 2004 20:52:22 -0000 1.6 @@ -29,6 +29,8 @@ #define EXIT_SHM 31 #define EXIT_SEM 32 +#define EXIT_BUG 41 + void bail_out (int excode, const char *details); /* $Id$ */ Index: exit.c =================================================================== RCS file: /cvsroot/sysfence/sysfence/exit.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- exit.c 20 May 2004 14:32:35 -0000 1.5 +++ exit.c 23 May 2004 20:52:22 -0000 1.6 @@ -29,8 +29,11 @@ [EXIT_PARSE] = "Parse error: %s", [EXIT_VALUE] = "Invalid value: %s", [EXIT_OPTION] = "Invalid option: %s", + [EXIT_SHM] = "Shared memory exists", - [EXIT_SEM] = "Semaphore exists" + [EXIT_SEM] = "Semaphore exists", + + [EXIT_BUG] = "Internal bug" }; extern char *usage; |
|
From: Michal S. <em...@us...> - 2004-05-23 20:52:38
|
Update of /cvsroot/sysfence/sysfence/parseopt In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14456/parseopt Modified Files: confread.c confread.h parse.c Log Message: * general redesign: moving to new, extensible data structures stat values logging is temporarily disabled Index: confread.c =================================================================== RCS file: /cvsroot/sysfence/sysfence/parseopt/confread.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- confread.c 26 Feb 2004 14:10:14 -0000 1.4 +++ confread.c 23 May 2004 20:52:23 -0000 1.5 @@ -17,6 +17,7 @@ #include "../exit.h" #include "../xalloc.h" #include "lex.h" +#include "../datastruct.h" #include "../getstats.h" #include "../conditions.h" #include "parse.h" @@ -84,13 +85,13 @@ return res; } -ruleset ** read_config_files (int argc, char *argv[]) +sf_rule ** read_config_files (int argc, char *argv[]) { int i = 0, setsize = RULESETS, setpos = 0; - ruleset **set = (ruleset **) - xalloc (NULL, setsize * sizeof (ruleset *)); + sf_rule **set = (sf_rule **) + xalloc (NULL, setsize * sizeof (sf_rule *)); parserdata *rule; tokdata *stok, *tok; @@ -103,12 +104,12 @@ rule = get_ruleset (tok); if (rule == NULL) break; tok = rule->ptr; - *(set + setpos) = (ruleset *) rule->parsed; + *(set + setpos) = (sf_rule *) rule->parsed; setpos ++; if (setpos == setsize - 1) { /* if we're running out of buffer, resize it */ setsize += RULESETS; - set = (ruleset **) xalloc (set, setsize * sizeof (ruleset *)); + set = (sf_rule **) xalloc (set, setsize * sizeof (sf_rule *)); } } Index: confread.h =================================================================== RCS file: /cvsroot/sysfence/sysfence/parseopt/confread.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- confread.h 8 Feb 2004 17:40:16 -0000 1.2 +++ confread.h 23 May 2004 20:52:23 -0000 1.3 @@ -18,6 +18,6 @@ char * readfile (char *fname); tokdata * tokenized_conf (char *fname); -ruleset ** read_config_files (int argc, char *argv[]); +sf_rule ** read_config_files (int argc, char *argv[]); /* $Id$ */ Index: parse.c =================================================================== RCS file: /cvsroot/sysfence/sysfence/parseopt/parse.c,v retrieving revision 1.12 retrieving revision 1.13 diff -u -d -r1.12 -r1.13 --- parse.c 20 May 2004 15:57:09 -0000 1.12 +++ parse.c 23 May 2004 20:52:23 -0000 1.13 @@ -17,6 +17,7 @@ #include "lex.h" #include "../exit.h" #include "../xalloc.h" +#include "../datastruct.h" #include "../getstats.h" #include "../conditions.h" #include "parse.h" @@ -55,6 +56,7 @@ bail_out (EXIT_PARSE, buf); } +#if 0 void collect_stats (expression *ex, int *tab) { if (ex->type == ATOMIC) { @@ -64,6 +66,7 @@ collect_stats ((expression *) ex->arg2, tab); } } +#endif parserdata * get_logdata (tokdata *tok) { @@ -73,7 +76,7 @@ * */ parserdata *res; - logdata *log; /* helper */ + sf_logdata *log; /* helper */ if (tok->type != KW_LOG) return NULL; @@ -81,8 +84,8 @@ /* that's log data. initialize structures */ res = (parserdata *) xalloc (NULL, sizeof (parserdata)); - res->parsed = xalloc (NULL, sizeof ( logdata)); - log = (logdata *) res->parsed; + res->parsed = xalloc (NULL, sizeof (sf_logdata)); + log = (sf_logdata *) res->parsed; if (tok->type == KW_ONCE) { log->once = 1; tok ++; @@ -103,7 +106,7 @@ const char *thisfuncname = "get_rundata()"; #endif parserdata *res; - rundata *run; /* helper */ + sf_rundata *run; /* helper */ if (tok->type != KW_RUN) return NULL; @@ -111,8 +114,8 @@ /* that's run data. initialize structures */ res = (parserdata *) xalloc (NULL, sizeof (parserdata)); - res->parsed = xalloc (NULL, sizeof (rundata)); - run = (rundata *) res->parsed; + res->parsed = xalloc (NULL, sizeof (sf_rundata)); + run = (sf_rundata *) res->parsed; if (tok->type == KW_ONCE) { run->once = 1; tok ++; @@ -124,7 +127,7 @@ #else parse_error (tok); #endif - run->runcmd = tok->val; + run->command = tok->val; tok ++; res->ptr = tok; @@ -177,14 +180,14 @@ #ifdef DEBUG const char *thisfuncname = "expression_decompose()"; #endif - expression *resexp; + sf_expression *resexp; parserdata *right, *res; tokdata *tok = left->ptr; if ((tok->type == LO_OR) || (tok->type == LO_AND)) { /* this is compound expression */ res = (parserdata *) xalloc (NULL, sizeof (parserdata)); - resexp = (expression *) xalloc (NULL, sizeof (expression)); + resexp = (sf_expression *) xalloc (NULL, sizeof (sf_expression)); res->parsed = (void *) resexp; resexp->type = RELATION; /* set the expression we found before as first argument */ @@ -244,7 +247,7 @@ #ifdef DEBUG const char *thisfuncname = "get_atomic()"; #endif - atomic *at = (atomic *) xalloc (NULL, sizeof (atomic)); + sf_atomic *at = (sf_atomic *) xalloc (NULL, sizeof (sf_atomic)); tokdata *var = tok, *op = tok + 1, *val = tok + 2; @@ -255,39 +258,46 @@ switch (var->type) { case ID_LA1: - at->type = DOUBLE; + at->thresh.type = DOUBLE; at->op = op->type; - at->val_id = STA_LA1; + at->stat.label = ST_LOAD; + at->stat.arg[0].laminutes = 1; break; case ID_LA5: - at->type = DOUBLE; + at->thresh.type = DOUBLE; at->op = op->type; - at->val_id = STA_LA5; + at->stat.label = ST_LOAD; + at->stat.arg[0].laminutes = 5; break; case ID_LA15: - at->type = DOUBLE; + at->thresh.type = DOUBLE; at->op = op->type; - at->val_id = STA_LA15; + at->stat.label = ST_LOAD; + at->stat.arg[0].laminutes = 15; break; case ID_MFREE: - at->type = SIZE; + at->thresh.type = INTEGER; at->op = op->type; - at->val_id = STA_MFREE; + at->stat.label = ST_MEM; + at->stat.arg[0].resstat = VA_FREE; break; case ID_MUSED: - at->type = SIZE; + at->thresh.type = INTEGER; at->op = op->type; - at->val_id = STA_MUSED; + at->stat.label = ST_MEM; + at->stat.arg[0].resstat = VA_USED; break; case ID_SFREE: - at->type = SIZE; + at->thresh.type = INTEGER; at->op = op->type; - at->val_id = STA_SFREE; + at->stat.label = ST_SWAP; + at->stat.arg[0].resstat = VA_FREE; break; case ID_SUSED: - at->type = SIZE; + at->thresh.type = INTEGER; at->op = op->type; - at->val_id = STA_SUSED; + at->stat.label = ST_SWAP; + at->stat.arg[0].resstat = VA_USED; break; default: return NULL; @@ -313,8 +323,8 @@ /* check value type */ if (val->type == VA_INT) { /* this is integer. convert it to type required by label */ - if (at->type == SIZE) val->type = VA_SIZ; - else if (at->type == DOUBLE) { + if (at->thresh.type == INTEGER) val->type = VA_SIZ; + else if (at->thresh.type == DOUBLE) { /* long int 2 double */ val->type = VA_DBL; tmp = xalloc (NULL, sizeof (double)); @@ -324,8 +334,8 @@ } } - if (((at->type == SIZE) && (val->type != VA_SIZ)) || - ((at->type == DOUBLE) && (val->type != VA_DBL))) + if (((at->thresh.type == INTEGER) && (val->type != VA_SIZ)) || + ((at->thresh.type == DOUBLE) && (val->type != VA_DBL))) #ifdef DEBUG parse_error (val, thisfuncname, "type mismatch"); #else @@ -333,7 +343,7 @@ #endif /* copy threshold value */ - at->thresh = val->val; + at->thresh.ptr = val->val; res = (parserdata *) xalloc (NULL, sizeof (parserdata)); res->ptr = tok; @@ -344,11 +354,11 @@ parserdata * get_atomic_expression (tokdata *tok) { /* get atomic and encapsulate into expression with type = ATOMIC */ - parserdata *at = get_atomic (tok); - expression *ex; + parserdata *at = get_atomic (tok); + sf_expression *ex; if (at == NULL) return NULL; - ex = (expression *) xalloc (NULL, sizeof (expression)); + ex = (sf_expression *) xalloc (NULL, sizeof (sf_expression)); /* we'll use the same parserdata structure */ ex->type = ATOMIC; @@ -405,14 +415,14 @@ /* our result data */ parserdata *res = (parserdata *) xalloc (NULL, sizeof (parserdata)), *tmp, *run, *log; - ruleset *rlst; /* helper */ + sf_rule *rlst; /* helper */ /* the only way to return w/o error is to find end-of-file */ if (tok->type == END) return NULL; /* create ruleset structure */ - res->parsed = (ruleset *) xalloc (NULL, sizeof (ruleset)); - rlst = (ruleset *) res->parsed; + res->parsed = (sf_rule *) xalloc (NULL, sizeof (sf_rule)); + rlst = (sf_rule *) res->parsed; /* reset fields */ rlst->name = NULL; rlst->expr = NULL; @@ -420,8 +430,6 @@ rlst->log = NULL; rlst->hit = 0; rlst->prevhit = 0; - for (i = 0; i < STA_LAST; i++) - rlst->showstat[i] = 0; /* ruleset begins with IF */ if (tok->type != KW_IF) @@ -432,11 +440,17 @@ #endif else tok ++; - /* then we may find an optional rule name. */ + /* then we have rule name */ if (tok->type == VA_STR) { rlst->name = tok->val; - tok ++; + } else { +#ifdef DEBUG + parse_error (tok, thisfuncname, "no rule name"); +#else + parse_error (tok); +#endif } + tok ++; /* next should be expression in block */ tmp = get_block_expression (tok); @@ -448,7 +462,7 @@ #endif /* save expression and skip to next token */ - rlst->expr = (expression *) tmp->parsed; + rlst->expr = (sf_expression *) tmp->parsed; tok = tmp->ptr; run = get_rundata (tok); @@ -464,7 +478,7 @@ /* this is full ruleset now but we try to get next action data */ if (run != NULL) { /* save rundata && get logdata */ - rlst->run = (rundata *) run->parsed; + rlst->run = (sf_rundata *) run->parsed; log = get_logdata (run->ptr); /* if we have log sequence, save it. @@ -472,16 +486,16 @@ */ if (log != NULL) { tok = log->ptr; - rlst->log = (logdata *) log->parsed; + rlst->log = (sf_logdata *) log->parsed; } else tok = run->ptr; } else { - rlst->log = (logdata *) log->parsed; + rlst->log = (sf_logdata *) log->parsed; /* save logdata && get rundata */ run = get_rundata (log->ptr); if (run != NULL) { tok = run->ptr; - rlst->run = (rundata *) run->parsed; + rlst->run = (sf_rundata *) run->parsed; } else tok = log->ptr; } @@ -491,7 +505,7 @@ rlst->step = *((unsigned int *) tmp->parsed); /* search expression tree for used stats */ - collect_stats (rlst->expr, &(rlst->showstat[0])); +// collect_stats (rlst->expr, &(rlst->showstat[0])); /* ok, now we got full ruleset structure. * we need only to skip to next token. |