Commit | Line | Data |
---|---|---|
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 PP |
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 | ||
4fc83d94 PP |
21 | #ifdef LTTNG_EMBED_HELP |
22 | static const char help_msg[] = | |
23 | #include <lttng-status.1.h> | |
24 | ; | |
25 | #endif | |
26 | ||
54a0adbf PP |
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 | ||
54a0adbf PP |
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: | |
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 | ||
84 | if (poptPeekArg(pc) != NULL) { | |
85 | ERR("This command does not accept positional arguments.\n"); | |
54a0adbf PP |
86 | ret = CMD_UNDEFINED; |
87 | goto end; | |
88 | } | |
89 | ||
90 | ret = status(); | |
91 | end: | |
92 | poptFreeContext(pc); | |
93 | return ret; | |
94 | } |