event-rule: userspace probe: rename get/set_name to get/set_event_name
[lttng-tools.git] / src / bin / lttng / commands / metadata.c
index 0faf4172a370349fabb2e8a46e7283d634b4bab6..f36be65fd3b66a76a31d1a3cc74486d30f8159ba 100644 (file)
@@ -1,18 +1,8 @@
 /*
- * Copyright (C) 2015 Julien Desfossez <jdesfossez@efficios.com>
+ * Copyright (C) 2015 Julien Desfossez <jdesfossez@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
@@ -33,6 +23,12 @@ static char *session_name = NULL;
 
 static int metadata_regenerate(int argc, const char **argv);
 
+#ifdef LTTNG_EMBED_HELP
+static const char help_msg[] =
+#include <lttng-metadata.1.h>
+;
+#endif
+
 enum {
        OPT_HELP = 1,
        OPT_LIST_OPTIONS,
@@ -55,23 +51,6 @@ static struct cmd_struct actions[] = {
        { NULL, NULL }  /* Array closure */
 };
 
-/*
- * usage
- */
-static void usage(FILE *ofp)
-{
-       fprintf(ofp, "usage: lttng metadata [OPTION] ACTION\n");
-       fprintf(ofp, "\n");
-       fprintf(ofp, "Actions:\n");
-       fprintf(ofp, "   regenerate\n");
-       fprintf(ofp, "      Regenerate and overwrite the metadata of the session.\n");
-       fprintf(ofp, "Options:\n");
-       fprintf(ofp, "  -h, --help               Show this help.\n");
-       fprintf(ofp, "      --list-options       Simple listing of options.\n");
-       fprintf(ofp, "  -s, --session NAME       Apply to session name.\n");
-       fprintf(ofp, "\n");
-}
-
 /*
  * Count and return the number of arguments in argv.
  */
@@ -92,10 +71,18 @@ static int metadata_regenerate(int argc, const char **argv)
 {
        int ret;
 
-       ret = lttng_metadata_regenerate(session_name);
+       if (argc > 1) {
+               ret = CMD_UNDEFINED;
+               goto end;
+       }
+       ret = lttng_regenerate_metadata(session_name);
        if (ret == 0) {
                MSG("Metadata successfully regenerated for session %s", session_name);
+       } else {
+               ERR("%s", lttng_strerror(ret));
        }
+
+end:
        return ret;
 }
 
@@ -105,12 +92,13 @@ static int handle_command(const char **argv)
        int ret = CMD_SUCCESS, i = 0, argc, command_ret = CMD_SUCCESS;
 
        if (argv == NULL) {
-               usage(stderr);
-               command_ret = CMD_ERROR;
+               ERR("No action specified for metadata command.");
+               ret = CMD_ERROR;
                goto end;
        }
 
        argc = count_arguments(argv);
+       assert(argc >= 1);
 
        cmd = &actions[i];
        while (cmd->func != NULL) {
@@ -165,7 +153,7 @@ int cmd_metadata(int argc, const char **argv)
        static poptContext pc;
 
        if (argc < 1) {
-               usage(stderr);
+               SHOW_HELP();
                ret = CMD_ERROR;
                goto end;
        }
@@ -199,7 +187,7 @@ int cmd_metadata(int argc, const char **argv)
        while ((opt = poptGetNextOpt(pc)) != -1) {
                switch (opt) {
                case OPT_HELP:
-                       usage(stdout);
+                       SHOW_HELP();
                        goto end;
                case OPT_LIST_OPTIONS:
                        list_cmd_options(stdout, long_options);
@@ -208,7 +196,7 @@ int cmd_metadata(int argc, const char **argv)
                        list_commands(actions, stdout);
                        goto end;
                default:
-                       usage(stderr);
+                       SHOW_HELP();
                        ret = CMD_UNDEFINED;
                        goto end;
                }
@@ -226,12 +214,7 @@ int cmd_metadata(int argc, const char **argv)
 
        command_ret = handle_command(poptGetArgs(pc));
        if (command_ret) {
-               switch (-command_ret) {
-               default:
-                       ERR("%s", lttng_strerror(command_ret));
-                       success = 0;
-                       break;
-               }
+               success = 0;
        }
 
        if (lttng_opt_mi) {
This page took 0.025322 seconds and 4 git commands to generate.