[op5-users] [PATCH] Add configuration option "ipc_binlog" for configurable binlog path.

Sean Millichamp sean at bruenor.org
Mon Nov 2 21:43:07 CET 2009


This adds a new configuration option "ipc_binlog" allows the
specification of the path where binlogs are written to disk.
This is configurable in both the module and daemon configuration
groups.  It also checks to make sure that the path is usable by
performing a test open on the path to help ensure configuration
problems are caught at start-time instead of when it actually
tries to write to the binlogs.
---
 ipc.c    |   52 ++++++++++++++++++++++++++++++++++++++++++++++++++--
 module.c |    2 ++
 2 files changed, 52 insertions(+), 2 deletions(-)

diff --git a/ipc.c b/ipc.c
index a0f1cb8..7e8ca64 100644
--- a/ipc.c
+++ b/ipc.c
@@ -9,6 +9,7 @@ static char *debug_write, *debug_read;
 static int listen_sock = -1; /* for bind() and such */
 static int ipc_sock = -1; /* once connected, we operate on this */
 static char *ipc_sock_path;
+static char *ipc_binlog_path;
 static merlin_event_counter ipc_events;
 
 static time_t last_connect_attempt;
@@ -100,6 +101,46 @@ static int ipc_set_sock_path(const char *path)
 	return 0;
 }
 
+static int ipc_set_binlog_path(const char *path)
+{
+	int result;
+
+	/* the binlog-path will be set both from module and daemon,
+	   so path must be absolute */
+	if (*path != '/') {
+		lerr("ipc_binlog path must be absolute");
+		return -1;
+	}
+
+	if (strlen(path) > UNIX_PATH_MAX)
+		return -1;
+
+	if (path[strlen(path)-1] == '/') {
+		lerr("ipc_binlog must not end in trailing slash");
+		return -1;
+	}
+
+	xfree(ipc_binlog_path);
+
+	ipc_binlog_path = strdup(path);
+	if (!ipc_binlog_path) {
+		lerr("ipc_binlog_set_path: could not strdup path, out of memory?");
+		return -1;
+	}
+
+	/* Test to make sure that the path will be usable when we need it. */
+	result = open(path, O_CREAT|O_APPEND, S_IRUSR|S_IWUSR);
+	if (result < 0) {
+		lerr("Error opening '%s' for writing, failed with error: %s",
+		     path, strerror(errno));
+		return -1;
+	}
+	close(result);
+	unlink(path);
+
+	return 0;
+}
+
 int ipc_grok_var(char *var, char *val)
 {
 	if (!val)
@@ -108,6 +149,9 @@ int ipc_grok_var(char *var, char *val)
 	if (!strcmp(var, "ipc_socket"))
 		return !ipc_set_sock_path(val);
 
+	if (!strcmp(var, "ipc_binlog"))
+		return !ipc_set_binlog_path(val);
+
 	if (!strcmp(var, "ipc_debug_write")) {
 		debug_write = strdup(val);
 		return 1;
@@ -126,8 +170,12 @@ int ipc_binlog_add(merlin_event *pkt)
 	if (!ipc_binlog) {
 		char *path;
 
-		asprintf(&path, "/opt/monitor/op5/merlin/binlogs/ipc.%s.binlog",
-				 is_module ? "module" : "daemon");
+		if (!ipc_binlog_path) {
+			asprintf(&path, "/opt/monitor/op5/merlin/binlogs/ipc.%s.binlog",
+					 is_module ? "module" : "daemon");
+		} else {
+			path = strdup(ipc_binlog_path);
+		}
 
 		/* 1MB in memory, 100MB on disk */
 		ipc_binlog = binlog_create(path, 1 << 20, 100 << 20, BINLOG_UNLINK);
diff --git a/module.c b/module.c
index 152acde..115f4d0 100644
--- a/module.c
+++ b/module.c
@@ -233,6 +233,8 @@ static void grok_module_compound(struct cfg_comp *comp)
 			continue;
 		if (log_grok_var(v->key, v->value))
 			continue;
+		if (ipc_grok_var(v->key, v->value))
+			continue;
 
 		cfg_error(comp, comp->vlist[i], "Unknown variable");
 	}
-- 
1.6.2.5



More information about the op5-users mailing list