nsswitch:libwbclient - fix leak in wbcCtxPingDc2
[Samba.git] / ctdb / server / ctdb_config.c
blob72830278c4299fa0b95374792b28f7da99a6cbfa
1 /*
2 CTDB daemon config handling
4 Copyright (C) Martin Schwenke 2018
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, see <http://www.gnu.org/licenses/>.
20 #include "replace.h"
22 #include "lib/util/debug.h"
24 #include "common/conf.h"
25 #include "common/logging_conf.h"
26 #include "common/path.h"
28 #include "cluster/cluster_conf.h"
29 #include "database/database_conf.h"
30 #include "event/event_conf.h"
31 #include "failover/failover_conf.h"
32 #include "legacy_conf.h"
34 #include "ctdb_config.h"
36 struct ctdb_config ctdb_config;
38 static void setup_config_pointers(struct conf_context *conf)
41 * Cluster
44 conf_assign_string_pointer(conf,
45 CLUSTER_CONF_SECTION,
46 CLUSTER_CONF_TRANSPORT,
47 &ctdb_config.transport);
48 conf_assign_string_pointer(conf,
49 CLUSTER_CONF_SECTION,
50 CLUSTER_CONF_NODE_ADDRESS,
51 &ctdb_config.node_address);
52 conf_assign_string_pointer(conf,
53 CLUSTER_CONF_SECTION,
54 CLUSTER_CONF_CLUSTER_LOCK,
55 &ctdb_config.cluster_lock);
56 conf_assign_string_pointer(conf,
57 CLUSTER_CONF_SECTION,
58 CLUSTER_CONF_RECOVERY_LOCK,
59 &ctdb_config.recovery_lock);
60 conf_assign_integer_pointer(conf,
61 CLUSTER_CONF_SECTION,
62 CLUSTER_CONF_LEADER_TIMEOUT,
63 &ctdb_config.leader_timeout);
64 conf_assign_boolean_pointer(conf,
65 CLUSTER_CONF_SECTION,
66 CLUSTER_CONF_LEADER_CAPABILITY,
67 &ctdb_config.leader_capability);
70 * Database
73 conf_assign_string_pointer(conf,
74 DATABASE_CONF_SECTION,
75 DATABASE_CONF_VOLATILE_DB_DIR,
76 &ctdb_config.dbdir_volatile);
77 conf_assign_string_pointer(conf,
78 DATABASE_CONF_SECTION,
79 DATABASE_CONF_PERSISTENT_DB_DIR,
80 &ctdb_config.dbdir_persistent);
81 conf_assign_string_pointer(conf,
82 DATABASE_CONF_SECTION,
83 DATABASE_CONF_STATE_DB_DIR,
84 &ctdb_config.dbdir_state);
85 conf_assign_string_pointer(conf,
86 DATABASE_CONF_SECTION,
87 DATABASE_CONF_LOCK_DEBUG_SCRIPT,
88 &ctdb_config.lock_debug_script);
89 conf_assign_boolean_pointer(conf,
90 DATABASE_CONF_SECTION,
91 DATABASE_CONF_TDB_MUTEXES,
92 &ctdb_config.tdb_mutexes);
95 * Event
97 conf_assign_string_pointer(conf,
98 EVENT_CONF_SECTION,
99 EVENT_CONF_DEBUG_SCRIPT,
100 &ctdb_config.event_debug_script);
103 * Failover
105 conf_assign_boolean_pointer(conf,
106 FAILOVER_CONF_SECTION,
107 FAILOVER_CONF_DISABLED,
108 &ctdb_config.failover_disabled);
111 * Legacy
114 conf_assign_boolean_pointer(conf,
115 LEGACY_CONF_SECTION,
116 LEGACY_CONF_REALTIME_SCHEDULING,
117 &ctdb_config.realtime_scheduling);
118 conf_assign_boolean_pointer(conf,
119 LEGACY_CONF_SECTION,
120 LEGACY_CONF_LMASTER_CAPABILITY,
121 &ctdb_config.lmaster_capability);
122 conf_assign_boolean_pointer(conf,
123 LEGACY_CONF_SECTION,
124 LEGACY_CONF_START_AS_STOPPED,
125 &ctdb_config.start_as_stopped);
126 conf_assign_boolean_pointer(conf,
127 LEGACY_CONF_SECTION,
128 LEGACY_CONF_START_AS_DISABLED,
129 &ctdb_config.start_as_disabled);
130 conf_assign_string_pointer(conf,
131 LEGACY_CONF_SECTION,
132 LEGACY_CONF_SCRIPT_LOG_LEVEL,
133 &ctdb_config.script_log_level);
136 int ctdbd_config_load(TALLOC_CTX *mem_ctx,
137 struct conf_context **result)
139 struct conf_context *conf = NULL;
140 int ret = 0;
141 char *conf_file = NULL;
143 ret = conf_init(mem_ctx, &conf);
144 if (ret != 0) {
145 return ret;
148 logging_conf_init(conf, "NOTICE");
149 cluster_conf_init(conf);
150 database_conf_init(conf);
151 event_conf_init(conf);
152 failover_conf_init(conf);
153 legacy_conf_init(conf);
155 setup_config_pointers(conf);
157 if (! conf_valid(conf)) {
158 ret = EINVAL;
159 goto fail;
162 conf_file = path_config(conf);
163 if (conf_file == NULL) {
164 D_ERR("Memory allocation error\n");
165 ret = ENOMEM;
166 goto fail;
168 ret = conf_load(conf, conf_file, true);
169 /* Configuration file does not need to exist */
170 if (ret != 0 && ret != ENOENT) {
171 D_ERR("Failed to load configuration file %s\n", conf_file);
172 goto fail;
175 talloc_free(conf_file);
176 *result = conf;
178 return 0;
180 fail:
181 talloc_free(conf);
182 return ret;