X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fbin%2Flttng%2Fcommands%2Fset_session.c;h=75762a2d8d6fb6727cabf9513ecce7527ad318fe;hb=d569ed5fd0949c61aecf37b4ab6aa39d7b82b980;hp=14fe9afd8362ee20eaaf2bc5618460af7217d953;hpb=7f0c090ded845bb58c341f75d28d2379db5c3e7e;p=lttng-tools.git diff --git a/src/bin/lttng/commands/set_session.c b/src/bin/lttng/commands/set_session.c index 14fe9afd8..75762a2d8 100644 --- a/src/bin/lttng/commands/set_session.c +++ b/src/bin/lttng/commands/set_session.c @@ -1,21 +1,10 @@ /* - * Copyright (C) 2011 - David Goulet + * Copyright (C) 2011 EfficiOS Inc. * - * 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 _GNU_SOURCE #define _LGPL_SOURCE #include #include @@ -30,7 +19,11 @@ #include "../command.h" -static char *opt_session_name; +#ifdef LTTNG_EMBED_HELP +static const char help_msg[] = +#include +; +#endif enum { OPT_HELP = 1, @@ -46,23 +39,10 @@ static struct poptOption long_options[] = { {0, 0, 0, 0, 0, 0, 0} }; -/* - * usage - */ -static void usage(FILE *ofp) -{ - fprintf(ofp, "usage: lttng set-session NAME [OPTIONS]\n"); - fprintf(ofp, "\n"); - fprintf(ofp, "Options:\n"); - fprintf(ofp, " -h, --help Show this help\n"); - fprintf(ofp, " --list-options Simple listing of options\n"); - fprintf(ofp, "\n"); -} - /* * Print the necessary mi for a session and name. */ -static int mi_print(char *session_name) +static int mi_print(const char *session_name) { int ret; @@ -103,14 +83,14 @@ end: /* * set_session */ -static int set_session(void) +static int set_session(const char *session_name) { int ret = CMD_SUCCESS; int count, i; unsigned int session_found = 0; struct lttng_session *sessions; - if (opt_session_name && strlen(opt_session_name) > NAME_MAX) { + if (session_name && strlen(session_name) > NAME_MAX) { ERR("Session name too long. Length must be lower or equal to %d", NAME_MAX); ret = CMD_ERROR; @@ -125,28 +105,28 @@ static int set_session(void) } for (i = 0; i < count; i++) { - if (strncmp(sessions[i].name, opt_session_name, NAME_MAX) == 0) { + if (strncmp(sessions[i].name, session_name, NAME_MAX) == 0) { session_found = 1; break; } } if (!session_found) { - ERR("Session '%s' not found", opt_session_name); + ERR("Session '%s' not found", session_name); ret = CMD_ERROR; goto error; } - ret = config_init(opt_session_name); + ret = config_init(session_name); if (ret < 0) { ERR("Unable to set session name"); ret = CMD_ERROR; goto error; } - MSG("Session set to %s", opt_session_name); + MSG("Session set to %s", session_name); if (lttng_opt_mi) { - ret = mi_print(opt_session_name); + ret = mi_print(session_name); if (ret) { ret = CMD_ERROR; goto error; @@ -168,6 +148,7 @@ int cmd_set_session(int argc, const char **argv) { int opt, ret = CMD_SUCCESS, command_ret = CMD_SUCCESS, success = 1; static poptContext pc; + const char *arg_session_name = NULL; pc = poptGetContext(NULL, argc, argv, long_options, 0); poptReadDefaultConfig(pc, 0); @@ -175,22 +156,20 @@ int cmd_set_session(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); goto end; default: - usage(stderr); ret = CMD_UNDEFINED; goto end; } } - opt_session_name = (char *) poptGetArg(pc); - if (opt_session_name == NULL) { + arg_session_name = poptGetArg(pc); + if (arg_session_name == NULL) { ERR("Missing session name"); - usage(stderr); ret = CMD_ERROR; goto end; } @@ -220,7 +199,7 @@ int cmd_set_session(int argc, const char **argv) } } - command_ret = set_session(); + command_ret = set_session(arg_session_name); if (command_ret) { success = 0; } @@ -257,7 +236,7 @@ end: ret = ret ? ret : LTTNG_ERR_MI_IO_FAIL; } - /* Overwrite ret if an error occured during set_session() */ + /* Overwrite ret if an error occurred during set_session() */ ret = command_ret ? command_ret : ret; poptFreeContext(pc);