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 int opt_destroy_all
;
38 static struct poptOption long_options
[] = {
39 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
40 {"help", 'h', POPT_ARG_NONE
, 0, OPT_HELP
, 0, 0},
41 {"all", 'a', POPT_ARG_VAL
, &opt_destroy_all
, 1, 0, 0},
42 {"list-options", 0, POPT_ARG_NONE
, NULL
, OPT_LIST_OPTIONS
, NULL
, NULL
},
49 static void usage(FILE *ofp
)
51 fprintf(ofp
, "usage: lttng destroy [options] [NAME]\n");
53 fprintf(ofp
, "Where NAME is an optional session name. If not specified, lttng will\n");
54 fprintf(ofp
, "get it from the configuration directory (.lttng).\n");
56 fprintf(ofp
, " -h, --help Show this help\n");
57 fprintf(ofp
, " -a, --all Destroy all sessions\n");
58 fprintf(ofp
, " --list-options Simple listing of options\n");
65 * Unregister the provided session to the session daemon. On success, removes
66 * the default configuration.
68 static int destroy_session(const char *session_name
)
72 ret
= lttng_destroy_session(session_name
);
75 case LTTCOMM_SESS_NOT_FOUND
:
76 WARN("Session name %s not found", session_name
);
84 MSG("Session %s destroyed", session_name
);
85 config_destroy_default();
92 * destroy_all_sessions
94 * Call destroy_sessions for each registered sessions
96 static int destroy_all_sessions()
98 int count
, i
, ret
= CMD_SUCCESS
;
99 struct lttng_session
*sessions
;
101 count
= lttng_list_sessions(&sessions
);
103 MSG("No session found, nothing to do.");
105 for (i
= 0; i
< count
; i
++) {
106 ret
= destroy_session(sessions
[i
].name
);
116 * get_default_session_name
118 * Returns the default sessions name, if any
120 static int get_default_session_name(char **name
)
122 char *session_name
= get_session_name();
123 if (session_name
== NULL
) {
126 *name
= session_name
;
131 * The 'destroy <options>' first level command
133 int cmd_destroy(int argc
, const char **argv
)
136 int ret
= CMD_SUCCESS
;
137 static poptContext pc
;
138 char *session_name
= NULL
;
140 pc
= poptGetContext(NULL
, argc
, argv
, long_options
, 0);
141 poptReadDefaultConfig(pc
, 0);
143 while ((opt
= poptGetNextOpt(pc
)) != -1) {
148 case OPT_LIST_OPTIONS
:
149 list_cmd_options(stdout
, long_options
);
159 session_name
= (char *) poptGetArg(pc
);
162 * ignore session name in case all
163 * sessions are to be destroyed
165 if (opt_destroy_all
) {
166 ret
= destroy_all_sessions();
169 if (session_name
== NULL
) {
170 ret
= get_default_session_name(&session_name
);
171 if (ret
< 0 || session_name
== NULL
) {
175 ret
= destroy_session(session_name
);
179 if (session_name
!= NULL
) {
This page took 0.047766 seconds and 6 git commands to generate.