2 * Copyright (C) 2017 - Julien Desfossez <jdesfossez@efficios.com>
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>
29 #include <common/sessiond-comm/sessiond-comm.h>
30 #include <common/mi-lttng.h>
32 #include "../command.h"
33 #include <lttng/rotation.h>
35 static char *opt_session_name
;
36 static struct mi_writer
*writer
;
44 static struct poptOption long_options
[] = {
45 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
46 {"help", 'h', POPT_ARG_NONE
, 0, OPT_HELP
, 0, 0},
47 {"list-options", 0, POPT_ARG_NONE
, NULL
, OPT_LIST_OPTIONS
, NULL
, NULL
},
48 {"session", 's', POPT_ARG_STRING
, &opt_session_name
, 0, 0, 0},
49 {"timer", 0, POPT_ARG_NONE
, 0, OPT_TIMER
, 0, 0},
53 static int setup_rotate(char *session_name
, uint64_t timer
)
56 struct lttng_rotation_schedule_attr
*attr
= NULL
;
58 attr
= lttng_rotation_schedule_attr_create();
64 /* Open rotation_schedule element */
65 ret
= mi_lttng_writer_open_element(writer
,
66 config_element_rotation_schedule
);
72 ret
= lttng_rotation_schedule_attr_set_session_name(attr
, session_name
);
78 ret
= mi_lttng_writer_write_element_string(writer
,
79 mi_lttng_element_session_name
, session_name
);
86 lttng_rotation_schedule_attr_set_timer_period(attr
, timer
);
87 MSG("Disabling rotation timer on session %s", session_name
);
90 ret
= lttng_rotation_set_schedule(attr
);
92 ERR("%s", lttng_strerror(ret
));
94 ret
= mi_lttng_writer_write_element_string(writer
,
95 mi_lttng_element_rotate_status
, "error");
99 /* Close rotation_schedule element */
100 ret
= mi_lttng_writer_close_element(writer
);
109 ret
= mi_lttng_writer_write_element_string(writer
,
110 mi_lttng_element_rotate_status
, "success");
115 /* Close rotation_schedule element */
116 ret
= mi_lttng_writer_close_element(writer
);
132 * cmd_disable_rotation
134 * The 'enable-rotation <options>' first level command
136 int cmd_disable_rotation(int argc
, const char **argv
)
138 int opt
, ret
= CMD_SUCCESS
, command_ret
= CMD_SUCCESS
, success
= 1;
140 static poptContext pc
;
141 char *session_name
= NULL
;
142 bool free_session_name
= false;
145 pc
= poptGetContext(NULL
, argc
, argv
, long_options
, 0);
146 popt_ret
= poptReadDefaultConfig(pc
, 0);
149 ERR("poptReadDefaultConfig");
153 while ((opt
= poptGetNextOpt(pc
)) != -1) {
158 case OPT_LIST_OPTIONS
:
159 list_cmd_options(stdout
, long_options
);
170 if (opt_session_name
== NULL
) {
171 session_name
= get_session_name();
172 if (session_name
== NULL
) {
175 free_session_name
= true;
177 session_name
= opt_session_name
;
182 writer
= mi_lttng_writer_create(fileno(stdout
), lttng_opt_mi
);
184 ret
= -LTTNG_ERR_NOMEM
;
188 /* Open command element */
189 ret
= mi_lttng_writer_command_open(writer
,
190 mi_lttng_element_command_disable_rotation
);
196 /* Open output element */
197 ret
= mi_lttng_writer_open_element(writer
,
198 mi_lttng_element_command_output
);
205 /* No config options, just rotate the session now */
207 ERR("No timer given");
211 command_ret
= setup_rotate(session_name
, timer
);
215 ERR("%s", lttng_strerror(command_ret
));
221 /* Close output element */
222 ret
= mi_lttng_writer_close_element(writer
);
228 ret
= mi_lttng_writer_write_element_bool(writer
,
229 mi_lttng_element_command_success
, success
);
235 /* Command element close */
236 ret
= mi_lttng_writer_command_close(writer
);
245 if (writer
&& mi_lttng_writer_destroy(writer
)) {
246 /* Preserve original error code */
247 ret
= ret
? ret
: -LTTNG_ERR_MI_IO_FAIL
;
250 /* Overwrite ret if an error occurred with start_tracing */
251 ret
= command_ret
? command_ret
: ret
;
253 if (free_session_name
) {