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]

cluster: master - rgmanager: Fix up logging, part 1


Gitweb:        http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=d58630ca31e56b425d2cd8d38d6db4efe7218c26
Commit:        d58630ca31e56b425d2cd8d38d6db4efe7218c26
Parent:        fb7e7af39de61fcf1b8fcd8213183eb1e4c1d4dc
Author:        Lon Hohberger <lhh@redhat.com>
AuthorDate:    Fri Dec 12 14:21:13 2008 -0500
Committer:     Lon Hohberger <lhh@redhat.com>
CommitterDate: Fri Dec 12 16:54:19 2008 -0500

rgmanager: Fix up logging, part 1

* Let clulog report the parent resource-agent
* Use ccs_read_logging API
* Don't break old configs using rm/@log_level or log_facility
---
 rgmanager/include/logging.h    |    9 +-
 rgmanager/src/clulib/Makefile  |    4 +-
 rgmanager/src/clulib/logging.c |  237 ++++++++++------------------------------
 rgmanager/src/daemons/Makefile |    7 +-
 rgmanager/src/daemons/main.c   |    2 +-
 rgmanager/src/utils/Makefile   |    4 +-
 rgmanager/src/utils/clulog.c   |   32 +++++-
 7 files changed, 102 insertions(+), 193 deletions(-)

diff --git a/rgmanager/include/logging.h b/rgmanager/include/logging.h
index 22a7ccb..4db57db 100644
--- a/rgmanager/include/logging.h
+++ b/rgmanager/include/logging.h
@@ -1,10 +1,15 @@
 #ifndef _LOGGING_H
 #define _LOGGING_H
 
-#include <corosync/engine/logsys.h>
+/* #include <corosync/engine/logsys.h>*/
+#include <liblogthread.h>
 
-void init_logging(int foreground, int debugging);
+void init_logging(char *name, int foreground, int debugging);
 void setup_logging(int ccs_handle);
 void close_logging(void);
 
+#ifndef log_printf
+#define log_printf logt_print
+#endif
+
 #endif
diff --git a/rgmanager/src/clulib/Makefile b/rgmanager/src/clulib/Makefile
index 85fd4fc..f8f8518 100644
--- a/rgmanager/src/clulib/Makefile
+++ b/rgmanager/src/clulib/Makefile
@@ -21,14 +21,14 @@ OBJS3= msgtest.o
 
 CFLAGS += -Werror -Wstrict-prototypes -Wshadow -fPIC -D_GNU_SOURCE
 CFLAGS += -I${ccsincdir} -I${cmanincdir} -I${dlmincdir}
-CFLAGS += -L${corosyncincdir}
+CFLAGS += -L${logtincdir}
 CFLAGS += -I$(S)/../../include
 CFLAGS += -I${incdir}
 
 LDFLAGS += -L${cmanlibdir} -lcman 
 LDFLAGS += -L. -lclulib -llalloc
 LDFLAGS += -lpthread
-LDFLAGS += -L${corosynclibdir} -llogsys
+LDFLAGS += -L${logtlibdir} -llogthread
 LDFLAGS += -L${libdir}
 
 ${TARGET1}: ${OBJS1}
diff --git a/rgmanager/src/clulib/logging.c b/rgmanager/src/clulib/logging.c
index 503555f..b7bdac1 100644
--- a/rgmanager/src/clulib/logging.c
+++ b/rgmanager/src/clulib/logging.c
@@ -1,4 +1,7 @@
+#include <stdio.h>
 #include <stdlib.h>
+#define SYSLOG_NAMES
+#include <syslog.h>
 #include <logging.h>
 #include <unistd.h>
 #include <string.h>
@@ -7,17 +10,17 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <ccs.h>
+#include <limits.h>
 
 #define DAEMON_NAME "rgmanager"
