X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fcommon%2Fconfig%2Fsession-config.c;h=416f9046ebb702cb4ac0fb3f87633293ecb378b7;hb=a0377dfefe40662ba7d68617bce6ff467114136c;hp=37c5ce383962e1b278e150a9dfac0a063998fd4e;hpb=d37ac3cdc4fe21f117edfb829db4d0eb7cf914a1;p=lttng-tools.git diff --git a/src/common/config/session-config.c b/src/common/config/session-config.c index 37c5ce383..416f9046e 100644 --- a/src/common/config/session-config.c +++ b/src/common/config/session-config.c @@ -7,7 +7,6 @@ #include "lttng/tracker.h" #define _LGPL_SOURCE -#include #include #include #include @@ -260,7 +259,7 @@ static int config_entry_handler_filter(struct handler_filter_args *args, int ret = 0; struct config_entry entry = { section, name, value }; - assert(args); + LTTNG_ASSERT(args); if (!section || !name || !value) { ret = -EIO; @@ -410,7 +409,7 @@ static xmlChar *encode_string(const char *in_str) xmlCharEncodingHandlerPtr handler; int out_len, ret, in_len; - assert(in_str); + LTTNG_ASSERT(in_str); handler = xmlFindCharEncodingHandler(config_xml_encoding); if (!handler) { @@ -639,6 +638,32 @@ int config_writer_write_element_bool(struct config_writer *writer, value ? config_xml_true : config_xml_false); } +LTTNG_HIDDEN +int config_writer_write_element_double(struct config_writer *writer, + const char *element_name, + double value) +{ + int ret; + xmlChar *encoded_element_name; + + if (!writer || !writer->writer || !element_name || !element_name[0]) { + ret = -1; + goto end; + } + + encoded_element_name = encode_string(element_name); + if (!encoded_element_name) { + ret = -1; + goto end; + } + + ret = xmlTextWriterWriteFormatElement( + writer->writer, encoded_element_name, "%f", value); + xmlFree(encoded_element_name); +end: + return ret >= 0 ? 0 : ret; +} + LTTNG_HIDDEN int config_writer_write_element_string(struct config_writer *writer, const char *element_name, const char *value) @@ -712,7 +737,7 @@ void fini_session_config_validation_ctx( } static -char *get_session_config_xsd_path() +char *get_session_config_xsd_path(void) { char *xsd_path; const char *base_path = lttng_secure_getenv(DEFAULT_SESSION_CONFIG_XSD_PATH_ENV); @@ -843,12 +868,14 @@ int parse_bool(xmlChar *str, int *val) goto end; } - if (!strcmp((const char *) str, config_xml_true)) { + if (!strcmp((const char *) str, config_xml_true) || + !strcmp((const char *) str, "1")) { *val = 1; - } else if (!strcmp((const char *) str, config_xml_false)) { + } else if (!strcmp((const char *) str, config_xml_false) || + !strcmp((const char *) str, "0")) { *val = 0; } else { - WARN("Invalid boolean value encoutered (%s).", + WARN("Invalid boolean value encountered (%s).", (const char *) str); ret = -1; } @@ -1230,7 +1257,7 @@ int process_consumer_output(xmlNodePtr consumer_output_node, int ret; xmlNodePtr node; - assert(output); + LTTNG_ASSERT(output); for (node = xmlFirstElementChild(consumer_output_node); node; node = xmlNextElementSibling(node)) { @@ -1296,7 +1323,7 @@ int create_session_net_output(const char *name, const char *control_uri, struct lttng_handle *handle; const char *uri = NULL; - assert(name); + LTTNG_ASSERT(name); handle = lttng_create_handle(name, NULL); if (!handle) { @@ -1325,7 +1352,7 @@ int create_snapshot_session(const char *session_name, xmlNodePtr output_node, xmlNodePtr snapshot_output_list_node; xmlNodePtr snapshot_output_node; - assert(session_name); + LTTNG_ASSERT(session_name); ret = lttng_create_session_snapshot(session_name, NULL); if (ret) { @@ -1478,7 +1505,7 @@ int create_session(const char *name, const char *data_uri = NULL; const char *path = NULL; - assert(name); + LTTNG_ASSERT(name); if (output_node) { consumer_output_node = xmlFirstElementChild(output_node); @@ -1744,8 +1771,8 @@ int process_probe_attribute_node(xmlNodePtr probe_attribute_node, { int ret; - assert(probe_attribute_node); - assert(attr); + LTTNG_ASSERT(probe_attribute_node); + LTTNG_ASSERT(attr); if (!strcmp((const char *) probe_attribute_node->name, config_element_address)) { @@ -1828,9 +1855,9 @@ int process_event_node(xmlNodePtr event_node, struct lttng_handle *handle, unsigned long exclusion_count = 0; char *filter_expression = NULL; - assert(event_node); - assert(handle); - assert(channel_name); + LTTNG_ASSERT(event_node); + LTTNG_ASSERT(handle); + LTTNG_ASSERT(channel_name); event = lttng_event_create(); if (!event) { @@ -1855,7 +1882,7 @@ int process_event_node(xmlNodePtr event_node, struct lttng_handle *handle, event->loglevel = LTTNG_LOGLEVEL_DEBUG; break; default: - assert(0); + abort(); } for (node = xmlFirstElementChild(event_node); node; @@ -2160,9 +2187,9 @@ int process_events_node(xmlNodePtr events_node, struct lttng_handle *handle, struct lttng_event event; xmlNodePtr node; - assert(events_node); - assert(handle); - assert(channel_name); + LTTNG_ASSERT(events_node); + LTTNG_ASSERT(handle); + LTTNG_ASSERT(channel_name); for (node = xmlFirstElementChild(events_node); node; node = xmlNextElementSibling(node)) { @@ -2204,10 +2231,10 @@ int process_channel_attr_node(xmlNodePtr attr_node, { int ret; - assert(attr_node); - assert(channel); - assert(contexts_node); - assert(events_node); + LTTNG_ASSERT(attr_node); + LTTNG_ASSERT(channel); + LTTNG_ASSERT(contexts_node); + LTTNG_ASSERT(events_node); if (!strcmp((const char *) attr_node->name, config_element_name)) { xmlChar *content; @@ -2510,8 +2537,8 @@ int process_context_node(xmlNodePtr context_node, struct lttng_event_context context; xmlNodePtr context_child_node = xmlFirstElementChild(context_node); - assert(handle); - assert(channel_name); + LTTNG_ASSERT(handle); + LTTNG_ASSERT(channel_name); if (!context_child_node) { ret = -LTTNG_ERR_LOAD_INVALID_CONFIG; @@ -2755,7 +2782,7 @@ static int process_legacy_pid_tracker_node( LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID : LTTNG_PROCESS_ATTR_PROCESS_ID; - assert(handle); + LTTNG_ASSERT(handle); tracker_handle_ret_code = lttng_session_get_tracker_handle( handle->session_name, handle->domain.type, @@ -2883,8 +2910,8 @@ static int process_id_tracker_node(xmlNodePtr id_tracker_node, struct lttng_process_attr_tracker_handle *tracker_handle = NULL; enum lttng_process_attr_tracker_handle_status status; - assert(handle); - assert(id_tracker_node); + LTTNG_ASSERT(handle); + LTTNG_ASSERT(id_tracker_node); tracker_handle_ret_code = lttng_session_get_tracker_handle( handle->session_name, handle->domain.type, process_attr, @@ -3071,7 +3098,7 @@ int process_domain_node(xmlNodePtr domain_node, const char *session_name) xmlNodePtr vgid_tracker_node = NULL; xmlNodePtr node; - assert(session_name); + LTTNG_ASSERT(session_name); ret = init_domain(domain_node, &domain); if (ret) { @@ -3707,7 +3734,7 @@ static int validate_file_read_creds(const char *path) { int ret; - assert(path); + LTTNG_ASSERT(path); /* Can we read the file. */ ret = access(path, R_OK); @@ -3734,8 +3761,8 @@ int load_session_from_file(const char *path, const char *session_name, xmlNodePtr sessions_node; xmlNodePtr session_node; - assert(path); - assert(validation_ctx); + LTTNG_ASSERT(path); + LTTNG_ASSERT(validation_ctx); ret = validate_file_read_creds(path); if (ret != 1) { @@ -3809,8 +3836,8 @@ int load_session_from_path(const char *path, const char *session_name, struct lttng_dynamic_buffer file_path; size_t path_len; - assert(path); - assert(validation_ctx); + LTTNG_ASSERT(path); + LTTNG_ASSERT(validation_ctx); path_len = strlen(path); lttng_dynamic_buffer_init(&file_path); if (path_len >= LTTNG_PATH_MAX) { @@ -3971,7 +3998,7 @@ static int validate_path_creds(const char *path) int ret, uid = getuid(); struct stat buf; - assert(path); + LTTNG_ASSERT(path); if (uid == 0) { goto valid; @@ -4017,16 +4044,17 @@ int config_load_session(const char *path, const char *session_name, /* Try home path */ home_path = utils_get_home_dir(); if (home_path) { - char path[PATH_MAX]; + char path_buf[PATH_MAX]; /* * Try user session configuration path. Ignore error here so we can * continue loading the system wide sessions. */ if (autoload) { - ret = snprintf(path, sizeof(path), - DEFAULT_SESSION_HOME_CONFIGPATH "/" - DEFAULT_SESSION_CONFIG_AUTOLOAD, home_path); + ret = snprintf(path_buf, sizeof(path_buf), + DEFAULT_SESSION_HOME_CONFIGPATH + "/" DEFAULT_SESSION_CONFIG_AUTOLOAD, + home_path); if (ret < 0) { PERROR("snprintf session autoload home config path"); ret = -LTTNG_ERR_INVALID; @@ -4038,19 +4066,20 @@ int config_load_session(const char *path, const char *session_name, * avoid any user session daemon to try to load kernel sessions * automatically and failing all the times. */ - ret = validate_path_creds(path); + ret = validate_path_creds(path_buf); if (ret) { - path_ptr = path; + path_ptr = path_buf; } } else { - ret = snprintf(path, sizeof(path), - DEFAULT_SESSION_HOME_CONFIGPATH, home_path); + ret = snprintf(path_buf, sizeof(path_buf), + DEFAULT_SESSION_HOME_CONFIGPATH, + home_path); if (ret < 0) { PERROR("snprintf session home config path"); ret = -LTTNG_ERR_INVALID; goto end; } - path_ptr = path; + path_ptr = path_buf; } if (path_ptr) { ret = load_session_from_path(path_ptr, session_name,