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