smbtorture: add test smb2.dirleases.leases
[samba4-gss.git] / ctdb / event / event_config.c
blob616b5284d52231fac34f93af996a8f9689455767
1 /*
2 CTDB event daemon - config handling
4 Copyright (C) Amitay Isaacs 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 <talloc.h>
24 #include "common/path.h"
26 #include "conf/conf.h"
27 #include "conf/logging_conf.h"
28 #include "conf/event_conf.h"
30 #include "event/event_private.h"
32 struct event_config {
33 char *config_file;
34 struct conf_context *conf;
36 const char *logging_location;
37 const char *logging_loglevel;
38 const char *debug_script;
41 int event_config_init(TALLOC_CTX *mem_ctx, struct event_config **result)
43 struct event_config *config;
44 int ret;
45 bool ok;
47 config = talloc_zero(mem_ctx, struct event_config);
48 if (config == NULL) {
49 return ENOMEM;
52 config->config_file = path_config(config);
53 if (config->config_file == NULL) {
54 talloc_free(config);
55 return ENOMEM;
58 ret = conf_init(config, &config->conf);
59 if (ret != 0) {
60 talloc_free(config);
61 return ret;
64 logging_conf_init(config->conf, NULL);
66 conf_assign_string_pointer(config->conf,
67 LOGGING_CONF_SECTION,
68 LOGGING_CONF_LOCATION,
69 &config->logging_location);
70 conf_assign_string_pointer(config->conf,
71 LOGGING_CONF_SECTION,
72 LOGGING_CONF_LOG_LEVEL,
73 &config->logging_loglevel);
75 event_conf_init(config->conf);
77 conf_assign_string_pointer(config->conf,
78 EVENT_CONF_SECTION,
79 EVENT_CONF_DEBUG_SCRIPT,
80 &config->debug_script);
82 ok = conf_valid(config->conf);
83 if (!ok) {
84 talloc_free(config);
85 return EINVAL;
88 ret = conf_load(config->conf, config->config_file, true, true);
89 if (ret != 0 && ret != ENOENT) {
90 talloc_free(config);
91 return ret;
94 *result = config;
95 return 0;
98 const char *event_config_log_location(struct event_config *config)
100 return config->logging_location;
103 const char *event_config_log_level(struct event_config *config)
105 return config->logging_loglevel;
108 const char *event_config_debug_script(struct event_config *config)
110 return config->debug_script;
113 int event_config_reload(struct event_config *config)
115 int ret;
117 ret = conf_reload(config->conf);
118 if (ret != 0 && ret != ENOENT) {
119 return ret;
122 return 0;