X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=src%2Flib%2Flttng-ctl%2Fload.c;h=f89effed04b8b69b23e186dfee6237e8b8cfe10d;hb=49c360e815ad63e137ba9664f786c91df76d27b3;hp=be236f242b25b9fb0096ba42e73167d6400fb38b;hpb=0d4bab5e4bd1654515ce754a3d9699cafe9b41b2;p=lttng-tools.git diff --git a/src/lib/lttng-ctl/load.c b/src/lib/lttng-ctl/load.c index be236f242..f89effed0 100644 --- a/src/lib/lttng-ctl/load.c +++ b/src/lib/lttng-ctl/load.c @@ -43,15 +43,18 @@ void reset_load_session_attr_urls(struct lttng_load_session_attr *attr) free(attr->raw_override_path_url); free(attr->raw_override_ctrl_url); free(attr->raw_override_data_url); - free(attr->override_attr.path_url); - free(attr->override_attr.ctrl_url); - free(attr->override_attr.data_url); + if (attr->override_attr) { + free(attr->override_attr->path_url); + free(attr->override_attr->ctrl_url); + free(attr->override_attr->data_url); + } } void lttng_load_session_attr_destroy(struct lttng_load_session_attr *attr) { if (attr) { reset_load_session_attr_urls(attr); + free(attr->override_attr); free(attr); } } @@ -86,27 +89,17 @@ int lttng_load_session_attr_get_overwrite( return attr ? attr->overwrite : -LTTNG_ERR_INVALID; } -const char *lttng_load_session_attr_get_override_path_url( - struct lttng_load_session_attr *attr) -{ - const char *ret = NULL; - - if (attr && attr->override_attr.path_url) { - ret = attr->raw_override_path_url; - } - - return ret; -} - const char *lttng_load_session_attr_get_override_ctrl_url( struct lttng_load_session_attr *attr) { const char *ret = NULL; - if (attr && attr->override_attr.ctrl_url) { - ret = attr->raw_override_ctrl_url; + if (!attr || !attr->override_attr) { + goto end; } + ret = attr->raw_override_ctrl_url; +end: return ret; } @@ -115,10 +108,12 @@ const char *lttng_load_session_attr_get_override_data_url( { const char *ret = NULL; - if (attr && attr->override_attr.data_url) { - ret = attr->raw_override_data_url; + if (!attr || !attr->override_attr) { + goto end; } + ret = attr->raw_override_data_url; +end: return ret; } @@ -127,12 +122,16 @@ const char *lttng_load_session_attr_get_override_url( { const char *ret = NULL; - if (attr && (attr->override_attr.path_url || - (attr->override_attr.ctrl_url && - attr->override_attr.data_url))) { - ret = attr->raw_override_url; + if (!attr || !attr->override_attr) { + goto end; } + if ((attr->override_attr->path_url || + (attr->override_attr->ctrl_url && + attr->override_attr->data_url))) { + ret = attr->raw_override_url; + } +end: return ret; } @@ -233,12 +232,19 @@ int lttng_load_session_attr_set_override_ctrl_url( goto end; } - if (attr->override_attr.path_url) { + if (!attr->override_attr) { + attr->override_attr = zmalloc( + sizeof(struct config_load_session_override_attr)); + if (!attr->override_attr) { + ret = -LTTNG_ERR_NOMEM; + goto end; + } + } + + if (attr->override_attr->path_url) { /* - * FIXME: return a more meaningful error. - * Setting a ctrl override after a path override make no - * sense. - * */ + * Setting a ctrl override after a path override makes no sense. + */ ret = -LTTNG_ERR_INVALID; goto end; } @@ -279,11 +285,11 @@ int lttng_load_session_attr_set_override_ctrl_url( } /* Squash old value if any */ - free(attr->override_attr.ctrl_url); + free(attr->override_attr->ctrl_url); free(attr->raw_override_ctrl_url); /* Populate the object */ - attr->override_attr.ctrl_url = url_str; + attr->override_attr->ctrl_url = url_str; attr->raw_override_ctrl_url = raw_str; /* Ownership passed to attr. */ @@ -311,7 +317,19 @@ int lttng_load_session_attr_set_override_data_url( goto end; } - if (attr->override_attr.path_url) { + if (!attr->override_attr) { + attr->override_attr = zmalloc( + sizeof(struct config_load_session_override_attr)); + if (!attr->override_attr) { + ret = -LTTNG_ERR_NOMEM; + goto end; + } + } + + if (attr->override_attr->path_url) { + /* + * Setting a data override after a path override makes no sense. + */ ret = -LTTNG_ERR_INVALID; goto end; } @@ -351,11 +369,11 @@ int lttng_load_session_attr_set_override_data_url( } /* Squash old value if any */ - free(attr->override_attr.data_url); + free(attr->override_attr->data_url); free(attr->raw_override_data_url); /* Populate the object */ - attr->override_attr.data_url = url_str; + attr->override_attr->data_url = url_str; attr->raw_override_data_url = raw_str; /* Ownership passed to attr. */ @@ -388,6 +406,15 @@ int lttng_load_session_attr_set_override_url( goto end; } + if (!attr->override_attr) { + attr->override_attr = zmalloc( + sizeof(struct config_load_session_override_attr)); + if (!attr->override_attr) { + ret = -LTTNG_ERR_NOMEM; + goto end; + } + } + /* * FIXME: uri_parse should be able to take as parameter the protocol * type to validate "url". For now only check the parsing goes through; @@ -475,9 +502,9 @@ int lttng_load_session_attr_set_override_url( reset_load_session_attr_urls(attr); - attr->override_attr.path_url = path_str; - attr->override_attr.ctrl_url = ctrl_str; - attr->override_attr.data_url = data_str; + attr->override_attr->path_url = path_str; + attr->override_attr->ctrl_url = ctrl_str; + attr->override_attr->data_url = data_str; attr->raw_override_url = raw_url_str; attr->raw_override_path_url = raw_path_str; @@ -519,7 +546,8 @@ int lttng_load_session(struct lttng_load_session_attr *attr) session_name = attr->session_name[0] != '\0' ? attr->session_name : NULL; - ret = config_load_session(url, session_name, attr->overwrite, 0); + ret = config_load_session(url, session_name, attr->overwrite, 0, + attr->override_attr); end: return ret;