dlm: master - dlm_controld: update logging

David Teigland teigland at fedoraproject.org
Thu Oct 6 16:32:41 UTC 2011


Gitweb:        http://git.fedorahosted.org/git/dlm.git?p=dlm.git;a=commitdiff;h=43931c355acc80658345a73c78ca866016938d32
Commit:        43931c355acc80658345a73c78ca866016938d32
Parent:        9a6125969490e49cd843b02feb23de1fc53c94ad
Author:        David Teigland <teigland at redhat.com>
AuthorDate:    Thu Oct 6 11:31:33 2011 -0500
Committer:     David Teigland <teigland at redhat.com>
CommitterDate: Thu Oct 6 11:31:33 2011 -0500

dlm_controld: update logging

don't bother logging from thread, other cleanups

Signed-off-by: David Teigland <teigland at redhat.com>
---
 dlm_controld/Makefile     |    2 +-
 dlm_controld/dlm_daemon.h |    2 +-
 dlm_controld/logging.c    |   54 ++++++++++++++++++++-------------------------
 dlm_controld/main.c       |   18 ++++++++++++--
 4 files changed, 41 insertions(+), 35 deletions(-)

diff --git a/dlm_controld/Makefile b/dlm_controld/Makefile
index 25b1ea4..7bd37a1 100644
--- a/dlm_controld/Makefile
+++ b/dlm_controld/Makefile
@@ -61,7 +61,7 @@ BIN_CFLAGS += -I../include -I../libdlm
 
 BIN_LDFLAGS += -Wl,-z,now -Wl,-z,relro -pie
 BIN_LDFLAGS += `xml2-config --libs`
-BIN_LDFLAGS += -lpthread -llogthread -lcpg -lconfdb -lcfg -lquorum -lfenced
+BIN_LDFLAGS += -lpthread -lrt -lcpg -lconfdb -lcfg -lquorum -lfenced
 
 LIB_CFLAGS += $(BIN_CFLAGS)
 LIB_LDFLAGS += -Wl,-z,relro -pie
diff --git a/dlm_controld/dlm_daemon.h b/dlm_controld/dlm_daemon.h
index 9c180d7..5d12296 100644
--- a/dlm_controld/dlm_daemon.h
+++ b/dlm_controld/dlm_daemon.h
@@ -271,6 +271,7 @@ void deadlk_confchg(struct lockspace *ls,
 /* main.c */
 int do_read(int fd, void *buf, size_t count);
 int do_write(int fd, void *buf, size_t count);
+uint64_t monotime(void);
 void client_dead(int ci);
 int client_add(int fd, void (*workfn)(int ci), void (*deadfn)(int ci));
 int client_fd(int ci);
@@ -319,7 +320,6 @@ void clear_plocks_data(struct lockspace *ls);
 /* logging.c */
 
 void init_logging(void);
-void setup_logging(void);
 void close_logging(void);
 void copy_log_dump(char *buf, int *len);
 void copy_log_dump_plock(char *buf, int *len);
diff --git a/dlm_controld/logging.c b/dlm_controld/logging.c
index cb3c7fb..bf1a0eb 100644
--- a/dlm_controld/logging.c
+++ b/dlm_controld/logging.c
@@ -1,14 +1,13 @@
 #include "dlm_daemon.h"
 
-static int log_mode;
 static int syslog_facility;
 static int syslog_priority;
 static int logfile_priority;
 static char logfile[PATH_MAX];
+static FILE *logfile_fp;
 
 void init_logging(void)
 {
-	log_mode = DEFAULT_LOG_MODE;
 	syslog_facility = DEFAULT_SYSLOG_FACILITY;
 	syslog_priority = DEFAULT_SYSLOG_PRIORITY;
 	logfile_priority = DEFAULT_LOGFILE_PRIORITY;
@@ -20,36 +19,22 @@ void init_logging(void)
 	if (cfgd_debug_logfile)
 		logfile_priority = LOG_DEBUG;
 
-	log_debug("logging mode %d syslog f %d p %d logfile p %d %s",
-		  log_mode, syslog_facility, syslog_priority,
-		  logfile_priority, logfile);
-
-	logt_init(DAEMON_NAME, log_mode, syslog_facility, syslog_priority,
-		  logfile_priority, logfile);
-}
-
-void setup_logging(void)
-{
-
-	/* TODO: look for settings for each of these in dlm.conf */
-	/*
-	ccs_read_logging(ccs_handle, DAEMON_NAME,
-			 &cfgd_debug_logfile, &log_mode,
-			 &syslog_facility, &syslog_priority,
-			 &logfile_priority, logfile);
-	*/
-
-	log_debug("logging mode %d syslog f %d p %d logfile p %d %s",
-		  log_mode, syslog_facility, syslog_priority,
-		  logfile_priority, logfile);
+	if (logfile[0]) {
+		logfile_fp = fopen(logfile, "a+");
+		if (logfile_fp != NULL) {
+			int fd = fileno(logfile_fp);
+			fcntl(fd, F_SETFD, fcntl(fd, F_GETFD, 0) | FD_CLOEXEC);
+		}
+	}
 
-	logt_conf(DAEMON_NAME, log_mode, syslog_facility, syslog_priority,
-		  logfile_priority, logfile);
+	openlog(DAEMON_NAME, LOG_CONS | LOG_PID, syslog_facility);
 }
 
 void close_logging(void)
 {
-	logt_exit();
+	closelog();
+	if (logfile_fp)
+		fclose(logfile_fp);
 }
 
 #define NAME_ID_SIZE 32
@@ -142,7 +127,7 @@ void log_level(char *name_in, uint32_t level_in, const char *fmt, ...)
 		snprintf(name, NAME_ID_SIZE, "%s ", name_in);
 
 	ret = snprintf(log_str + pos, len - pos, "%llu %s",
-		       (unsigned long long)time(NULL), name);
+		       (unsigned long long)monotime(), name);
 
 	pos += ret;
 
