lttng: add status command
[lttng-tools.git] / src / bin / lttng / commands / status.c
CommitLineData
54a0adbf
PP
1/*
2 * Copyright (C) 2015 - Philippe Proulx <pproulx@efficios.com>
3 *
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.
7 *
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.
12 *
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.
16 */
17
18#define _GNU_SOURCE
19#define _LGPL_SOURCE
20#include <popt.h>
21#include <stdio.h>
22#include <stdlib.h>
23#include <string.h>
24#include <sys/stat.h>
25#include <sys/types.h>
26#include <unistd.h>
27
28#include "../command.h"
29#include "../utils.h"
30#include <config.h>
31
32enum {
33 OPT_HELP = 1,
34 OPT_LIST_OPTIONS,
35};
36
37static struct poptOption long_options[] = {
38 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
39 {"help", 'h', POPT_ARG_NONE, NULL, OPT_HELP, NULL, NULL},
40 {"list-options", 0, POPT_ARG_NONE, NULL, OPT_LIST_OPTIONS, NULL, NULL},
41 {0, 0, 0, 0, 0, 0, 0}
42};
43
44static void usage(FILE *ofp)
45{
46 fprintf(ofp, "Usage: lttng status [options]\n");
47 fprintf(ofp, "\n");
48 fprintf(ofp, "Options:\n");
49 fprintf(ofp, " -h, --help Show this help\n");
50 fprintf(ofp, " --list-options List options\n");
51}
52
53static int status(void)
54{
55 const char *argv[2];
56 int ret = CMD_SUCCESS;
57 char *session_name = NULL;
58
59 session_name = get_session_name();
60 if (!session_name) {
61 ret = CMD_ERROR;
62 goto end;
63 }
64
65 argv[0] = "list";
66 argv[1] = session_name;
67 ret = cmd_list(2, argv);
68end:
69 free(session_name);
70 return ret;
71}
72
73/*
74 * The 'status <options>' first level command
75 */
76int cmd_status(int argc, const char **argv)
77{
78 int opt, ret = CMD_SUCCESS;
79 static poptContext pc;
80
81 pc = poptGetContext(NULL, argc, argv, long_options, 0);
82 poptReadDefaultConfig(pc, 0);
83
84 while ((opt = poptGetNextOpt(pc)) != -1) {
85 switch (opt) {
86 case OPT_HELP:
87 usage(stdout);
88 goto end;
89 case OPT_LIST_OPTIONS:
90 list_cmd_options(stdout, long_options);
91 goto end;
92 default:
93 usage(stderr);
94 ret = CMD_UNDEFINED;
95 goto end;
96 }
97 }
98
99 if (poptPeekArg(pc) != NULL) {
100 ERR("This command does not accept positional arguments.\n");
101 usage(stderr);
102 ret = CMD_UNDEFINED;
103 goto end;
104 }
105
106 ret = status();
107end:
108 poptFreeContext(pc);
109 return ret;
110}
This page took 0.028027 seconds and 5 git commands to generate.