X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fbin%2Flttng%2Fcommands%2Fload.c;h=a0f5e1d65befd4f5990def4bd91acd948c6dd3f5;hb=623bc34cc3236f5cddef955fb2ae0e538230bba0;hp=cb3eb75aa8439c6813d1c5765555b37038c8773b;hpb=f40ef1d56886bc58f5d7e147d77f818f46b66456;p=lttng-tools.git diff --git a/src/bin/lttng/commands/load.c b/src/bin/lttng/commands/load.c index cb3eb75aa..a0f5e1d65 100644 --- a/src/bin/lttng/commands/load.c +++ b/src/bin/lttng/commands/load.c @@ -25,6 +25,7 @@ #include #include +#include #include "../command.h" @@ -53,24 +54,6 @@ static struct poptOption load_opts[] = { {0, 0, 0, 0, 0, 0, 0} }; -/* - * usage - */ -static void usage(FILE *ofp) -{ - fprintf(ofp, "usage: lttng load [OPTIONS] [SESSION]\n"); - fprintf(ofp, "\n"); - fprintf(ofp, "Options:\n"); - fprintf(ofp, " -h, --help Show this help\n"); - fprintf(ofp, " -a, --all Load all sessions (default)\n"); - fprintf(ofp, " -i, --input-path PATH Input path of the session file(s).\n"); - fprintf(ofp, " If a directory, load all files in it\n"); - fprintf(ofp, " else try to load the given file.\n"); - fprintf(ofp, " -f, --force Override existing session(s).\n"); - fprintf(ofp, " This will destroy existing session(s)\n"); - fprintf(ofp, " before creating new one(s).\n"); -} - static int mi_partial_session(const char *session_name) { int ret; @@ -141,9 +124,11 @@ end: */ int cmd_load(int argc, const char **argv) { - int ret = CMD_SUCCESS, command_ret = CMD_SUCCESS, success; + int ret, success; int opt; poptContext pc; + struct lttng_load_session_attr *session_attr = NULL; + char *input_path = NULL; pc = poptGetContext(NULL, argc, argv, load_opts, 0); poptReadDefaultConfig(pc, 0); @@ -151,24 +136,32 @@ int cmd_load(int argc, const char **argv) while ((opt = poptGetNextOpt(pc)) != -1) { switch (opt) { case OPT_HELP: - usage(stdout); + SHOW_HELP(); + ret = CMD_SUCCESS; goto end; case OPT_ALL: opt_load_all = 1; break; case OPT_LIST_OPTIONS: list_cmd_options(stdout, load_opts); + ret = CMD_SUCCESS; goto end; case OPT_FORCE: opt_force = 1; break; default: - usage(stderr); ret = CMD_UNDEFINED; goto end; } } + ret = lttng_session_daemon_alive(); + if (!ret) { + ERR("No session daemon is available"); + ret = CMD_ERROR; + goto end; + } + if (!opt_load_all) { session_name = poptGetArg(pc); if (session_name) { @@ -183,7 +176,7 @@ int cmd_load(int argc, const char **argv) if (lttng_opt_mi) { writer = mi_lttng_writer_create(fileno(stdout), lttng_opt_mi); if (!writer) { - ret = -LTTNG_ERR_NOMEM; + ret = CMD_ERROR; goto end; } @@ -204,15 +197,65 @@ int cmd_load(int argc, const char **argv) } } - command_ret = config_load_session(opt_input_path, session_name, opt_force, 0); - if (command_ret) { - ERR("%s", lttng_strerror(command_ret)); + /* Prepare load attributes */ + session_attr = lttng_load_session_attr_create(); + if (!session_attr) { + ERR("Failed to create load session attributes"); + ret = CMD_ERROR; + goto end; + } + + /* + * Set the input url + * lttng_load_session_attr_set_input_url only suppports absolute path. + * Use realpath to resolve any relative path. + * */ + if (opt_input_path) { + input_path = realpath(opt_input_path, NULL); + if (!input_path) { + PERROR("Invalid input path"); + ret = CMD_ERROR; + goto end; + } + } else { + input_path = NULL; + } + + ret = lttng_load_session_attr_set_input_url(session_attr, + input_path); + if (ret) { + ERR("Invalid input path"); + ret = CMD_ERROR; + goto end; + } + + /* Set the session name. NULL means all sessions should be loaded */ + ret = lttng_load_session_attr_set_session_name(session_attr, + session_name); + if (ret) { + ERR("Invalid session name"); + ret = CMD_ERROR; + goto end; + } + + /* Set the overwrite attribute */ + ret = lttng_load_session_attr_set_overwrite(session_attr, opt_force); + if (ret) { + ERR("Force argument could not be applied"); + ret = CMD_ERROR; + goto end; + } + + ret = lttng_load_session(session_attr); + if (ret) { + ERR("%s", lttng_strerror(ret)); success = 0; + ret = CMD_ERROR; } else { if (opt_load_all) { MSG("All sessions have been loaded successfully"); } else if (session_name) { - ret = config_init((char *)session_name); + ret = config_init((char *) session_name); if (ret < 0) { ret = CMD_WARNING; } @@ -221,6 +264,7 @@ int cmd_load(int argc, const char **argv) MSG("Session has been loaded successfully"); } success = 1; + ret = CMD_SUCCESS; } /* Mi Printing and closing */ @@ -256,13 +300,11 @@ int cmd_load(int argc, const char **argv) } end: if (writer && mi_lttng_writer_destroy(writer)) { - /* Preserve original error code */ - ret = ret ? ret : -LTTNG_ERR_MI_IO_FAIL; + ERR("Failed to destroy mi lttng writer"); } - /* Overwrite ret if the was an error with the load command */ - ret = command_ret ? -command_ret : ret; - + lttng_load_session_attr_destroy(session_attr); + free(input_path); poptFreeContext(pc); return ret; }