@@ -162,8 +147,17 @@ void log_level(char *name_in, uint32_t level_in, const char *fmt, ...)
 		log_save_str(level, pos - 1, log_dump, &log_point, &log_wrap);
 	if (plock)
 		log_save_str(level, pos - 1, log_dump_plock, &log_point_plock, &log_wrap_plock);
-	if (level)
-		logt_print(level, "%s", log_str);
+
+	if (level <= syslog_priority)
+		syslog(level, "%s", log_str);
+
+	if (level <= logfile_priority && logfile_fp) {
+		time_t logtime = time(NULL);
+		char tbuf[64];
+		strftime(tbuf, sizeof(tbuf), "%b %d %T", localtime(&logtime));
+		fprintf(logfile_fp, "%s %s", tbuf, log_str);
+		fflush(logfile_fp);
+	}
 
 	if (!daemon_debug_opt)
 		return;
diff --git a/dlm_controld/main.c b/dlm_controld/main.c
index 2be088a..e940fc0 100644
--- a/dlm_controld/main.c
+++ b/dlm_controld/main.c
@@ -62,6 +62,13 @@ int do_write(int fd, void *buf, size_t count)
 	return 0;
 }
 
+uint64_t monotime(void)
+{
+	struct timespec ts;
+	clock_gettime(CLOCK_MONOTONIC, &ts);
+	return ts.tv_sec;
+}
+
 static void client_alloc(void)
 {
 	int i;
@@ -871,8 +878,6 @@ static void loop(void)
 
 	setup_config(0);
 
-	setup_logging();
-
 	rv = check_uncontrolled_lockspaces();
 	if (rv < 0)
 		goto out;
@@ -1240,10 +1245,17 @@ int main(int argc, char **argv)
 			exit(EXIT_FAILURE);
 		}
 	}
-	fd = lockfile(RUNDIR, RUN_FILE_NAME);
+
 	init_logging();
+
+	fd = lockfile(RUNDIR, RUN_FILE_NAME);
+	if (fd < 0)
+		return fd;
+
 	log_level(NULL, LOG_INFO, "dlm_controld %s started", RELEASE_VERSION);
+
 	signal(SIGTERM, sigterm_handler);
+
 	set_scheduler();
 
 	loop();


More information about the cluster-commits mailing list