X-Git-Url: http://git.efficios.com/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Flib%2Flttng-ctl%2Flttng-ctl.c;h=e4560bb7fb927895d5b11fd84db2338001b0507b;hp=064f739aa329d939ceefd116e5cb09f387ef7a20;hb=ff7ef7b8297ae2e3aa6451a0045d657d91aec7be;hpb=a4b92340642035d1eafeb1eead0ad01f64d2007d diff --git a/src/lib/lttng-ctl/lttng-ctl.c b/src/lib/lttng-ctl/lttng-ctl.c index 064f739aa..e4560bb7f 100644 --- a/src/lib/lttng-ctl/lttng-ctl.c +++ b/src/lib/lttng-ctl/lttng-ctl.c @@ -34,17 +34,17 @@ #include #include -#include "filter-ast.h" -#include "filter-parser.h" -#include "filter-bytecode.h" -#include "memstream.h" +#include "filter/filter-ast.h" +#include "filter/filter-parser.h" +#include "filter/filter-bytecode.h" +#include "filter/memstream.h" #ifdef DEBUG -const int print_xml = 1; +static const int print_xml = 1; #define dbg_printf(fmt, args...) \ printf("[debug liblttng-ctl] " fmt, ## args) #else -const int print_xml = 0; +static const int print_xml = 0; #define dbg_printf(fmt, args...) \ do { \ /* do nothing but check printf format */ \ @@ -524,7 +524,7 @@ static int ask_sessiond_varlen(struct lttcomm_session_msg *lsm, } /* Check error code if OK */ - if (llm.ret_code != LTTCOMM_OK) { + if (llm.ret_code != LTTNG_OK) { ret = -llm.ret_code; goto end; } @@ -782,24 +782,24 @@ int lttng_set_event_filter(struct lttng_handle *handle, strlen(filter_expression), "r"); if (!fmem) { fprintf(stderr, "Error opening memory as stream\n"); - return -ENOMEM; + return -LTTNG_ERR_FILTER_NOMEM; } ctx = filter_parser_ctx_alloc(fmem); if (!ctx) { fprintf(stderr, "Error allocating parser\n"); - ret = -ENOMEM; + ret = -LTTNG_ERR_FILTER_NOMEM; goto alloc_error; } ret = filter_parser_ctx_append_ast(ctx); if (ret) { fprintf(stderr, "Parse error\n"); - ret = -EINVAL; + ret = -LTTNG_ERR_FILTER_INVAL; goto parse_error; } ret = filter_visitor_set_parent(ctx); if (ret) { fprintf(stderr, "Set parent error\n"); - ret = -EINVAL; + ret = -LTTNG_ERR_FILTER_INVAL; goto parse_error; } if (print_xml) { @@ -807,7 +807,7 @@ int lttng_set_event_filter(struct lttng_handle *handle, if (ret) { fflush(stdout); fprintf(stderr, "XML print error\n"); - ret = -EINVAL; + ret = -LTTNG_ERR_FILTER_INVAL; goto parse_error; } } @@ -817,7 +817,7 @@ int lttng_set_event_filter(struct lttng_handle *handle, ret = filter_visitor_ir_generate(ctx); if (ret) { fprintf(stderr, "Generate IR error\n"); - ret = -EINVAL; + ret = -LTTNG_ERR_FILTER_INVAL; goto parse_error; } dbg_printf("done\n"); @@ -826,7 +826,7 @@ int lttng_set_event_filter(struct lttng_handle *handle, fflush(stdout); ret = filter_visitor_ir_check_binary_op_nesting(ctx); if (ret) { - ret = -EINVAL; + ret = -LTTNG_ERR_FILTER_INVAL; goto parse_error; } dbg_printf("done\n"); @@ -836,7 +836,7 @@ int lttng_set_event_filter(struct lttng_handle *handle, ret = filter_visitor_bytecode_generate(ctx); if (ret) { fprintf(stderr, "Generate bytecode error\n"); - ret = -EINVAL; + ret = -LTTNG_ERR_FILTER_INVAL; goto parse_error; } dbg_printf("done\n"); @@ -1041,18 +1041,13 @@ int lttng_list_tracepoint_fields(struct lttng_handle *handle, */ const char *lttng_strerror(int code) { - /* lttcomm error codes range from -LTTCOMM_OK down to -LTTCOMM_NR */ - if (code > -LTTCOMM_OK) { - return "Ended with errors"; - } - - return lttcomm_get_readable_code(code); + return error_get_str(code); } /* * Create a brand new session using name and url for destination. * - * Returns LTTCOMM_OK on success or a negative error code. + * Returns LTTNG_OK on success or a negative error code. */ int lttng_create_session(const char *name, const char *url) { @@ -1072,7 +1067,7 @@ int lttng_create_session(const char *name, const char *url) /* There should never be a data URL */ size = parse_str_urls_to_uri(url, NULL, &uris); if (size < 0) { - return LTTCOMM_INVALID; + return LTTNG_ERR_INVALID; } lsm.u.uri.size = size; @@ -1351,7 +1346,7 @@ int lttng_set_consumer_url(struct lttng_handle *handle, size = parse_str_urls_to_uri(control_url, data_url, &uris); if (size < 0) { - return LTTCOMM_INVALID; + return LTTNG_ERR_INVALID; } lsm.u.uri.size = size; @@ -1496,6 +1491,71 @@ error: return ret; } +/* + * This is an extension of create session that is ONLY and SHOULD only be used + * by the lttng command line program. It exists to avoid using URI parsing in + * the lttng client. + * + * We need the date and time for the trace path subdirectory for the case where + * the user does NOT define one using either -o or -U. Using the normal + * lttng_create_session API call, we have no clue on the session daemon side if + * the URL was generated automatically by the client or define by the user. + * + * So this function "wrapper" is hidden from the public API, takes the datetime + * string and appends it if necessary to the URI subdirectory before sending it + * to the session daemon. + * + * With this extra function, the lttng_create_session call behavior is not + * changed and the timestamp is appended to the URI on the session daemon side + * if necessary. + */ +int _lttng_create_session_ext(const char *name, const char *url, + const char *datetime) +{ + int ret; + ssize_t size; + struct lttcomm_session_msg lsm; + struct lttng_uri *uris = NULL; + + if (name == NULL || datetime == NULL) { + return -1; + } + + memset(&lsm, 0, sizeof(lsm)); + + lsm.cmd_type = LTTNG_CREATE_SESSION; + if (!strncmp(name, DEFAULT_SESSION_NAME, strlen(DEFAULT_SESSION_NAME))) { + ret = snprintf(lsm.session.name, sizeof(lsm.session.name), "%s-%s", + name, datetime); + if (ret < 0) { + PERROR("snprintf session name datetime"); + return -1; + } + } else { + copy_string(lsm.session.name, name, sizeof(lsm.session.name)); + } + + /* There should never be a data URL */ + size = parse_str_urls_to_uri(url, NULL, &uris); + if (size < 0) { + return LTTNG_ERR_INVALID; + } + + lsm.u.uri.size = size; + + if (uris[0].dtype != LTTNG_DST_PATH && strlen(uris[0].subdir) == 0) { + ret = snprintf(uris[0].subdir, sizeof(uris[0].subdir), "%s-%s", name, + datetime); + if (ret < 0) { + PERROR("snprintf uri subdir"); + return -1; + } + } + + return ask_sessiond_varlen(&lsm, uris, sizeof(struct lttng_uri) * size, + NULL); +} + /* * lib constructor */