ctdb-event: Add event daemon config file options
authorAmitay Isaacs <amitay@gmail.com>
Mon, 23 Apr 2018 04:02:43 +0000 (14:02 +1000)
committerAmitay Isaacs <amitay@samba.org>
Thu, 17 May 2018 02:04:30 +0000 (04:04 +0200)
Signed-off-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Martin Schwenke <martin@meltin.net>
ctdb/event/event_conf.c [new file with mode: 0644]
ctdb/event/event_conf.h [new file with mode: 0644]
ctdb/wscript

diff --git a/ctdb/event/event_conf.c b/ctdb/event/event_conf.c
new file mode 100644 (file)
index 0000000..33bfc7c
--- /dev/null
@@ -0,0 +1,85 @@
+/*
+   CTDB event daemon
+
+   Copyright (C) Amitay Isaacs  2018
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "replace.h"
+#include "system/filesys.h"
+#include "system/dir.h"
+
+#include "lib/util/debug.h"
+
+#include "common/conf.h"
+#include "common/path.h"
+
+#include "event/event_conf.h"
+
+static bool event_conf_validate_debug_script(const char *key,
+                                            const char *old_script,
+                                            const char *new_script,
+                                            enum conf_update_mode mode)
+{
+       char script[PATH_MAX];
+       char script_path[PATH_MAX];
+       struct stat st;
+       size_t len;
+       int ret;
+
+       len = strlcpy(script, new_script, sizeof(script));
+       if (len >= sizeof(script)) {
+               D_ERR("debug script name too long\n");
+               return false;
+       }
+
+       ret = snprintf(script_path,
+                      sizeof(script_path),
+                      "%s/%s",
+                      path_etcdir(),
+                      basename(script));
+       if (ret >= sizeof(script_path)) {
+               D_ERR("debug script path too long\n");
+               return false;
+       }
+
+       ret = stat(script_path, &st);
+       if (ret == -1) {
+               D_ERR("debug script %s does not exist\n", script_path);
+               return false;
+       }
+
+       if (! S_ISREG(st.st_mode)) {
+               D_ERR("debug script %s is not a file\n", script_path);
+               return false;
+       }
+       if (! (st.st_mode & S_IXUSR)) {
+               D_ERR("debug script %s is not executable\n", script_path);
+               return false;
+       }
+
+       return true;
+}
+
+void event_conf_init(struct conf_context *conf)
+{
+       conf_define_section(conf, EVENT_CONF_SECTION, NULL);
+
+       conf_define_string(conf,
+                          EVENT_CONF_SECTION,
+                          EVENT_CONF_DEBUG_SCRIPT,
+                          NULL,
+                          event_conf_validate_debug_script);
+}
diff --git a/ctdb/event/event_conf.h b/ctdb/event/event_conf.h
new file mode 100644 (file)
index 0000000..964a18a
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+   CTDB event daemon
+
+   Copyright (C) Amitay Isaacs  2018
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef __CTDB_EVENT_CONF_H__
+#define __CTDB_EVENT_CONF_H__
+
+#include "common/conf.h"
+
+#define EVENT_CONF_SECTION             "event"
+
+#define EVENT_CONF_DEBUG_SCRIPT                "debug script"
+
+void event_conf_init(struct conf_context *conf);
+
+#endif /* __CTDB_EVENT_CONF_H__ */
index 0cf9409d9e8a7e7d0afe2b2ba004af4bf0c94818..8c4c97b19ccbc127b94e4dd39c1b0e2a07e11b95 100644 (file)
@@ -464,6 +464,10 @@ def build(bld):
                      deps='''ctdb-util samba-util talloc replace popt''',
                      install_path='${CTDB_HELPER_BINDIR}')
 
+    bld.SAMBA_SUBSYSTEM('ctdb-event-conf',
+                        source='event/event_conf.c',
+                        deps='ctdb-util')
+
     bld.SAMBA_BINARY('ctdb-config',
                      source='common/conf_tool.c',
                      cflags='-DCTDB_CONF_TOOL',