From 1114378362fe014288ccaab1d1fed52f7b5703f8 Mon Sep 17 00:00:00 2001 From: David Goulet Date: Wed, 26 Mar 2014 10:50:41 -0400 Subject: [PATCH] Remove -s option from lttng load command This is to help usability and also provide the same usage as lttng save command that does not require this option. Fixes #755 Signed-off-by: David Goulet --- src/bin/lttng/commands/load.c | 23 +++++++++++++--------- src/common/config/config.c | 8 +++++++- tests/regression/tools/save-load/test_load | 8 ++++---- 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/src/bin/lttng/commands/load.c b/src/bin/lttng/commands/load.c index 3f926548a..4d38c792b 100644 --- a/src/bin/lttng/commands/load.c +++ b/src/bin/lttng/commands/load.c @@ -27,10 +27,11 @@ #include "../command.h" static char *opt_input_path; -static char *opt_session_name; static int opt_force; static int opt_load_all; +static const char *session_name; + enum { OPT_HELP = 1, OPT_ALL, @@ -41,7 +42,6 @@ static struct poptOption load_opts[] = { /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */ {"help", 'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0}, {"all", 'a', POPT_ARG_NONE, 0, OPT_ALL, 0, 0}, - {"session", 's', POPT_ARG_STRING, &opt_session_name, 0, 0, 0}, {"input-path", 'i', POPT_ARG_STRING, &opt_input_path, 0, 0, 0}, {"force", 'f', POPT_ARG_NONE, 0, OPT_FORCE, 0, 0}, {0, 0, 0, 0, 0, 0, 0} @@ -52,12 +52,11 @@ static struct poptOption load_opts[] = { */ static void usage(FILE *ofp) { - fprintf(ofp, "usage: lttng load [OPTIONS]\n"); + 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, " -s, --session Load a specific session\n"); fprintf(ofp, " -i, --input-path Input path of the session configuration(s)\n"); fprintf(ofp, " -f, --force Override existing session configuration(s)\n"); } @@ -92,14 +91,20 @@ int cmd_load(int argc, const char **argv) } } - if (opt_session_name && opt_load_all) { - WARN("Conflicting session options, loading session %s", - opt_session_name); + if (!opt_load_all) { + session_name = poptGetArg(pc); + if (!session_name) { + ERR("A session name must be provided if the \"all\" option is not used."); + ret = CMD_ERROR; + goto end; + } + DBG2("Loading session name: %s", session_name); } - ret = config_load_session(opt_input_path, opt_session_name, opt_force); + ret = config_load_session(opt_input_path, session_name, opt_force); if (ret) { - ret = CMD_ERROR; + ERR("%s", lttng_strerror(ret)); + ret = -ret; } end: poptFreeContext(pc); diff --git a/src/common/config/config.c b/src/common/config/config.c index 722904772..0e9e1bdc7 100644 --- a/src/common/config/config.c +++ b/src/common/config/config.c @@ -2342,9 +2342,15 @@ int load_session_from_path(const char *path, const char *session_name, directory = opendir(path); if (!directory) { - if (errno != ENOTDIR) { + switch (errno) { + case ENOTDIR: ret = -LTTNG_ERR_LOAD_IO_FAIL; goto end; + case ENOENT: + ret = -LTTNG_ERR_LOAD_SESSION_NOENT; + goto end; + default: + break; } } if (directory) { diff --git a/tests/regression/tools/save-load/test_load b/tests/regression/tools/save-load/test_load index a58c29967..6cc98a0c5 100755 --- a/tests/regression/tools/save-load/test_load +++ b/tests/regression/tools/save-load/test_load @@ -51,7 +51,7 @@ function test_basic_load() { diag "Test basic load" - lttng_load "-s $SESSION_NAME -i $CURDIR" + lttng_load "$SESSION_NAME -i $CURDIR" destroy_lttng_session $SESSION_NAME } @@ -65,7 +65,7 @@ function test_complex_load() # custom values. start_lttng_relayd "-C tcp://localhost:8172 -D tcp://localhost:9817" - lttng_load "-s $sess -i $CURDIR" + lttng_load "$sess -i $CURDIR" # Once loaded, we are suppose to be able to disable certain events/channels # thus having a confirmation that it's valid @@ -102,10 +102,10 @@ function test_overwrite() { diag "Test load overwrite" - lttng_load "-s $SESSION_NAME -i $CURDIR" + lttng_load "$SESSION_NAME -i $CURDIR" # This one should succeed - lttng_load "-f -s $SESSION_NAME -i $CURDIR" + lttng_load "-f -i $CURDIR $SESSION_NAME" destroy_lttng_session $SESSION_NAME } -- 2.34.1