Fix: wrong behavior of save command when no session name is provided
[lttng-tools.git] / src / bin / lttng / commands / save.c
index e7c3caeefb2e6dce8de041c7bf4e9c73e6888628..9be710326349150a08bd9da5d5999152a777c6ab 100644 (file)
@@ -93,12 +93,9 @@ int cmd_save(int argc, const char **argv)
 
        if (!opt_save_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;
+               if (session_name) {
+                       DBG2("Session name: %s", session_name);
                }
-               DBG2("Session name: %s", session_name);
        }
 
        attr = lttng_save_session_attr_create();
@@ -117,18 +114,27 @@ int cmd_save(int argc, const char **argv)
                goto end_destroy;
        }
 
-       if (lttng_save_session_attr_set_output_url(attr,
-               opt_output_path)) {
+       if (lttng_save_session_attr_set_output_url(attr, opt_output_path)) {
                ret = CMD_ERROR;
                goto end_destroy;
        }
 
        ret = lttng_save_session(attr);
-       if (ret) {
-               if (ret == -LTTNG_ERR_SESS_NOT_FOUND) {
-                       ERR("Session '%s' not found", session_name);
+       if (ret < 0) {
+               ERR("%s", lttng_strerror(ret));
+       } else {
+               /* Inform the user of what just happened on success. */
+               if (session_name && opt_output_path) {
+                       MSG("Session %s saved successfully in %s.", session_name,
+                                       opt_output_path);
+               } else if (session_name && !opt_output_path) {
+                       MSG("Session %s saved successfully.", session_name);
+               } else if (!session_name && opt_output_path) {
+                       MSG("All sessions have been saved successfully in %s.",
+                                       opt_output_path);
+               } else {
+                       MSG("All sessions have been saved successfully.");
                }
-               ret = CMD_ERROR;
        }
 end_destroy:
        lttng_save_session_attr_destroy(attr);
This page took 0.026358 seconds and 5 git commands to generate.