Update of /cvsroot/sysfence/sysfence/parseopt
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4613/parseopt
Modified Files:
parse.c
Log Message:
+ nproc handling
so far, works only with -DDEBUG and crashes without it. don't know why
Index: parse.c
===================================================================
RCS file: /cvsroot/sysfence/sysfence/parseopt/parse.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- parse.c 31 May 2004 14:10:06 -0000 1.17
+++ parse.c 4 Jun 2004 13:07:04 -0000 1.18
@@ -14,6 +14,8 @@
*/
+#include <stdio.h>
+#include <stdlib.h>
#include "lex.h"
#include "../sys/exit.h"
#include "../sys/xalloc.h"
@@ -21,8 +23,7 @@
#include "../getstats.h"
#include "../conditions.h"
#include "parse.h"
-#include <stdio.h>
-#include <stdlib.h>
+#include "../sys/users.h"
#ifdef DEBUG
#include <syslog.h>
#include "../sys/log.h"
@@ -248,6 +249,108 @@
#endif
}
+sf_list * get_uid_list_rec (tokdata **tok)
+{
+ sf_list *res;
+ uid_t *tmpuid;
+#ifdef DEBUG
+ char *thisfuncname = "get_uid_list_rec()";
+#endif
+
+ switch ((*tok)->type) {
+ case VA_INT:
+ tmpuid = (uid_t *) xalloc (NULL, sizeof (uid_t));
+ tmpuid = (uid_t *) (*tok)->val;
+ break;
+ case VA_STR:
+ tmpuid = username2uid ((char *) (*tok)->val);
+ if (!tmpuid) {
+#ifdef DEBUG
+ parse_error (*tok, thisfuncname, "invalid username");
+#else
+ parse_error (*tok);
+#endif
+ }
+ break;
+ default:
+ return NULL;
+ }
+
+ res = (sf_list *) xalloc (NULL, sizeof (sf_list));
+ res->elsize = sizeof (uid_t);
+ res->el = (void *) tmpuid;
+ *tok = *tok + 1;
+
+ if ((*tok)->type == LI_SEP) {
+ /* separator?
+ * go, fetch next uid
+ */
+ *tok = *tok + 1;
+ res->next = get_uid_list_rec (tok);
+ } else res->next = NULL;
+ return res;
+}
+
+parserdata * get_uid_list (tokdata *tok)
+{
+ parserdata *res;
+ sf_list *list = get_uid_list_rec (&tok);
+
+ res->ptr = tok - 1;
+ res->parsed = (void *) list;
+ return res;
+}
+
+char get_states_rec (tokdata **tok)
+{
+ char thisstate = 0;
+
+ switch ((*tok)->type) {
+ case PR_RUN:
+ thisstate = PROC_RUN;
+ break;
+ case PR_STOP:
+ thisstate = PROC_STOP;
+ break;
+ case PR_SLEEP:
+ thisstate = PROC_SLEEP;
+ break;
+ case PR_UNINT:
+ thisstate = PROC_UNINT;
+ break;
+ case PR_ZOMBIE:
+ thisstate = PROC_ZOMBIE;
+ break;
+ default:
+ return 0;
+ }
+
+ *tok = *tok + 1;
+
+ if ((*tok)->type == LI_SEP) {
+ /* separator?
+ * go, fetch next state
+ */
+ *tok = *tok + 1;
+ thisstate |= get_states_rec (tok);
+ }
+
+ return thisstate;
+}
+
+parserdata * get_states (tokdata *tok)
+{
+ parserdata *res = (parserdata *) xalloc (NULL, sizeof (parserdata));
+ char *states = (char *) xalloc (NULL, sizeof (char));
+
+ *states = get_states_rec (&tok);
+
+ if (*states == 0) *states = PROC_ANY;
+ res->ptr = tok;
+ res->parsed = (void *) states;
+ return res;
+}
+
parserdata * get_atomic (tokdata *tok)
{
#ifdef DEBUG
@@ -259,7 +362,9 @@
*arg2 = NULL,
*op,
*val;
- parserdata *res;
+ sf_list *uids = NULL;
+ char states = PROC_ANY;
+ parserdata *res, *subpar;
double *tmp;
int skiptok = 3;
@@ -284,6 +389,23 @@
val = tok + 3;
skiptok ++;
break;
+ case ID_NPROC:
+ /* try to get uids list */
+ subpar = get_uid_list (tok + 1);
+ if (subpar->parsed) uids = (sf_list *) subpar->parsed;
+ tok = subpar->ptr;
+
+ /* try to get states */
+ subpar = get_states (tok + 1);
+ if (subpar) {
+ states = *((char *) subpar->parsed);
+ tok = subpar->ptr;
+ }
+
+ skiptok = 2;
+ op = tok;
+ val = tok + 1;
+ break;
default:
op = NULL;
}
@@ -354,6 +476,16 @@
at->stat.arg[0].resstat = VA_USED;
at->stat.arg[1].path = (char *) arg1->val;
break;
+ case ID_NPROC:
+ at->thresh.type = INTEGER;
+ at->op = op->type;
+ at->stat.label = ST_PROC;
+ at->stat.arg[0].uids = uids;
+#ifdef DEBUG
+ syslog (LOG_DEBUG, "%s", uids_2_str (uids));
+#endif
+ at->stat.arg[1].procstates = states;
+ break;
default:
return NULL;
}
|