bug-cfengine
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Cfengine] Re: SplitLine bug in filters.c


From: Bas van der Vlies
Subject: Re: [Cfengine] Re: SplitLine bug in filters.c
Date: Mon, 04 Aug 2003 07:51:36 +0200
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.4) Gecko/20030624

I notice it when i post this message that it is debian specific ;-( and forgot to mention it.

Andrew Stribblehill wrote:

Quoting Bas van der Vlies <address@hidden> (2003-08-01 10:40:14 BST):

cfengine: 2.0.7p3

I uss the filters commadn to determine if PPID=1. In cfengine 2.0.5
i get the right values but in cfengine 2.0.7p3 it is broken. The code
has changed between this version in SplitLine. I have applied the
following simple patch and now it works again for me, see attachment


That won't apply. Your patch was to a Debian-local patch I wrote and
haven't yet pushed up to Mark. So I guess what I'm saying is that
SplitLine in 2.0.7p3 hasn't changed but should do.

Here's the patch, relative to 2.0.7p3 -- feel free to reject if it
doesn't apply cleanly to 2.1.0. It fixes the case where ps returns
something like:

     UID   PID  PPID  C    STIME TTY      TIME CMD
   httpd 11992   436  0                   0:00 <defunct>

That's what Solaris does for zombies.

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  2003-04-23 21:48:13.000000000 +0100
+++ cfengine-2.0.7p3/src/filters.c      2003-07-16 18:03:14.000000000 +0100
@@ -583,7 +583,7 @@
    return false;
    }
-SplitLine(proc,filterlist,names,start,end,line);
+SplitLine(proc,names,start,end,line);
for (fp = VFILTERLIST; fp != NULL; fp=fp->next)
    {
@@ -1010,7 +1010,7 @@
   regex_t rx;
   regmatch_t pmatch;
- Debug("FilterProcMatch(%s,%s,%s,%s,[%s])\n",name1,name2,expr,names,line);
+  Debug("FilterProcMatch(%s,%s,%s,<%x>,<%x>)\n",name1,name2,expr,names,line);
if (CfRegcomp(&rx,expr,REG_EXTENDED) != 0)
    {
@@ -1419,8 +1419,8 @@
    else if (start[col] == -1)
       {
       start[col] = offset;
-      Debug("Start of %s is %d\n",title,offset);
       sscanf(sp,"%15s",title);
+      Debug("Start of %s is %d\n",title,offset);
       names[col] = strdup(title);
       Debug("Col[%d]=%s\n",col,names[col]);
       }
@@ -1435,11 +1435,10 @@
/*******************************************************************/ -void SplitLine(proc,filterlist,names,start,end,line)
+void SplitLine(proc,names,start,end,line)
char *proc, **names, **line;
 int *start,*end;
-struct Item *filterlist;
{ int i,s,e; @@ -1452,9 +1451,6 @@ for (i = 0; names[i] != NULL; i++)
    {
-   s = start[i];
-   e = end[i];
-
    for (s = start[i]; (s >= 0) && !isspace((int)*(proc+s)); s--)
       {
       }
@@ -1488,10 +1484,17 @@
         }
       }
- line[i] = (char *)malloc(e-s+2);
-
-   bzero(line[i],(e-s+2));
-   strncpy(line[i],(char *)(proc+s),(e-s+1));
+   if (s <= e)
+      {
+      line[i] = (char *)malloc(e-s+2);
+      bzero(line[i],(e-s+2));
+      strncpy(line[i],(char *)(proc+s),(e-s+1));
+      }
+   else
+      {
+      line[i] = (char *)malloc(1);
+      line[i][0] = '\0';
+      }
Debug(" %s=(%s) of [%s]\n",names[i],line[i],proc);
    }
diff -ruN cfengine-2.0.7p3-old/src/prototypes.h 
cfengine-2.0.7p3/src/prototypes.h
--- cfengine-2.0.7p3-old/src/prototypes.h       2003-05-11 11:10:09.000000000 
+0100
+++ cfengine-2.0.7p3/src/prototypes.h   2003-07-16 17:30:06.000000000 +0100
@@ -322,7 +322,7 @@
 enum filternames FilterActionsToCode ARGLIST((char *filtertype));
 int FilterExists ARGLIST((char *name));
 int ProcessFilter ARGLIST((char *proc, struct Item *filterlist,char 
**names,int *start,int *stop));
-void SplitLine ARGLIST((char *proc, struct Item *filterlist,char **names,int 
*start,int *stop,char **line));
+void SplitLine ARGLIST((char *proc, char **names,int *start,int *stop,char 
**line));
 int FileObjectFilter ARGLIST((char *file, struct stat *statptr, struct Item 
*filterlist, enum actions context));
 time_t Date2Number ARGLIST((char *string, time_t now));
 void Size2Number ARGLIST((char *buffer));



--
--
********************************************************************
*                                                                  *
*  Bas van der Vlies                     e-mail: address@hidden      *
*  SARA - Academic Computing Services    phone:  +31 20 592 8012   *
*  Kruislaan 415                         fax:    +31 20 6683167    *
*  1098 SJ Amsterdam                                               *
*                                                                  *
********************************************************************





reply via email to

[Prev in Thread] Current Thread [Next in Thread]