help-cfengine
[Top][All Lists]
Advanced

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

SyslogFacility (with proposed patch)


From: Leonardo Helman
Subject: SyslogFacility (with proposed patch)
Date: Thu, 29 Jul 2004 15:34:42 -0300
User-agent: Mutt/1.4.2.1i

Hi


I've been trying to change the cfengine (server) syslog facility.
I want it to be able to change the loggin file with syslog.conf.

I've found reading the code that you can change that setting
with environment variables.
Something like:
export SyslogFacility=LOG_LOCAL4    (for example)

before starting the server.
Something like setting it in /etc/init.d/cfengine

That solved my problem.

At this time, you can't set it whith a configuration parameter in cfservd.conf
like:
-----------------------------------------
control:

        Syslog= ( on )
        SyslogFacility= ( LOG_LOCAL1 )

-----------------------------------------
Because the function CfOpenLog is called before the configuration
is read.

So I've made a little patch, calling again CfOpenLog,
and if the new SyslogFacility is not equal to the default,
I'll do a closelog, and a new open.

The result is, that if you don't have configuration or memory
errors, all syslog facilities will go to the configurated one.
And only if you have some errors, will log to the default.

It's not the perfect solution, but...

here is the patch (only cfservd.c and log.c)
--------------------------------------------------------------
--- src/cfservd.c.ori   2004-07-29 14:43:49.000000000 -0300
+++ src/cfservd.c       2004-07-29 14:48:27.000000000 -0300
@@ -137,6 +137,9 @@
 {
 CheckOptsAndInit(argc,argv);
 ParseInputFile(VINPUTFILE);
+/* We call CfOpenLog again so, if we configure SyslogFacility, 
+   we open syslog again */
+CfOpenLog();
 CheckVariables();
 SummarizeParsing();
 
--- src/log.c.ori       2004-07-29 14:44:05.000000000 -0300
+++ src/log.c   2004-07-29 15:19:11.000000000 -0300
@@ -39,6 +39,7 @@
 
 { char value[CF_BUFSIZE];
   int facility = LOG_USER; 
+  static lastsyslog=0;
  
 if (GetMacroValue(CONTEXTID,"SyslogFacility"))
    {
@@ -73,14 +74,32 @@
       facility = LOG_LOCAL4;
       }
    
+   if( lastsyslog != 1 ) {
+      if( lastsyslog ) {
+         closelog();
+      }
+   }
+   lastsyslog=1;
    openlog(VPREFIX,LOG_PID|LOG_NOWAIT|LOG_ODELAY,facility);
    }
 else if (ISCFENGINE)
    {
+   if( lastsyslog != 2 ) {
+      if( lastsyslog ) {
+         closelog();
+      }
+   }
+   lastsyslog=2;
    openlog(VPREFIX,LOG_PID|LOG_NOWAIT|LOG_ODELAY,LOG_USER);
    }
 else
    {
+   if( lastsyslog != 3 ) {
+      if( lastsyslog ) {
+         closelog();
+      }
+   }
+   lastsyslog=3;
    openlog(VPREFIX,LOG_PID|LOG_NOWAIT|LOG_ODELAY,LOG_DAEMON);
    }
 }
--------------------------------------------------------------



Saludos

Eng. Leonardo Helman
Pert Consultores
Argentina


PS: If it's not to much to ask from you, would you
be so kind to add LOCAL5, LOCAL6 and LOCAL7 for linux?
 





reply via email to

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