[Pacemaker] [PATCH 5/8 ] ha_logd: New option to disable syslog logging

Bernd Schubert bs_lists at aakef.fastmail.fm
Wed Sep 15 18:16:36 EDT 2010


ha_logd: New option to disable syslog logging

As we already write ha-log and ha-debug, users might want to disable syslog
logging.

Signed-off-by: Bernd Schubert <bschubert at ddn.com>

diff --git a/logd/ha_logd.c b/logd/ha_logd.c
--- a/logd/ha_logd.c
+++ b/logd/ha_logd.c
@@ -91,6 +91,7 @@ static struct {
 	int		log_facility;
 	mode_t		logmode;
 	gboolean	syslogfmtmsgs;
+	gboolean	syslog;
 } logd_config =
 	{
 		.debugfile = "",
@@ -98,7 +99,8 @@ static struct {
 		.entity    = "logd",
 		.log_facility = HA_LOG_FACILITY,
 		.logmode  = 0644,
-		.syslogfmtmsgs = FALSE
+		.syslogfmtmsgs = FALSE,
+		.syslog = TRUE,
 	};
 
 static void	logd_log(const char * fmt, ...) G_GNUC_PRINTF(1,2);
@@ -109,6 +111,7 @@ static int	set_entity(const char * optio
 static int	set_sendqlen(const char * option);
 static int	set_recvqlen(const char * option);
 static int	set_logmode(const char * option);
+static int 	set_syslog(const char* option);
 static int	set_syslogfmtmsgs(const char * option);
 
 
@@ -126,6 +129,7 @@ static struct directive {
 	{"sendqlen",	set_sendqlen},
 	{"recvqlen",	set_recvqlen},
 	{"logmode",	set_logmode},
+	{"syslog",	set_syslog},
 	{"syslogmsgfmt",set_syslogfmtmsgs}
 };
 
@@ -275,6 +279,26 @@ set_logmode(const char * option)
 	logd_config.logmode = (mode_t)mode;
 	return TRUE;
 }
+
+static int
+set_syslog(const char* option)
+{
+	gboolean	syslog;
+	
+    	if (!option){
+		return FALSE;
+	}
+	if (cl_str_to_boolean(option, &syslog) == HA_OK ) {
+		cl_log(LOG_INFO, "Setting syslog logging to %s",
+			syslog ? "enbled" : "disabled");
+		logd_config.syslog = syslog;
+	} else
+		return FALSE;
+	
+	return TRUE;
+}
+
+
 static int
 set_syslogfmtmsgs(const char * option)
 {
@@ -918,20 +942,13 @@ main(int argc, char** argv, char** envp)
 	
 	set_ipc_time_debug_flag(FALSE);
 	cl_log_set_uselogd(FALSE);
+	/* initialize early, so that we see our own errors on stdout */
+	cl_log_enable_stderr(TRUE);
 
 	if (!cfgfile && access(DEFAULT_CFG_FILE, F_OK) == 0) {
 		cfgfile = DEFAULT_CFG_FILE;
 	}
-	
-
-	/* default one set to "logd"
-	 * by setting facility, we enable syslog
-	 */
-	cl_log_enable_stderr(TRUE);
-	cl_log_set_entity(logd_config.entity);
-	cl_log_set_facility(logd_config.log_facility);
-	
-	
+		
 	if (ask_status){
 		long pid;
 		
@@ -954,8 +971,6 @@ main(int argc, char** argv, char** envp)
 		exit(LSB_EXIT_OK);
 	}
 
-	logd_make_daemon(daemonize);
-
 	
 	if (ipc_channel_pair(chanspair) != IPC_OK){
 		cl_perror("cannot create channel pair IPC");
@@ -969,15 +984,29 @@ main(int argc, char** argv, char** envp)
 		exit(LSB_EXIT_NOTCONFIGED);
 	}
 	
+	if (!logd_config.syslog && logd_config.debugfile == EOS && 
+	    logd_config.logfile == EOS) {
+		cl_log(LOG_ERR, "Invalid config: No logfile defined and syslog disabled");
+		exit(LSB_EXIT_EINVAL);
+	}
+	
+	/* 
+	 * by setting facility, we enable syslog
+	 */
+	if (logd_config.syslog) {
+		cl_log_set_entity(logd_config.entity);
+		cl_log_set_facility(logd_config.log_facility);
+	}
+	
 	if (strlen(logd_config.debugfile) > 0) {
 		cl_log_set_debugfile(logd_config.debugfile);
 	}
 	if (strlen(logd_config.logfile) > 0) {
 		cl_log_set_logfile(logd_config.logfile);
 	}
-	cl_log_set_entity(logd_config.entity);
-	cl_log_set_facility(logd_config.log_facility);
 	
+	/* Only daemonize after setting up log files */
+	logd_make_daemon(daemonize);
 	
 	cl_log(LOG_INFO, "logd started with %s.",
 	       cfgfile ? cfgfile : "default configuration");
diff --git a/logd/logd.cf b/logd/logd.cf
--- a/logd/logd.cf
+++ b/logd/logd.cf
@@ -41,4 +41,6 @@
 #
 #recvqlen 256
 
-
+#	Do we log to syslog?
+#	Default: yes
+#syslog yes




More information about the Pacemaker mailing list