2 * Copyright (C) 2015 - Julien Desfossez <jdesfossez@efficios.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License, version 2 only,
6 * as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 #include <common/mi-lttng.h>
29 #include "../command.h"
31 static char *opt_session_name
;
32 static char *session_name
= NULL
;
34 static int metadata_regenerate(int argc
, const char **argv
);
42 static struct poptOption long_options
[] = {
43 /* { longName, shortName, argInfo, argPtr, value, descrip, argDesc, } */
44 { "help", 'h', POPT_ARG_NONE
, 0, OPT_HELP
, 0, 0, },
45 { "session", 's', POPT_ARG_STRING
, &opt_session_name
, 0, 0, 0},
46 { "list-options", 0, POPT_ARG_NONE
, NULL
, OPT_LIST_OPTIONS
, 0, 0, },
47 { "list-commands", 0, POPT_ARG_NONE
, NULL
, OPT_LIST_COMMANDS
},
48 { 0, 0, 0, 0, 0, 0, 0, },
51 static struct cmd_struct actions
[] = {
52 { "regenerate", metadata_regenerate
},
53 { NULL
, NULL
} /* Array closure */
59 static void usage(FILE *ofp
)
61 fprintf(ofp
, "usage: lttng metadata [OPTION] ACTION\n");
63 fprintf(ofp
, "Actions:\n");
64 fprintf(ofp
, " regenerate\n");
65 fprintf(ofp
, " Regenerate and overwrite the metadata of the session.\n");
66 fprintf(ofp
, "Options:\n");
67 fprintf(ofp
, " -h, --help Show this help.\n");
68 fprintf(ofp
, " --list-options Simple listing of options.\n");
69 fprintf(ofp
, " -s, --session NAME Apply to session name.\n");
74 * Count and return the number of arguments in argv.
76 static int count_arguments(const char **argv
)
82 while (argv
[i
] != NULL
) {
89 static int metadata_regenerate(int argc
, const char **argv
)
93 ret
= lttng_metadata_regenerate(session_name
);
95 MSG("Metadata successfully regenerated for session %s", session_name
);
100 static int handle_command(const char **argv
)
102 struct cmd_struct
*cmd
;
103 int ret
= CMD_SUCCESS
, i
= 0, argc
, command_ret
= CMD_SUCCESS
;
107 command_ret
= CMD_ERROR
;
111 argc
= count_arguments(argv
);
114 while (cmd
->func
!= NULL
) {
116 if (strcmp(argv
[0], cmd
->name
) == 0) {
117 command_ret
= cmd
->func(argc
, argv
);
127 /* Overwrite ret if an error occurred in cmd->func() */
128 ret
= command_ret
? command_ret
: ret
;
133 * Metadata command handling.
135 int cmd_metadata(int argc
, const char **argv
)
137 int opt
, ret
= CMD_SUCCESS
, command_ret
= CMD_SUCCESS
;
138 static poptContext pc
;
146 pc
= poptGetContext(NULL
, argc
, argv
, long_options
, 0);
147 poptReadDefaultConfig(pc
, 0);
149 while ((opt
= poptGetNextOpt(pc
)) != -1) {
154 case OPT_LIST_OPTIONS
:
155 list_cmd_options(stdout
, long_options
);
157 case OPT_LIST_COMMANDS
:
158 list_commands(actions
, stdout
);
167 if (!opt_session_name
) {
168 session_name
= get_session_name();
169 if (session_name
== NULL
) {
174 session_name
= opt_session_name
;
177 command_ret
= handle_command(poptGetArgs(pc
));
179 switch (-command_ret
) {
181 ERR("%s", lttng_strerror(command_ret
));
187 if (!opt_session_name
) {
191 /* Overwrite ret if an error occurred during handle_command() */
192 ret
= command_ret
? command_ret
: ret
;
This page took 0.050635 seconds and 6 git commands to generate.