2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
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.
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.
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.
24 #include <sys/types.h>
27 #include "../command.h"
29 #include <common/sessiond-comm/sessiond-comm.h>
31 static char *opt_session_name
;
32 static int opt_destroy_all
;
39 static struct poptOption long_options
[] = {
40 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
41 {"help", 'h', POPT_ARG_NONE
, 0, OPT_HELP
, 0, 0},
42 {"all", 'a', POPT_ARG_VAL
, &opt_destroy_all
, 1, 0, 0},
43 {"list-options", 0, POPT_ARG_NONE
, NULL
, OPT_LIST_OPTIONS
, NULL
, NULL
},
50 static void usage(FILE *ofp
)
52 fprintf(ofp
, "usage: lttng destroy [NAME] [OPTIONS]\n");
54 fprintf(ofp
, "Where NAME is an optional session name. If not specified, lttng will\n");
55 fprintf(ofp
, "get it from the configuration directory (.lttng).\n");
57 fprintf(ofp
, "Options:\n");
58 fprintf(ofp
, " -h, --help Show this help\n");
59 fprintf(ofp
, " -a, --all Destroy all sessions\n");
60 fprintf(ofp
, " --list-options Simple listing of options\n");
67 * Unregister the provided session to the session daemon. On success, removes
68 * the default configuration.
70 static int destroy_session(const char *session_name
)
74 ret
= lttng_destroy_session(session_name
);
77 case LTTNG_ERR_SESS_NOT_FOUND
:
78 WARN("Session name %s not found", session_name
);
81 ERR("%s", lttng_strerror(ret
));
87 MSG("Session %s destroyed", session_name
);
88 config_destroy_default();
95 * destroy_all_sessions
97 * Call destroy_sessions for each registered sessions
99 static int destroy_all_sessions()
101 int count
, i
, ret
= CMD_SUCCESS
;
102 struct lttng_session
*sessions
;
104 count
= lttng_list_sessions(&sessions
);
106 MSG("No session found, nothing to do.");
107 } else if (count
< 0) {
108 ERR("%s", lttng_strerror(ret
));
112 for (i
= 0; i
< count
; i
++) {
113 ret
= destroy_session(sessions
[i
].name
);
123 * The 'destroy <options>' first level command
125 int cmd_destroy(int argc
, const char **argv
)
128 int ret
= CMD_SUCCESS
;
129 static poptContext pc
;
130 char *session_name
= NULL
;
132 pc
= poptGetContext(NULL
, argc
, argv
, long_options
, 0);
133 poptReadDefaultConfig(pc
, 0);
135 while ((opt
= poptGetNextOpt(pc
)) != -1) {
140 case OPT_LIST_OPTIONS
:
141 list_cmd_options(stdout
, long_options
);
151 /* Ignore session name in case all sessions are to be destroyed */
152 if (opt_destroy_all
) {
153 ret
= destroy_all_sessions();
157 opt_session_name
= (char *) poptGetArg(pc
);
159 if (opt_session_name
== NULL
) {
160 /* No session name specified, lookup default */
161 session_name
= get_session_name();
162 if (session_name
== NULL
) {
167 session_name
= opt_session_name
;
170 ret
= destroy_session(session_name
);
173 if (opt_session_name
== NULL
) {
This page took 0.047655 seconds and 4 git commands to generate.