Cleanup: always use sysconf to get the page size
[lttng-tools.git] / src / bin / lttng / commands / snapshot.c
index 19b28321f084f26a97a7549bc6c13bb42a122c84..c37e09a7dbed02eb1c192481c0955544808e4d7b 100644 (file)
@@ -1,22 +1,11 @@
 /*
- * Copyright (C) 2013 David Goulet <dgoulet@efficios.com>
+ * Copyright (C) 2013 David Goulet <dgoulet@efficios.com>
  *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License, version 2 only, as
- * published by the Free Software Foundation.
+ * SPDX-License-Identifier: GPL-2.0-only
  *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 51
- * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #define _LGPL_SOURCE
-#include <assert.h>
 #include <inttypes.h>
 #include <popt.h>
 #include <stdio.h>
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <unistd.h>
-#include <assert.h>
 
 #include <common/utils.h>
 #include <common/mi-lttng.h>
-#include <lttng/snapshot.h>
+#include <lttng/lttng.h>
 
 #include "../command.h"
 
@@ -91,7 +79,7 @@ static int count_arguments(const char **argv)
 {
        int i = 0;
 
-       assert(argv);
+       LTTNG_ASSERT(argv);
 
        while (argv[i] != NULL) {
                i++;
@@ -179,11 +167,18 @@ static int list_output(void)
        }
 
        while ((s_iter = lttng_snapshot_output_list_get_next(list)) != NULL) {
-               MSG("%s[%" PRIu32 "] %s: %s (max-size: %" PRId64 ")", indent4,
-                               lttng_snapshot_output_get_id(s_iter),
-                               lttng_snapshot_output_get_name(s_iter),
-                               lttng_snapshot_output_get_ctrl_url(s_iter),
-                               lttng_snapshot_output_get_maxsize(s_iter));
+               if (lttng_snapshot_output_get_maxsize(s_iter)) {
+                       MSG("%s[%" PRIu32 "] %s: %s (max size: %" PRIu64 " bytes)", indent4,
+                                       lttng_snapshot_output_get_id(s_iter),
+                                       lttng_snapshot_output_get_name(s_iter),
+                                       lttng_snapshot_output_get_ctrl_url(s_iter),
+                                       lttng_snapshot_output_get_maxsize(s_iter));
+               } else {
+                       MSG("%s[%" PRIu32 "] %s: %s", indent4,
+                                       lttng_snapshot_output_get_id(s_iter),
+                                       lttng_snapshot_output_get_name(s_iter),
+                                       lttng_snapshot_output_get_ctrl_url(s_iter));
+               }
                output_seen = 1;
                if (lttng_opt_mi) {
                        ret = mi_lttng_snapshot_list_output(writer, s_iter);
@@ -312,10 +307,16 @@ static int add_output(const char *url)
 
        MSG("Snapshot output successfully added for session %s",
                        current_session_name);
-       MSG("  [%" PRIu32 "] %s: %s (max-size: %" PRId64 ")",
-                       lttng_snapshot_output_get_id(output), n_ptr,
-                       lttng_snapshot_output_get_ctrl_url(output),
-                       lttng_snapshot_output_get_maxsize(output));
+       if (opt_max_size) {
+               MSG("  [%" PRIu32 "] %s: %s (max size: %" PRIu64 " bytes)",
+                               lttng_snapshot_output_get_id(output), n_ptr,
+                               lttng_snapshot_output_get_ctrl_url(output),
+                               lttng_snapshot_output_get_maxsize(output));
+       } else {
+               MSG("  [%" PRIu32 "] %s: %s",
+                               lttng_snapshot_output_get_id(output), n_ptr,
+                               lttng_snapshot_output_get_ctrl_url(output));
+       }
        if (lttng_opt_mi) {
                ret = mi_lttng_snapshot_add_output(writer, current_session_name,
                                n_ptr, output);
@@ -333,11 +334,23 @@ static int cmd_add_output(int argc, const char **argv)
        int ret;
 
        if (argc < 2 && (!opt_data_url || !opt_ctrl_url)) {
+               ERR("An output destination must be specified to add a snapshot output.");
                ret = CMD_ERROR;
                goto end;
        }
 
        ret = add_output(argv[1]);
+       if (ret < 0) {
+               switch (-ret) {
+               case LTTNG_ERR_SNAPSHOT_UNSUPPORTED:
+                       ERR("Session \"%s\" contains a channel that is incompatible with the snapshot functionality.\nMake sure all channels are configured in 'mmap' output mode.",
+                                       current_session_name);
+                       ret = CMD_ERROR;
+                       break;
+               default:
+                       break;
+               }
+       }
 
 end:
        return ret;
@@ -350,6 +363,7 @@ static int cmd_del_output(int argc, const char **argv)
        long id;
 
        if (argc < 2) {
+               ERR("A snapshot output name or id must be provided to delete a snapshot output.");
                ret = CMD_ERROR;
                goto end;
        }
@@ -457,7 +471,7 @@ static enum cmd_error_code handle_command(const char **argv)
 
        argc = count_arguments(argv);
        /* popt should have passed NULL if no arguments are present. */
-       assert(argc > 0);
+       LTTNG_ASSERT(argc > 0);
 
        cmd = &actions[i];
        while (cmd->func != NULL) {
@@ -493,8 +507,22 @@ static enum cmd_error_code handle_command(const char **argv)
 
                        result = cmd->func(argc, argv);
                        if (result) {
-                               switch (-result) {
-                               case LTTNG_ERR_SNAPSHOT_NODATA:
+                               switch (result) {
+                               case CMD_ERROR:
+                               case CMD_UNDEFINED:
+                               case CMD_FATAL:
+                               case CMD_WARNING:
+                               case CMD_UNSUPPORTED:
+                                       /*
+                                        * Sub-commands mix lttng_error_codes
+                                        * and cmd_error_codes. This should be
+                                        * cleaned-up, but in the meantime this
+                                        * hack works since the values of the
+                                        * two enums do not intersect.
+                                        */
+                                       cmd_ret = result;
+                                       break;
+                               case -LTTNG_ERR_SNAPSHOT_NODATA:
                                        WARN("%s", lttng_strerror(result));
 
                                        /*  A warning is fine since the user has no control on
@@ -594,10 +622,11 @@ int cmd_snapshot(int argc, const char **argv)
                case OPT_MAX_SIZE:
                {
                        uint64_t val;
-                       const char *opt = poptGetOptArg(pc);
+                       const char *max_size_arg = poptGetOptArg(pc);
 
-                       if (utils_parse_size_suffix((char *) opt, &val) < 0) {
-                               ERR("Unable to handle max-size value %s", opt);
+                       if (utils_parse_size_suffix((char *) max_size_arg, &val) < 0) {
+                               ERR("Unable to handle max-size value %s",
+                                               max_size_arg);
                                cmd_ret = CMD_ERROR;
                                goto end;
                        }
This page took 0.027957 seconds and 4 git commands to generate.