Tests: Fix: Use '.logfile' instead of '.log' for test app output
[lttng-tools.git] / src / bin / lttng / commands / status.cpp
1 /*
2 * Copyright (C) 2015 Philippe Proulx <pproulx@efficios.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 */
7
8 #define _LGPL_SOURCE
9 #include "../command.hpp"
10 #include "../utils.hpp"
11
12 #include <config.h>
13 #include <popt.h>
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <string.h>
17 #include <sys/stat.h>
18 #include <sys/types.h>
19 #include <unistd.h>
20
21 #ifdef LTTNG_EMBED_HELP
22 static const char help_msg[] =
23 #include <lttng-status.1.h>
24 ;
25 #endif
26
27 enum {
28 OPT_HELP = 1,
29 OPT_LIST_OPTIONS,
30 };
31
32 static struct poptOption long_options[] = {
33 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
34 { "help", 'h', POPT_ARG_NONE, nullptr, OPT_HELP, nullptr, nullptr },
35 { "list-options", 0, POPT_ARG_NONE, nullptr, OPT_LIST_OPTIONS, nullptr, nullptr },
36 { nullptr, 0, 0, nullptr, 0, nullptr, nullptr }
37 };
38
39 static int status()
40 {
41 const char *argv[2];
42 int ret = CMD_SUCCESS;
43 char *session_name = nullptr;
44
45 session_name = get_session_name();
46 if (!session_name) {
47 ret = CMD_ERROR;
48 goto end;
49 }
50
51 argv[0] = "list";
52 argv[1] = session_name;
53 ret = cmd_list(2, argv);
54 end:
55 free(session_name);
56 return ret;
57 }
58
59 /*
60 * The 'status <options>' first level command
61 */
62 int cmd_status(int argc, const char **argv)
63 {
64 int opt, ret = CMD_SUCCESS;
65 static poptContext pc;
66
67 pc = poptGetContext(nullptr, argc, argv, long_options, 0);
68 poptReadDefaultConfig(pc, 0);
69
70 while ((opt = poptGetNextOpt(pc)) != -1) {
71 switch (opt) {
72 case OPT_HELP:
73 SHOW_HELP();
74 goto end;
75 case OPT_LIST_OPTIONS:
76 list_cmd_options(stdout, long_options);
77 goto end;
78 default:
79 ret = CMD_UNDEFINED;
80 goto end;
81 }
82 }
83
84 if (poptPeekArg(pc) != nullptr) {
85 ERR("This command does not accept positional arguments.\n");
86 ret = CMD_UNDEFINED;
87 goto end;
88 }
89
90 ret = status();
91 end:
92 poptFreeContext(pc);
93 return ret;
94 }
This page took 0.031314 seconds and 4 git commands to generate.