[Top][All Lists]

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

Patching an itch (part 2)

From: Chip Seraphine
Subject: Patching an itch (part 2)
Date: Wed, 05 Nov 2003 17:03:01 -0600
User-agent: Mozilla/5.0 (X11; U; SunOS i86pc; en-US; rv:1.2.1) Gecko/20030121

Here's another one we use here.  It is rather specific to the way I use
cfengine, but I'm posting it anyway in case it is of general interest.

I do a lot of syslog monitoring at my site, and in the interest of log
readability I tweaked the shellcommands logging so that it is less verbose at
default levels.  (A lot of my commands are passed $CFALLCLASSES on their
command line; printing the first couple hundred characters of the classlist
twice per shellcommand is a bit much at default verbosity levels, IMHO.)  At
'normal' verbosity (i.e. no -d or -v flags) it will generate one log entry
instead of two, and the exec string in that one will be truncated if it is
longer than 31 characters.  This patch does not change any behavior when
running with verbosity.

--- cfengine-2.1.0p1/src/do.c   Wed Oct 22 03:28:57 2003
+++ cfengine-2.1.0p1-new/src/do.c       Wed Nov  5 16:57:29 2003
@@ -1124,6 +1124,7 @@
 { struct ShellComm *ptr;
   char line[bufsize];
   char comm[20], *sp;
+  char execstrbuf[trunc_bufsize], *execstrtmp;
   char execstr[bufsize];
   char chdir_buf[bufsize];
   char chroot_buf[bufsize];
@@ -1160,7 +1161,18 @@

-   snprintf(OUTPUT,bufsize*2,"Executing script 
+   /* Unless we are debugging, keep the execstr manageable.  This is so
+      that commands that are passed entire CFALLCLASSES lists don't overly
+      pollute the syslogs. */
+   if ( (!SILENT && (VERBOSE || DEBUG || D2)) || (strlen(execstr) < 
trunc_bufsize) )
+      {
+      execstrtmp= execstr;
+      }
+   else
+      {
+      execstrtmp= strncpy(execstrbuf,execstr,trunc_bufsize-1);
+      }
+   snprintf(OUTPUT,bufsize*2,"Executing script 

    if (DONTDO && preview != 'y')
@@ -1330,8 +1342,10 @@


+   /* Don't bother conditionally truncating this one, since it
+      goes out on cfsilent anyway. */
    snprintf(OUTPUT,bufsize*2,"Finished script %s\n",execstr);
-   CfLog(cfinform,OUTPUT,"");
+   CfLog(cfsilent,OUTPUT,"");  /* Want to know about completion if debugging */


reply via email to

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