Remove -s option from lttng load command
authorDavid Goulet <dgoulet@efficios.com>
Wed, 26 Mar 2014 14:50:41 +0000 (10:50 -0400)
committerDavid Goulet <dgoulet@efficios.com>
Wed, 26 Mar 2014 14:51:44 +0000 (10:51 -0400)
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 <dgoulet@efficios.com>
src/bin/lttng/commands/load.c
src/common/config/config.c
tests/regression/tools/save-load/test_load

index 3f926548ae637414d5c5e46fc5ecc2ef32ee8a50..4d38c792b82cc4e9ffe69253b04457410906eb9a 100644 (file)
 #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);
index 722904772316c0fc0b48f548817a472e051247a1..0e9e1bdc722661c21fb4172b27ba49a593b742ae 100644 (file)
@@ -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) {
index a58c29967cc60aa1d22218b8f4076b75f586c475..6cc98a0c5d61214df449f960faff2f6297a4ddf9 100755 (executable)
@@ -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
 }
This page took 0.028652 seconds and 4 git commands to generate.