[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: Bug in FilterProcTTimeMatch function in filters.c
From: |
Bas van der Vlies |
Subject: |
RE: Bug in FilterProcTTimeMatch function in filters.c |
Date: |
Wed, 03 Sep 2003 10:04:24 +0200 |
User-agent: |
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.4) Gecko/20030624 |
Forgot to include the patch ;-)
--
--
********************************************************************
* *
* Bas van der Vlies e-mail: basv@sara.nl *
* SARA - Academic Computing Services phone: +31 20 592 8012 *
* Kruislaan 415 fax: +31 20 6683167 *
* 1098 SJ Amsterdam *
* *
********************************************************************
diff -ruN cfengine-2.0.7p3-old/src/filters.c cfengine-2.0.7p3/src/filters.c
--- cfengine-2.0.7p3-old/src/filters.c Tue Sep 2 12:00:57 2003
+++ cfengine-2.0.7p3/src/filters.c Tue Sep 2 12:01:47 2003
@@ -1095,6 +1095,49 @@
return false;
}
+/*
+ * HvB: Bas van der Vlies
+ * Parse different TTime values
+*/
+void ParseTTime(line, time_str)
+
+char *line;
+char *time_str;
+
+{
+int day=0, hr=0, min=0, sec=0;
+int r;
+
+if (strstr(line,":")) /* day-Hr:Min:Sec */
+ {
+ /*
+ * first check the long fromat
+ * day-hr:min:sec (posix)
+ * hr:min:sec (posix)
+ * min:sec (old)
+ */
+ if ((r = sscanf(line,"%d-%d:%d:%d",&day,&hr,&min,&sec)) == 4)
+ {
+ snprintf(time_str,256,"accumulated(0,0,%d,%d,%d,%d)",day,hr,min,sec);
+ }
+ else if ((r = sscanf(line,"%d:%d:%d",&hr,&min,&sec)) == 3 )
+ {
+ snprintf(time_str,256,"accumulated(0,0,0,%d,%d,%d)",hr,min,sec);
+ }
+ else if ((r = sscanf(line,"%d:%d",&min,&sec)) == 2 )
+ {
+ if (min > 59)
+ {
+ day = min / (24 * 60);
+ hr = (min - (day * 24 * 60)) / (60);
+ min = min % 60;
+ }
+ snprintf(time_str,256,"accumulated(0,0,%d,%d,%d,%d)",day,hr,min,sec);
+ }
+ }
+}
+
+
/*******************************************************************/
int FilterProcTTimeMatch(name1,name2,fromexpr,toexpr,names,line)
@@ -1113,19 +1156,10 @@
{
if ((strcmp(names[i],name1) == 0) || (strcmp(names[i],name2) == 0))
{
- if (strstr(line[i],":")) /* Hr:Min:Sec */
- {
- sscanf(line[i],"%d:%d",&min,&sec);
-
- if (sec < 0 || min < 0)
- {
- CfLog(cferror,"Parse error checking process time","");
- return false;
- }
-
- snprintf(timestr,256,"accumulated(0,0,0,%d,%d,%d)",hr,min,sec);
- pstime = Date2Number(timestr,now);
- }
+ bzero(timestr, sizeof(timestr));
+ ParseTTime(line[i], timestr);
+ Debug("ParseTTime = %s\n",timestr);
+ pstime = Date2Number(timestr,now);
return ((fromtime < pstime) && (pstime < totime));
}