2 * Copyright (C) 2013 Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 * SPDX-License-Identifier: GPL-2.0-only
11 #include <common/config/ini.h>
12 #include <common/config/config-session-abi.h>
13 #include <common/macros.h>
17 /* section is NULL if the entry is not in a section */
23 struct config_load_session_override_attr
{
30 /* Instance of a configuration writer. */
34 * A config_entry_handler_cb receives config_entry structures belonging to the
35 * sections the handler has been registered to.
37 * The config_entry and its members are only valid for the duration of the call
38 * and must not be freed.
40 * config_entry_handler_cb may return negative value to indicate an error in
41 * the configuration file.
43 typedef int (*config_entry_handler_cb
)(const struct config_entry
*, void *);
46 * Read a section's entries in an INI configuration file.
48 * path may be NULL, in which case the following paths will be tried:
49 * 1) $HOME/.lttng/lttng.conf
50 * 2) /etc/lttng/lttng.conf
52 * handler will only be called with entries belonging to the provided section.
53 * If section is NULL, all entries will be relayed to handler. If section is
54 * "", only the global entries are relayed.
56 * Returns 0 on success. Negative values are error codes. If the return value
57 * is positive, it represents the line number on which a parsing error occurred.
59 int config_get_section_entries(const char *path
, const char *section
,
60 config_entry_handler_cb handler
, void *user_data
);
63 * Parse a configuration value.
65 * This function expects either an unsigned integer or a boolean text option.
66 * The following strings are recognized: true, yes, on, false, no and off.
68 * Returns either the value of the parsed integer, or 0/1 if a boolean text
69 * string was recognized. Negative values indicate an error.
71 int config_parse_value(const char *value
);
74 * Create an instance of a configuration writer.
76 * fd_output File to which the XML content must be written. fd_output is
77 * owned by the caller.
79 * indent If other than 0 the XML will be pretty printed
80 * with indentation and newline.
82 * Returns an instance of a configuration writer on success, NULL on
85 struct config_writer
*config_writer_create(int fd_output
, int indent
);
88 * Destroy an instance of a configuration writer.
90 * writer An instance of a configuration writer.
92 * Returns zero if the XML document could be closed cleanly. Negative values
95 int config_writer_destroy(struct config_writer
*writer
);
98 * Open an element tag.
100 * writer An instance of a configuration writer.
102 * element_name Element tag name.
104 * Returns zero if the XML element could be opened.
105 * Negative values indicate an error.
107 int config_writer_open_element(struct config_writer
*writer
,
108 const char *element_name
);
111 * Write an element tag attribute.
113 * writer An instance of a configuration writer.
115 * name Attribute name.
117 * Returns zero if the XML element's attribute could be written.
118 * Negative values indicate an error.
120 int config_writer_write_attribute(struct config_writer
*writer
,
121 const char *name
, const char *value
);
124 * Close the current element tag.
126 * writer An instance of a configuration writer.
128 * Returns zero if the XML document could be closed cleanly.
129 * Negative values indicate an error.
131 int config_writer_close_element(struct config_writer
*writer
);
134 * Write an element of type unsigned int.
136 * writer An instance of a configuration writer.
138 * element_name Element name.
140 * value Unsigned int value of the element
142 * Returns zero if the element's value could be written.
143 * Negative values indicate an error.
145 int config_writer_write_element_unsigned_int(struct config_writer
*writer
,
146 const char *element_name
, uint64_t value
);
149 * Write an element of type signed int.
151 * writer An instance of a configuration writer.
153 * element_name Element name.
155 * value Signed int value of the element
157 * Returns zero if the element's value could be written.
158 * Negative values indicate an error.
160 int config_writer_write_element_signed_int(struct config_writer
*writer
,
161 const char *element_name
, int64_t value
);
164 * Write an element of type boolean.
166 * writer An instance of a configuration writer.
168 * element_name Element name.
170 * value Boolean value of the element
172 * Returns zero if the element's value could be written.
173 * Negative values indicate an error.
175 int config_writer_write_element_bool(struct config_writer
*writer
,
176 const char *element_name
, int value
);
179 * Write an element of type string.
181 * writer An instance of a configuration writer.
183 * element_name Element name.
185 * value String value of the element
187 * Returns zero if the element's value could be written.
188 * Negative values indicate an error.
190 int config_writer_write_element_string(struct config_writer
*writer
,
191 const char *element_name
, const char *value
);
194 * Write an element of type double.
196 * writer An instance of a configuration writer.
198 * element_name Element name.
200 * value Double value of the element
202 * Returns zero if the element's value could be written.
203 * Negative values indicate an error.
205 int config_writer_write_element_double(struct config_writer
*writer
,
206 const char *element_name
,
210 * Load session configurations from a file.
212 * path Path to an LTTng session configuration file. All *.lttng files
213 * will be loaded if path is a directory. If path is NULL, the default
214 * paths will be searched in the following order:
215 * 1) $HOME/.lttng/sessions
216 * 2) /etc/lttng/sessions
218 * session_name Name of the session to load. Will load all
219 * sessions from path if NULL.
221 * overwrite Overwrite current session configuration if it exists.
222 * autoload Tell to load the auto session(s).
223 * overrides The override attribute structure specifying override parameters.
225 * Returns zero if the session could be loaded successfully. Returns
226 * a negative LTTNG_ERR code on error.
228 int config_load_session(const char *path
, const char *session_name
,
229 int overwrite
, unsigned int autoload
,
230 const struct config_load_session_override_attr
*overrides
);
232 #endif /* _CONFIG_H */