X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fbin%2Flttng%2Fcommands%2Fstatus.cpp;fp=src%2Fbin%2Flttng%2Fcommands%2Fstatus.cpp;h=23e8c03d390bc8fa2007cd82e7e271ec5bcda810;hp=0000000000000000000000000000000000000000;hb=48a4000561343808724f7cb5fa8c131877489ccd;hpb=81663f073dbfb4b61c06a0ceb8ca33c4fc41b1c5 diff --git a/src/bin/lttng/commands/status.cpp b/src/bin/lttng/commands/status.cpp new file mode 100644 index 000000000..23e8c03d3 --- /dev/null +++ b/src/bin/lttng/commands/status.cpp @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2015 Philippe Proulx + * + * SPDX-License-Identifier: GPL-2.0-only + * + */ + +#define _LGPL_SOURCE +#include +#include +#include +#include +#include +#include +#include + +#include "../command.h" +#include "../utils.h" +#include + +#ifdef LTTNG_EMBED_HELP +static const char help_msg[] = +#include +; +#endif + +enum { + OPT_HELP = 1, + OPT_LIST_OPTIONS, +}; + +static struct poptOption long_options[] = { + /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */ + {"help", 'h', POPT_ARG_NONE, NULL, OPT_HELP, NULL, NULL}, + {"list-options", 0, POPT_ARG_NONE, NULL, OPT_LIST_OPTIONS, NULL, NULL}, + {0, 0, 0, 0, 0, 0, 0} +}; + +static int status(void) +{ + const char *argv[2]; + int ret = CMD_SUCCESS; + char *session_name = NULL; + + session_name = get_session_name(); + if (!session_name) { + ret = CMD_ERROR; + goto end; + } + + argv[0] = "list"; + argv[1] = session_name; + ret = cmd_list(2, argv); +end: + free(session_name); + return ret; +} + +/* + * The 'status ' first level command + */ +int cmd_status(int argc, const char **argv) +{ + int opt, ret = CMD_SUCCESS; + static poptContext pc; + + pc = poptGetContext(NULL, argc, argv, long_options, 0); + poptReadDefaultConfig(pc, 0); + + while ((opt = poptGetNextOpt(pc)) != -1) { + switch (opt) { + case OPT_HELP: + SHOW_HELP(); + goto end; + case OPT_LIST_OPTIONS: + list_cmd_options(stdout, long_options); + goto end; + default: + ret = CMD_UNDEFINED; + goto end; + } + } + + if (poptPeekArg(pc) != NULL) { + ERR("This command does not accept positional arguments.\n"); + ret = CMD_UNDEFINED; + goto end; + } + + ret = status(); +end: + poptFreeContext(pc); + return ret; +}