This is the mail archive of the cluster-cvs@sourceware.org mailing list for the cluster.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

master - ccs: add ccs_read_logging


Gitweb:        http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=74577abb0191939a47bacf1453390c937346a08c
Commit:        74577abb0191939a47bacf1453390c937346a08c
Parent:        ae8893dbff1377dea4111411db17d5438d2e39f9
Author:        Fabio M. Di Nitto <fdinitto@redhat.com>
AuthorDate:    Wed Oct 29 06:16:25 2008 +0100
Committer:     Fabio M. Di Nitto <fdinitto@redhat.com>
CommitterDate: Wed Oct 29 06:21:03 2008 +0100

ccs: add ccs_read_logging

this function is a simple wrapper to gather all logging configuration
from one central place since this code is replicated already N times
across the tree.

the function should always be invoked with the selected default values
and it will apply overrides from the config (if available and if
possible).

you are responsible for freeing char **file when changed via
cluster.conf.

Signed-off-by: Fabio M. Di Nitto <fdinitto@redhat.com>
---
 config/libs/libccsconfdb/Makefile |    2 +-
 config/libs/libccsconfdb/ccs.h    |    1 +
 config/libs/libccsconfdb/extras.c |  128 +++++++++++++++++++++++++++++++++++++
 3 files changed, 130 insertions(+), 1 deletions(-)

diff --git a/config/libs/libccsconfdb/Makefile b/config/libs/libccsconfdb/Makefile
index d75710f..2b233f3 100644
--- a/config/libs/libccsconfdb/Makefile
+++ b/config/libs/libccsconfdb/Makefile
@@ -16,7 +16,7 @@ include $(OBJDIR)/make/uninstall.mk
 
 CFLAGS += -fPIC
 CFLAGS += -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64
-CFLAGS += -I${corosyncincdir} `xml2-config --cflags`
+CFLAGS += -I${corosyncincdir} -I${logtincdir} `xml2-config --cflags`
 CFLAGS += -I${incdir}
 
 LDFLAGS += -L${corosynclibdir} -lconfdb
diff --git a/config/libs/libccsconfdb/ccs.h b/config/libs/libccsconfdb/ccs.h
index a4ead73..d2ff07a 100644
--- a/config/libs/libccsconfdb/ccs.h
+++ b/config/libs/libccsconfdb/ccs.h
@@ -12,6 +12,7 @@ int ccs_get(int desc, const char *query, char **rtn);
 int ccs_get_list(int desc, const char *query, char **rtn);
 int ccs_set(int desc, const char *path, char *val);
 int ccs_lookup_nodename(int desc, const char *nodename, char **rtn);
+void ccs_read_logging(int desc, char *name, int *debug, int *mode, int *facility, int *priority, char **file);
 
 extern int fullxpath;
 
diff --git a/config/libs/libccsconfdb/extras.c b/config/libs/libccsconfdb/extras.c
index 9f72978..456dd9c 100644
--- a/config/libs/libccsconfdb/extras.c
+++ b/config/libs/libccsconfdb/extras.c
@@ -4,6 +4,11 @@
 #include <netdb.h>
 #include <stdlib.h>
 #include <stdio.h>
+#include <limits.h>
+
+#define SYSLOG_NAMES
+#include <syslog.h>
+#include <liblogthread.h>
 
 #include "ccs.h"
 
@@ -192,3 +197,126 @@ out_fail:
 	*retval = NULL;
 	return (-1);
 }