+static char daemon_name[PATH_MAX];
 
 /* default: errors go to syslog (/var/log/messages) and <daemon>.log
    logging/debug=on: errors continue going to syslog (/var/log/messages)
    and <daemon>.log, debug messages are added to <daemon>.log. */
 
-#define DEFAULT_MODE		LOG_MODE_OUTPUT_SYSLOG_THREADED | \
-				LOG_MODE_OUTPUT_FILE | \
-				LOG_MODE_NOSUBSYS | \
-				LOG_MODE_FILTER_DEBUG_FROM_SYSLOG
+#define DEFAULT_MODE		LOG_MODE_OUTPUT_SYSLOG| \
+				LOG_MODE_OUTPUT_FILE
 static int default_mode = DEFAULT_MODE;
 
 #define DEFAULT_FACILITY	SYSLOGFACILITY /* cluster config setting */
@@ -26,208 +29,84 @@ static int default_priority = DEFAULT_PRIORITY;
 
 #define DEFAULT_FILE		LOGDIR "/" DAEMON_NAME ".log"
 
-#define DAEMON_LEVEL_PATH "/cluster/logging/logger_subsys[@subsys=\"rgmanager\"]/@syslog_level"
-#define DAEMON_DEBUG_PATH "/cluster/logging/logger_subsys[@subsys=\"rgmanager\"]/@debug"
-
-/* Read cluster.conf settings and convert them into logsys values.
-   If no cluster.conf setting exists, the default that was used in
-   logsys_init() is used.
-
-   mode from
-   "/cluster/logging/@to_stderr"
-   "/cluster/logging/@to_syslog"
-   "/cluster/logging/@to_file"
-
-   facility from
-   "/cluster/logging/@syslog_facility"
-
-   priority from
-   "/cluster/logging/logger_subsys[@subsys=\"prog_name\"]/@syslog_level"
-
-   file from
-   "/cluster/logging/@logfile"
 
-   debug from
-   "/cluster/logging/@debug"
-   "/cluster/logging/logger_subsys[@subsys=\"prog_name\"]/@debug"
-*/
-static void
-read_ccs_name(int ccs_handle, char *path, char *name, size_t max)
+void
+init_logging(char *name, int foreground, int default_prio)
 {
-	char *str;
-	int error;
-
-	name[max-1] = 0;
-
-	error = ccs_get(ccs_handle, path, &str);
-	if (error || !str)
-		return;
+	if (!name)
+		name = DAEMON_NAME;
 
-	strncpy(name, str, max-1);
+	strncpy(daemon_name, name, PATH_MAX);
 
-	free(str);
+	if (foreground)
+		default_mode |= LOG_MODE_OUTPUT_STDERR;
+	if (default_prio >= 0)
+		default_priority = default_prio;
+	logt_init(name, default_mode, DEFAULT_FACILITY,
+		  DEFAULT_PRIORITY, DEFAULT_PRIORITY, DEFAULT_FILE);
 }
 
 
