Move to kernel style SPDX license identifiers
[lttng-tools.git] / src / bin / lttng / commands / status.c
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 <popt.h>
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <string.h>
13 #include <sys/stat.h>
14 #include <sys/types.h>
15 #include <unistd.h>
16
17 #include "../command.h"
18 #include "../utils.h"
19 #include <config.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, NULL, OPT_HELP, NULL, NULL},
35 {"list-options", 0, POPT_ARG_NONE, NULL, OPT_LIST_OPTIONS, NULL, NULL},
36 {0, 0, 0, 0, 0, 0, 0}
37 };
38
39 static int status(void)
40 {
41 const char *argv[2];
42 int ret = CMD_SUCCESS;
43 char *session_name = NULL;
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(NULL, 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) != NULL) {
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.032 seconds and 5 git commands to generate.