diff options
author | Martin Schwenke <martin@meltin.net> | 2018-04-20 17:10:51 +1000 |
---|---|---|
committer | Amitay Isaacs <amitay@samba.org> | 2018-05-17 04:04:31 +0200 |
commit | 52d27012796474a3ce024a14d10d8c7eceff057c (patch) | |
tree | b6c3a85ff78e75670bd16e4b47554151512c6951 /ctdb/database | |
parent | dbdd49da23c78fa12af39f29277f38827b5a6942 (diff) | |
download | samba-52d27012796474a3ce024a14d10d8c7eceff057c.tar.gz |
ctdb-database: Define database configuration file options
Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
Diffstat (limited to 'ctdb/database')
-rw-r--r-- | ctdb/database/database_conf.c | 144 | ||||
-rw-r--r-- | ctdb/database/database_conf.h | 34 |
2 files changed, 178 insertions, 0 deletions
diff --git a/ctdb/database/database_conf.c b/ctdb/database/database_conf.c new file mode 100644 index 00000000000..0333ce0a0a5 --- /dev/null +++ b/ctdb/database/database_conf.c @@ -0,0 +1,144 @@ +/* + CTDB database config handling + + Copyright (C) Martin Schwenke 2018 + + database_conf_validate_lock_debug_script() based on + event_conf_validatye_debug_script(): + + 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 "lib/util/samba_util.h" + +#include "common/conf.h" +#include "common/path.h" + +#include "database_conf.h" + +#define DATABASE_CONF_VOLATILE_DB_DIR_DEFAULT CTDB_VARDIR "/volatile" +#define DATABASE_CONF_PERSISTENT_DB_DIR_DEFAULT CTDB_VARDIR "/persistent" +#define DATABASE_CONF_STATE_DB_DIR_DEFAULT CTDB_VARDIR "/state" + +static bool check_static_string_change(const char *key, + const char *old_value, + const char *new_value, + enum conf_update_mode mode) +{ + if (mode == CONF_MODE_RELOAD) { + if (strcmp(old_value, new_value) != 0) { + D_WARNING("Ignoring update of [%s] -> %s\n", + DATABASE_CONF_SECTION, + key); + } + } + + return true; +} + +static bool database_conf_validate_lock_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; + + if (new_script == NULL) { + return true; + } + + len = strlcpy(script, new_script, sizeof(script)); + if (len >= sizeof(script)) { + D_ERR("lock 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("lock debug script path too long\n"); + return false; + } + + ret = stat(script_path, &st); + if (ret == -1) { + D_ERR("lock debug script %s does not exist\n", script_path); + return false; + } + + if (! S_ISREG(st.st_mode)) { + D_ERR("lock debug script %s is not a file\n", script_path); + return false; + } + if (! (st.st_mode & S_IXUSR)) { + D_ERR("lock debug script %s is not executable\n", script_path); + return false; + } + + return true; +} + +static bool database_conf_validate_db_dir(const char *key, + const char *old_dir, + const char *new_dir, + enum conf_update_mode mode) +{ + if (! directory_exist(new_dir)) { + D_ERR("%s \"%s\" does not exist\n", key, new_dir); + return false; + } + + /* This sometimes warns but always returns true */ + return check_static_string_change(key, old_dir, new_dir, mode); +} + +void database_conf_init(struct conf_context *conf) +{ + conf_define_section(conf, DATABASE_CONF_SECTION, NULL); + + conf_define_string(conf, + DATABASE_CONF_SECTION, + DATABASE_CONF_VOLATILE_DB_DIR, + DATABASE_CONF_VOLATILE_DB_DIR_DEFAULT, + database_conf_validate_db_dir); + conf_define_string(conf, + DATABASE_CONF_SECTION, + DATABASE_CONF_PERSISTENT_DB_DIR, + DATABASE_CONF_PERSISTENT_DB_DIR_DEFAULT, + database_conf_validate_db_dir); + conf_define_string(conf, + DATABASE_CONF_SECTION, + DATABASE_CONF_STATE_DB_DIR, + DATABASE_CONF_STATE_DB_DIR_DEFAULT, + database_conf_validate_db_dir); + conf_define_string(conf, + DATABASE_CONF_SECTION, + DATABASE_CONF_LOCK_DEBUG_SCRIPT, + NULL, + database_conf_validate_lock_debug_script); +} diff --git a/ctdb/database/database_conf.h b/ctdb/database/database_conf.h new file mode 100644 index 00000000000..4891b0053b6 --- /dev/null +++ b/ctdb/database/database_conf.h @@ -0,0 +1,34 @@ +/* + CTDB database config handling + + Copyright (C) Martin Schwenke 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_DATABASE_CONF_H__ +#define __CTDB_DATABASE_CONF_H__ + +#include "common/conf.h" + +#define DATABASE_CONF_SECTION "database" + +#define DATABASE_CONF_VOLATILE_DB_DIR "volatile database directory" +#define DATABASE_CONF_PERSISTENT_DB_DIR "persistent database directory" +#define DATABASE_CONF_STATE_DB_DIR "state database directory" +#define DATABASE_CONF_LOCK_DEBUG_SCRIPT "lock debug script" + +void database_conf_init(struct conf_context *conf); + +#endif /* __CTDB_DATABASE_CONF_H__ */ |