-static int
-read_ccs_yesno(int ccs_handle, char *path)
+int
+ccs_read_old_logging(int ccsfd, int *facility, int *priority)
 {
-	char *str = NULL;
-	int error;
-	int ret = -1;
-
-	error = ccs_get(ccs_handle, path, &str);
-	if (error)
-		goto out;
-
-	if ((!strcasecmp(str, "yes")) ||
-	    (!strcasecmp(str, "true")) ||
-	    (atoi(str) > 0)) {
-		ret = 1;
+	char query[256];
+	char *val;
+	int x, ret = 0;
+
+	/* Get log log_facility */
+	snprintf(query, sizeof(query), "/cluster/rm/@log_facility");
+	if (ccs_get(ccsfd, query, &val) == 0) {
+		for (x = 0; facilitynames[x].c_name; x++) {
+			if (strcasecmp(val, facilitynames[x].c_name))
+				continue;
+			*facility = facilitynames[x].c_val;
+			ret = 1;
+			break;
+		}
+		free(val);
 	}
 
-	if ((!strcasecmp(str, "no")) ||
-	    (!strcasecmp(str, "false")) ||
-	    (atoi(str) == 0)) {
-		ret = 0;
+	/* Get log level */
+	snprintf(query, sizeof(query), "/cluster/rm/@log_level");
+	if (ccs_get(ccsfd, query, &val) == 0) {
+		*priority = atoi(val);
+		free(val);
+		if (*priority < 0)
+			*priority = DEFAULT_PRIORITY;
+		else
+			ret = 1;
 	}
 
-out:
-	if (str) 
-		free(str);
 	return ret;
 }
 
 
-static int
-read_ccs_logging(int ccs_handle, int *mode, int *facility, int *priority,
-		 char *file)
-{
-	int val;
-	int m = 0, f = 0, p = 0;
-	char name[PATH_MAX];
-
-	/*
-	 * mode
-	 */
-
-	m = default_mode;
-	val = read_ccs_yesno(ccs_handle, "/cluster/logging/@to_stderr");
-	if (val == 1)
-		m |= LOG_MODE_OUTPUT_STDERR;
-	else if (val == 0)
-		m &= ~LOG_MODE_OUTPUT_STDERR;
-
-	val = read_ccs_yesno(ccs_handle, "/cluster/logging/@to_stderr");
-	if (val == 1)
-		m |= LOG_MODE_OUTPUT_SYSLOG_THREADED;
-	else if (val == 0)
-		m &= ~LOG_MODE_OUTPUT_SYSLOG_THREADED;
-
-	val = read_ccs_yesno(ccs_handle, "/cluster/logging/@to_file");
-	if (val == 1)
-		m |= LOG_MODE_OUTPUT_FILE;
-	else if (val == 0)
-		m &= ~LOG_MODE_OUTPUT_FILE;
-
-	*mode = m;
-
-	/*
-	 * facility
-	 */
-
-	f = DEFAULT_FACILITY;
-
-	memset(name, 0, sizeof(name));
-	read_ccs_name(ccs_handle, "/cluster/logging/@syslog_facility", name, sizeof(name));
-
-	if (name[0]) {
-		val = logsys_facility_id_get(name);
-		if (val >= 0)
-			f = val;
-	}
-
-	*facility = f;
-
-	/*
-	 * priority
-	 */
-
-	p = DEFAULT_PRIORITY;
-
-	memset(name, 0, sizeof(name));
-	read_ccs_name(ccs_handle, DAEMON_LEVEL_PATH, name, sizeof(name));
-
-	if (name[0]) {
-		val = logsys_priority_id_get(name);
-		if (val >= 0)
-			p = val;
-	}
-
-	*priority = p;
-
-	/*
-	 * file
-	 */
-
-	strcpy(file, DEFAULT_FILE);
-
-	memset(name, 0, sizeof(name));
-	read_ccs_name(ccs_handle, "/cluster/logging/@logfile", name, sizeof(name));
-
-	if (name[0])
-		strcpy(file, name);
-
-	/*
-	 * debug
-	 */
-	memset(name, 0, sizeof(name));
-	read_ccs_name(ccs_handle, "/cluster/logging/@debug", name, sizeof(name));
-
-#if 0
-	if (!strcmp(name, "on"))
-		cfgd_debug_logsys = 1;
-
-	memset(name, 0, sizeof(name));
-	read_ccs_name(ccs_handle, DAEMON_DEBUG_PATH, name);
-
-	if (!strcmp(name, "on"))
-		cfgd_debug_logsys = 1;
-	else if (!strcmp(name, "off"))
-		cfgd_debug_logsys = 0;
-#endif
-	return 0;
-}
-
-/* initial settings until we can read cluster.conf logging settings from ccs */
-
-void
-init_logging(int foreground, int default_prio)
-{
-	if (foreground)
-		default_mode |= LOG_MODE_OUTPUT_STDERR;
-	if (default_prio >= 0)
-		default_priority = default_prio;
-	logsys_init(DAEMON_NAME, default_mode, DEFAULT_FACILITY,
-		    DEFAULT_PRIORITY, DEFAULT_FILE);
-}
-
 /* this function is also called when we get a cman config-update event */
 void
 setup_logging(int ccs_handle)
 {
-	int mode, facility, priority;
+	int mode = DEFAULT_MODE;
+	int facility = DEFAULT_FACILITY;
+	int loglevel = DEFAULT_PRIORITY, filelevel = DEFAULT_PRIORITY;
+	int debug = 0;
 	char file[PATH_MAX];
 
 	memset(file, 0, PATH_MAX);
+	snprintf(file, sizeof(file)-1, DEFAULT_FILE);
+	if (ccs_read_old_logging(ccs_handle, &facility, &loglevel))
+		filelevel = loglevel;
 
-	read_ccs_logging(ccs_handle, &mode, &facility, &priority, file);
-	logsys_conf(DAEMON_NAME, mode, facility, priority, file);
+	ccs_read_logging(ccs_handle, (char *)DAEMON_NAME, &debug, &mode,
+        		 &facility, &loglevel, &filelevel, (char *)file);
+
+	/* clulog uses rgmanager's config but getppid()'s name */
+	logt_conf(daemon_name, mode, facility, loglevel,
+	    	      filelevel, file);
 }
 
 void
 close_logging(void)
 {
-	logsys_exit();
+	logt_exit();
 }
-
diff --git a/rgmanager/src/daemons/Makefile b/rgmanager/src/daemons/Makefile
index 70bfc1e..edad463 100644
--- a/rgmanager/src/daemons/Makefile
+++ b/rgmanager/src/daemons/Makefile
@@ -21,6 +21,7 @@ OBJS1=	depends.o \
 	reslist.o \
 	resrules.o \
 	restree.o \
+	restart_counter.o \
 	rg_event.o \
 	rg_forward.o \
 	rg_locks.o \
@@ -37,8 +38,8 @@ OBJS2=	test-noccs.o
 OBJS3=	dtest-noccs.o
 
 SHAREDOBJS=	depends-noccs.o \
-		restart_counter.o \
 		fo_domain-noccs.o \
+		restart_counter.o \
 		reslist-noccs.o \
 		resrules-noccs.o \
 		restree-noccs.o \
@@ -47,7 +48,7 @@ SHAREDOBJS=	depends-noccs.o \
 
 CFLAGS += -DSHAREDIR=\"${sharedir}\"
 CFLAGS += -Werror -Wstrict-prototypes -Wshadow -fPIC
-CFLAGS += -I${ccsincdir} -I${cmanincdir} -I${dlmincdir} -I${corosyncincdir}
+CFLAGS += -I${ccsincdir} -I${cmanincdir} -I${dlmincdir} -I${logtincdir}
 CFLAGS += `xml2-config --cflags` -I${readlineincdir} -I${slangincdir}
 CFLAGS += -I$(S)/../../include
 CFLAGS += -I${incdir}
@@ -59,7 +60,7 @@ LDFLAGS += -L${libdir}
 
 CCS_LDFLAGS += -L${ccslibdir} -lccs 
 CMAN_LDFLAGS += -L${cmanlibdir} -lcman
-LOGSYS_LDFLAGS += -L${corosynclibdir} -llogsys
+LOGSYS_LDFLAGS += -L${logtlibdir} -llogthread
 DLM_LDFLAGS += -L${dlmlibdir} -ldlm
 XML2_LDFLAGS += `xml2-config --libs`
 SLANG_LDFLAGS += -L${slanglibdir} -lslang
diff --git a/rgmanager/src/daemons/main.c b/rgmanager/src/daemons/main.c
index 49d208f..d40a77b 100644
--- a/rgmanager/src/daemons/main.c
+++ b/rgmanager/src/daemons/main.c
@@ -1001,7 +1001,7 @@ main(int argc, char **argv)
 		unblock_signal(SIGSEGV);
 	}
 
-	init_logging(foreground, (debug? LOG_LEVEL_DEBUG : SYSLOGLEVEL));
+	init_logging(NULL, foreground, (debug? LOG_DEBUG : SYSLOGLEVEL));
 	clu_initialize(&clu);
 	if (cman_init_subsys(clu) < 0) {
 		perror("cman_init_subsys");
diff --git a/rgmanager/src/utils/Makefile b/rgmanager/src/utils/Makefile
index a24b4eb..a458c6a 100644
--- a/rgmanager/src/utils/Makefile
+++ b/rgmanager/src/utils/Makefile
@@ -19,7 +19,7 @@ DISABLEDTARGETS= cluarp
 
 CFLAGS += -Werror -Wstrict-prototypes -Wshadow -fPIC -D_GNU_SOURCE
 CFLAGS += -I${ccsincdir} -I${cmanincdir} -I${dlmincdir}
-CFLAGS += -I${corosyncincdir} -I${ncursesincdir}
+CFLAGS += -I${logtincdir} -I${ncursesincdir}
 CFLAGS += -I$(S)/../../include
 CFLAGS += -I${incdir}
 
@@ -30,7 +30,7 @@ LDDEPS += ../clulib/libclulib.a
 
 CCS_LDFLAGS += -L${ccslibdir} -lccs
 CMAN_LDFLAGS += -L${cmanlibdir} -lcman
-LOGSYS_LDFLAGS += -L${corosynclibdir} -llogsys
+LOGSYS_LDFLAGS += -L${logtlibdir} -llogthread
 NCURSES_LDFLAGS += -L${ncurseslibdir} -lncurses
 PTHREAD_LDFLAGS += -lpthread 
 
diff --git a/rgmanager/src/utils/clulog.c b/rgmanager/src/utils/clulog.c
index 7c0d483..752233d 100644
--- a/rgmanager/src/utils/clulog.c
+++ b/rgmanager/src/utils/clulog.c
@@ -1,14 +1,18 @@
 /** @file
  * Utility for logging arbitrary strings to the cluster log file via syslog.
  *
- * Author: Jeff Moyer <jmoyer at redhat.com>
+ * Author: Lon Hohberger <lhh at redhat.com>
+ * Based on original code by: Jeff Moyer <jmoyer at redhat.com>
  */
 #include <stdio.h>
 #include <stdlib.h>
 #include <errno.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <limits.h>
+#include <libgen.h>
 #include <getopt.h>
 #include <string.h>
-#include <corosync/engine/logsys.h>
 #include <ccs.h>
 #include <logging.h>
 
@@ -20,6 +24,26 @@ usage(char *progname)
 }
 
 
+char *
+log_name(void)
+{
+	char lnk[PATH_MAX];
+	static char file[PATH_MAX];
+
+	snprintf(lnk, sizeof(lnk), "/proc/%d/exe", getppid());
+
+	printf("%s\n", lnk);
+
+	if (readlink(lnk, file, sizeof(file)) < 0) {
+		perror("readlink");
+		return NULL;
+	}
+	printf("%s\n", basename(file));
+
+	return basename(file);
+}
+
+
 int
 main(int argc, char **argv)
 {
@@ -44,12 +68,12 @@ main(int argc, char **argv)
 	if (severity < 0)
 		severity = SYSLOGLEVEL;
 
-	init_logging(1, severity);
+	init_logging(log_name(), 1, severity);
 	ccsfd = ccs_connect();
 	setup_logging(ccsfd);
 	ccs_disconnect(ccsfd);
 
-	log_printf(severity, "%s", logmsg);
+	log_printf(severity, "%s\n", logmsg);
 
 	close_logging();
 	return 0;


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