+
+static int facility_id_get (char *name)
+{
+	unsigned int i;
+
+	for (i = 0; facilitynames[i].c_name != NULL; i++) {
+		if (strcasecmp(name, facilitynames[i].c_name) == 0) {
+			return (facilitynames[i].c_val);
+		}
+	}
+	return (-1);
+}
+
+static int priority_id_get (char *name)
+{
+	unsigned int i;
+
+	for (i = 0; prioritynames[i].c_name != NULL; i++) {
+		if (strcasecmp(name, prioritynames[i].c_name) == 0) {
+			return (prioritynames[i].c_val);
+		}
+	}
+	return (-1);
+}
+
+void ccs_read_logging(int ccsfd, char *name, int *debug, int *mode, int *facility, int *priority, char **file)
+{
+	char *val = NULL;
+	char tmppath[PATH_MAX];
+	int global_debug = 0;
+
+	if (!*debug) {
+		if (ccs_get(ccsfd, "/cluster/logging/@debug", &val) == 0) {
+			if(!strcmp(val, "on")) {
+				global_debug = 1;
+			} else
+			if(!strcmp(val, "off")) {
+				global_debug = 0;
+			}
+			free(val);
+			val = NULL;
+		}
+
+		memset(tmppath, 0, PATH_MAX);
+		snprintf(tmppath, PATH_MAX - 1, "/cluster/logging/logger_subsys[@subsys=\"%s\"]/@debug", name);
+		if (ccs_get(ccsfd, tmppath, &val) == 0) {
+			if(!strcmp(val, "on")) {
+				*debug = 1;
+			} else
+			if(!strcmp(val, "off")) { /* debug from cmdline/envvars override config */
+				*debug = 0;
+			}
+			free(val);
+			val = NULL;
+		} else {
+			*debug = global_debug; /* global debug overrides subsystem only if latter is not specified */
+			*priority = LOG_DEBUG;
+		}
+
+		memset(tmppath, 0, PATH_MAX);
+		snprintf(tmppath, PATH_MAX - 1, "/cluster/logging/logger_subsys[@subsys=\"%s\"]/@syslog_level", name);
+		if (ccs_get(ccsfd, tmppath, &val) == 0) {
+			*priority = priority_id_get (val);
+			if (*priority < 0)
+				*priority = SYSLOGLEVEL;
+
+			if (!*debug)
+				if (*priority == LOG_DEBUG)
+					*debug = 1;
+
+			free(val);
+			val = NULL;
+		}
+	} else
+		*priority = LOG_DEBUG;
+
+	if (ccs_get(ccsfd, "/cluster/logging/@to_stderr", &val) == 0) {
+		if(!strcmp(val, "yes")) {
+			*mode |= LOG_MODE_OUTPUT_STDERR;
+		} else
+		if(!strcmp(val, "no")) {
+			*mode &= ~LOG_MODE_OUTPUT_STDERR;
+		}
+		free(val);
+		val = NULL;
+	}
+
+	if (ccs_get(ccsfd, "/cluster/logging/@to_syslog", &val) == 0) {
+		if(!strcmp(val, "yes")) {
+			*mode |= LOG_MODE_OUTPUT_SYSLOG_THREADED;
+		} else
+		if(!strcmp(val, "no")) {
+			*mode &= ~LOG_MODE_OUTPUT_SYSLOG_THREADED;
+		}
+		free(val);
+		val = NULL;
+	}
+	if (ccs_get(ccsfd, "/cluster/logging/@to_file", &val) == 0) {
+		if(!strcmp(val, "yes")) {
+			*mode |= LOG_MODE_OUTPUT_FILE;
+		} else
+		if(!strcmp(val, "no")) {
+			*mode &= ~LOG_MODE_OUTPUT_FILE;
+		}
+		free(val);
+		val = NULL;
+	}
+	if (ccs_get(ccsfd, "/cluster/logging/@logfile", &val) == 0) {
+		*file = strdup(val);
+		free(val);
+		val = NULL;
+	}
+	if (ccs_get(ccsfd, "/cluster/logging/@syslog_facility", &val) == 0) {
+		*facility = facility_id_get (val);
+		if (*facility < 0)
+			*facility = SYSLOGFACILITY;
+
+		free(val);
+		val = NULL;
+	}
+
+	return;
+}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]