From: Amitay Isaacs Date: Mon, 23 Apr 2018 04:02:43 +0000 (+1000) Subject: ctdb-event: Add event daemon config file options X-Git-Tag: ldb-1.4.0~186 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8831f6740e0892d296eaba91805f9d437ecbdb9a;p=thirdparty%2Fsamba.git ctdb-event: Add event daemon config file options Signed-off-by: Amitay Isaacs Reviewed-by: Martin Schwenke --- diff --git a/ctdb/event/event_conf.c b/ctdb/event/event_conf.c new file mode 100644 index 00000000000..33bfc7c5335 --- /dev/null +++ b/ctdb/event/event_conf.c @@ -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 . +*/ + +#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 index 00000000000..964a18a077e --- /dev/null +++ b/ctdb/event/event_conf.h @@ -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 . +*/ + +#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__ */ diff --git a/ctdb/wscript b/ctdb/wscript index 0cf9409d9e8..8c4c97b19cc 100644 --- a/ctdb/wscript +++ b/ctdb/wscript @@ -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',