1 /* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2005 Mathieu Desnoyers
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 as
6 * 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
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
27 #include <gdk/gdkkeysyms.h>
29 #include <lttv/lttv.h>
30 #include <lttv/module.h>
31 #include <lttv/hook.h>
33 #include <lttvwindow/lttvwindow.h>
34 #include <lttvwindow/lttvwindowtraces.h>
36 #include "hTraceControlInsert.xpm"
37 #include "TraceControlStart.xpm"
38 #include "TraceControlPause.xpm"
39 #include "TraceControlStop.xpm"
41 #include <sys/types.h>
49 #define MAX_ARGS_LEN PATH_MAX * 10
51 GSList
*g_control_list
= NULL
;
53 /*! \file lttv/modules/gui/tracecontrol/tracecontrol.c
54 * \brief Graphic trace start/stop control interface.
56 * This plugin interacts with lttctl to start/stop tracing. It needs to take the
57 * root password to be able to interact with lttctl.
61 typedef struct _ControlData ControlData
;
66 GtkWidget
*guicontrol_get_widget(ControlData
*tcd
);
67 ControlData
*gui_control(Tab
*tab
);
68 void gui_control_destructor(ControlData
*tcd
);
69 GtkWidget
* h_guicontrol(Tab
*tab
);
70 void control_destroy_walk(gpointer data
, gpointer user_data
);
76 static void start_clicked (GtkButton
*button
, gpointer user_data
);
77 static void pause_clicked (GtkButton
*button
, gpointer user_data
);
78 static void unpause_clicked (GtkButton
*button
, gpointer user_data
);
79 static void stop_clicked (GtkButton
*button
, gpointer user_data
);
83 * @struct _ControlData
85 * @brief Main structure of gui control
88 Tab
*tab
; /**< current tab of module */
90 GtkWidget
*window
; /**< window */
92 GtkWidget
*main_box
; /**< main container */
93 GtkWidget
*start_button
;
94 GtkWidget
*pause_button
;
95 GtkWidget
*unpause_button
;
96 GtkWidget
*stop_button
;
97 GtkWidget
*username_label
;
98 GtkWidget
*username_entry
;
99 GtkWidget
*password_label
;
100 GtkWidget
*password_entry
;
101 GtkWidget
*channel_dir_label
;
102 GtkWidget
*channel_dir_entry
;
103 GtkWidget
*trace_dir_label
;
104 GtkWidget
*trace_dir_entry
;
105 GtkWidget
*trace_name_label
;
106 GtkWidget
*trace_name_entry
;
107 GtkWidget
*trace_mode_label
;
108 GtkWidget
*trace_mode_combo
;
109 GtkWidget
*start_daemon_label
;
110 GtkWidget
*start_daemon_check
;
111 GtkWidget
*append_label
;
112 GtkWidget
*append_check
;
113 GtkWidget
*optional_label
;
114 GtkWidget
*subbuf_size_label
;
115 GtkWidget
*subbuf_size_entry
;
116 GtkWidget
*subbuf_num_label
;
117 GtkWidget
*subbuf_num_entry
;
118 GtkWidget
*lttctl_path_label
;
119 GtkWidget
*lttctl_path_entry
;
120 GtkWidget
*lttd_path_label
;
121 GtkWidget
*lttd_path_entry
;
122 GtkWidget
*fac_path_label
;
123 GtkWidget
*fac_path_entry
;
127 * @fn GtkWidget* guicontrol_get_widget(ControlData*)
129 * This function returns the current main widget
130 * used by this module
131 * @param tcd the module struct
132 * @return The main widget
135 guicontrol_get_widget(ControlData
*tcd
)
141 * @fn ControlData* gui_control(Tab*)
143 * Constructor is used to create ControlData data structure.
144 * @param tab The tab structure used by the widget
145 * @return The Filter viewer data created.
148 gui_control(Tab
*tab
)
150 g_debug("filter::gui_control()");
153 GtkCellRenderer
*renderer
;
154 GtkTreeViewColumn
*column
;
156 ControlData
* tcd
= g_new(ControlData
,1);
160 tcd
->window
= gtk_window_new(GTK_WINDOW_TOPLEVEL
);
161 gtk_window_set_title(GTK_WINDOW(tcd
->window
), "LTTng Trace Control");
163 * Initiating GtkTable layout
164 * starts with 2 rows and 5 columns and
165 * expands when expressions added
167 tcd
->main_box
= gtk_table_new(14,7,FALSE
);
168 gtk_table_set_row_spacings(GTK_TABLE(tcd
->main_box
),5);
169 gtk_table_set_col_spacings(GTK_TABLE(tcd
->main_box
),5);
171 gtk_container_add(GTK_CONTAINER(tcd
->window
), GTK_WIDGET(tcd
->main_box
));
173 GList
*focus_chain
= NULL
;
176 * start/pause/stop buttons
180 pixbuf
= gdk_pixbuf_new_from_xpm_data((const char **)TraceControlStart_xpm
);
181 image
= gtk_image_new_from_pixbuf(pixbuf
);
182 tcd
->start_button
= gtk_button_new_with_label("start");
183 gtk_button_set_image(GTK_BUTTON(tcd
->start_button
), image
);
184 gtk_button_set_alignment(GTK_BUTTON(tcd
->start_button
), 0.0, 0.0);
185 gtk_widget_show (tcd
->start_button
);
186 gtk_table_attach( GTK_TABLE(tcd
->main_box
),tcd
->start_button
,6,7,0,1,GTK_FILL
,GTK_FILL
,2,2);
188 pixbuf
= gdk_pixbuf_new_from_xpm_data((const char **)TraceControlPause_xpm
);
189 image
= gtk_image_new_from_pixbuf(pixbuf
);
190 tcd
->pause_button
= gtk_button_new_with_label("pause");
191 gtk_button_set_image(GTK_BUTTON(tcd
->pause_button
), image
);
192 gtk_button_set_alignment(GTK_BUTTON(tcd
->pause_button
), 0.0, 0.0);
193 gtk_widget_show (tcd
->pause_button
);
194 gtk_table_attach( GTK_TABLE(tcd
->main_box
),tcd
->pause_button
,6,7,1,2,GTK_FILL
,GTK_FILL
,2,2);
196 pixbuf
= gdk_pixbuf_new_from_xpm_data((const char **)TraceControlPause_xpm
);
197 image
= gtk_image_new_from_pixbuf(pixbuf
);
198 tcd
->unpause_button
= gtk_button_new_with_label("unpause");
199 gtk_button_set_image(GTK_BUTTON(tcd
->unpause_button
), image
);
200 gtk_button_set_alignment(GTK_BUTTON(tcd
->unpause_button
), 0.0, 0.0);
201 gtk_widget_show (tcd
->unpause_button
);
202 gtk_table_attach( GTK_TABLE(tcd
->main_box
),tcd
->unpause_button
,6,7,2,3,GTK_FILL
,GTK_FILL
,2,2);
204 pixbuf
= gdk_pixbuf_new_from_xpm_data((const char **)TraceControlStop_xpm
);
205 image
= gtk_image_new_from_pixbuf(pixbuf
);
206 tcd
->stop_button
= gtk_button_new_with_label("stop");
207 gtk_button_set_image(GTK_BUTTON(tcd
->stop_button
), image
);
208 gtk_button_set_alignment(GTK_BUTTON(tcd
->stop_button
), 0.0, 0.0);
209 gtk_widget_show (tcd
->stop_button
);
210 gtk_table_attach( GTK_TABLE(tcd
->main_box
),tcd
->stop_button
,6,7,3,4,GTK_FILL
,GTK_FILL
,2,2);
213 * First half of the filter window
214 * - textual entry of filter expression
215 * - processing button
217 tcd
->username_label
= gtk_label_new("Username:");
218 gtk_widget_show (tcd
->username_label
);
219 tcd
->username_entry
= gtk_entry_new();
220 gtk_entry_set_text(GTK_ENTRY(tcd
->username_entry
),"root");
221 gtk_widget_show (tcd
->username_entry
);
222 gtk_table_attach( GTK_TABLE(tcd
->main_box
),tcd
->username_label
,0,2,0,1,GTK_FILL
,GTK_FILL
,2,2);
223 gtk_table_attach( GTK_TABLE(tcd
->main_box
),tcd
->username_entry
,2,6,0,1,GTK_FILL
|GTK_EXPAND
|GTK_SHRINK
,GTK_FILL
,0,0);
227 tcd
->password_label
= gtk_label_new("Password:");
228 gtk_widget_show (tcd
->password_label
);
229 tcd
->password_entry
= gtk_entry_new();
230 gtk_entry_set_visibility(GTK_ENTRY(tcd
->password_entry
), FALSE
);
231 gtk_widget_show (tcd
->password_entry
);
232 gtk_table_attach( GTK_TABLE(tcd
->main_box
),tcd
->password_label
,0,2,1,2,GTK_FILL
,GTK_FILL
,2,2);
233 gtk_table_attach( GTK_TABLE(tcd
->main_box
),tcd
->password_entry
,2,6,1,2,GTK_FILL
|GTK_EXPAND
|GTK_SHRINK
,GTK_FILL
,0,0);
236 tcd
->channel_dir_label
= gtk_label_new("Channel directory:");
237 gtk_widget_show (tcd
->channel_dir_label
);
238 tcd
->channel_dir_entry
= gtk_entry_new();
239 gtk_entry_set_text(GTK_ENTRY(tcd
->channel_dir_entry
),"/mnt/relayfs/ltt");
240 gtk_widget_show (tcd
->channel_dir_entry
);
241 gtk_table_attach( GTK_TABLE(tcd
->main_box
),tcd
->channel_dir_label
,0,2,2,3,GTK_FILL
,GTK_FILL
,2,2);
242 gtk_table_attach( GTK_TABLE(tcd
->main_box
),tcd
->channel_dir_entry
,2,6,2,3,GTK_FILL
|GTK_EXPAND
|GTK_SHRINK
,GTK_FILL
,0,0);
244 tcd
->trace_dir_label
= gtk_label_new("Trace directory:");
245 gtk_widget_show (tcd
->trace_dir_label
);
246 tcd
->trace_dir_entry
= gtk_entry_new();
247 gtk_entry_set_text(GTK_ENTRY(tcd
->trace_dir_entry
),"/tmp/trace1");
248 gtk_widget_show (tcd
->trace_dir_entry
);
249 gtk_table_attach( GTK_TABLE(tcd
->main_box
),tcd
->trace_dir_label
,0,2,3,4,GTK_FILL
,GTK_FILL
,2,2);
250 gtk_table_attach( GTK_TABLE(tcd
->main_box
),tcd
->trace_dir_entry
,2,6,3,4,GTK_FILL
|GTK_EXPAND
|GTK_SHRINK
,GTK_FILL
,0,0);
252 tcd
->trace_name_label
= gtk_label_new("Trace name:");
253 gtk_widget_show (tcd
->trace_name_label
);
254 tcd
->trace_name_entry
= gtk_entry_new();
255 gtk_entry_set_text(GTK_ENTRY(tcd
->trace_name_entry
),"trace");
256 gtk_widget_show (tcd
->trace_name_entry
);
257 gtk_table_attach( GTK_TABLE(tcd
->main_box
),tcd
->trace_name_label
,0,2,4,5,GTK_FILL
,GTK_FILL
,2,2);
258 gtk_table_attach( GTK_TABLE(tcd
->main_box
),tcd
->trace_name_entry
,2,6,4,5,GTK_FILL
|GTK_EXPAND
|GTK_SHRINK
,GTK_FILL
,0,0);
260 tcd
->trace_mode_label
= gtk_label_new("Trace mode ");
261 gtk_widget_show (tcd
->trace_mode_label
);
262 tcd
->trace_mode_combo
= gtk_combo_box_new_text();
263 gtk_combo_box_append_text(GTK_COMBO_BOX(tcd
->trace_mode_combo
),
265 gtk_combo_box_append_text(GTK_COMBO_BOX(tcd
->trace_mode_combo
),
267 gtk_combo_box_set_active(GTK_COMBO_BOX(tcd
->trace_mode_combo
), 0);
268 gtk_widget_show (tcd
->trace_mode_combo
);
269 gtk_table_attach( GTK_TABLE(tcd
->main_box
),tcd
->trace_mode_label
,0,2,5,6,GTK_FILL
,GTK_FILL
,2,2);
270 gtk_table_attach( GTK_TABLE(tcd
->main_box
),tcd
->trace_mode_combo
,2,6,5,6,GTK_FILL
|GTK_EXPAND
|GTK_SHRINK
,GTK_FILL
,0,0);
272 tcd
->start_daemon_label
= gtk_label_new("Start daemon ");
273 gtk_widget_show (tcd
->start_daemon_label
);
274 tcd
->start_daemon_check
= gtk_check_button_new();
275 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(tcd
->start_daemon_check
), TRUE
);
276 gtk_widget_show (tcd
->start_daemon_check
);
277 gtk_table_attach( GTK_TABLE(tcd
->main_box
),tcd
->start_daemon_label
,0,2,6,7,GTK_FILL
,GTK_FILL
,2,2);
278 gtk_table_attach( GTK_TABLE(tcd
->main_box
),tcd
->start_daemon_check
,2,6,6,7,GTK_FILL
,GTK_FILL
,0,0);
280 tcd
->append_label
= gtk_label_new("Append to trace ");
281 gtk_widget_show (tcd
->append_label
);
282 tcd
->append_check
= gtk_check_button_new();
283 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(tcd
->append_check
), FALSE
);
284 gtk_widget_show (tcd
->append_check
);
285 gtk_table_attach( GTK_TABLE(tcd
->main_box
),tcd
->append_label
,0,2,7,8,GTK_FILL
,GTK_FILL
,2,2);
286 gtk_table_attach( GTK_TABLE(tcd
->main_box
),tcd
->append_check
,2,6,7,8,GTK_FILL
,GTK_FILL
,0,0);
289 tcd
->optional_label
= gtk_label_new("Optional fields ");
290 gtk_widget_show (tcd
->optional_label
);
291 gtk_table_attach( GTK_TABLE(tcd
->main_box
),tcd
->optional_label
,0,6,8,9,GTK_FILL
,GTK_FILL
,2,2);
293 tcd
->subbuf_size_label
= gtk_label_new("Subbuffer size:");
294 gtk_widget_show (tcd
->subbuf_size_label
);
295 tcd
->subbuf_size_entry
= gtk_entry_new();
296 gtk_widget_show (tcd
->subbuf_size_entry
);
297 gtk_table_attach( GTK_TABLE(tcd
->main_box
),tcd
->subbuf_size_label
,0,2,9,10,GTK_FILL
,GTK_FILL
,2,2);
298 gtk_table_attach( GTK_TABLE(tcd
->main_box
),tcd
->subbuf_size_entry
,2,6,9,10,GTK_FILL
|GTK_EXPAND
|GTK_SHRINK
,GTK_FILL
,0,0);
300 tcd
->subbuf_num_label
= gtk_label_new("Number of subbuffers:");
301 gtk_widget_show (tcd
->subbuf_num_label
);
302 tcd
->subbuf_num_entry
= gtk_entry_new();
303 gtk_widget_show (tcd
->subbuf_num_entry
);
304 gtk_table_attach( GTK_TABLE(tcd
->main_box
),tcd
->subbuf_num_label
,0,2,10,11,GTK_FILL
,GTK_FILL
,2,2);
305 gtk_table_attach( GTK_TABLE(tcd
->main_box
),tcd
->subbuf_num_entry
,2,6,10,11,GTK_FILL
|GTK_EXPAND
|GTK_SHRINK
,GTK_FILL
,0,0);
307 tcd
->lttctl_path_label
= gtk_label_new("path to lttctl:");
308 gtk_widget_show (tcd
->lttctl_path_label
);
309 tcd
->lttctl_path_entry
= gtk_entry_new();
310 gtk_entry_set_text(GTK_ENTRY(tcd
->lttctl_path_entry
),PACKAGE_BIN_DIR
"/lttctl");
311 gtk_widget_show (tcd
->lttctl_path_entry
);
312 gtk_table_attach( GTK_TABLE(tcd
->main_box
),tcd
->lttctl_path_label
,0,2,11,12,GTK_FILL
,GTK_FILL
,2,2);
313 gtk_table_attach( GTK_TABLE(tcd
->main_box
),tcd
->lttctl_path_entry
,2,6,11,12,GTK_FILL
|GTK_EXPAND
|GTK_SHRINK
,GTK_FILL
,0,0);
316 tcd
->lttd_path_label
= gtk_label_new("path to lttd:");
317 gtk_widget_show (tcd
->lttd_path_label
);
318 tcd
->lttd_path_entry
= gtk_entry_new();
319 gtk_entry_set_text(GTK_ENTRY(tcd
->lttd_path_entry
),PACKAGE_BIN_DIR
"/lttd");
320 gtk_widget_show (tcd
->lttd_path_entry
);
321 gtk_table_attach( GTK_TABLE(tcd
->main_box
),tcd
->lttd_path_label
,0,2,12,13,GTK_FILL
,GTK_FILL
,2,2);
322 gtk_table_attach( GTK_TABLE(tcd
->main_box
),tcd
->lttd_path_entry
,2,6,12,13,GTK_FILL
|GTK_EXPAND
|GTK_SHRINK
,GTK_FILL
,0,0);
325 tcd
->fac_path_label
= gtk_label_new("path to facilities:");
326 gtk_widget_show (tcd
->fac_path_label
);
327 tcd
->fac_path_entry
= gtk_entry_new();
328 gtk_entry_set_text(GTK_ENTRY(tcd
->fac_path_entry
),PACKAGE_DATA_DIR
"/" PACKAGE
"/facilities");
329 gtk_widget_set_size_request(tcd
->fac_path_entry
, 250, -1);
330 gtk_widget_show (tcd
->fac_path_entry
);
331 gtk_table_attach( GTK_TABLE(tcd
->main_box
),tcd
->fac_path_label
,0,2,13,14,GTK_FILL
,GTK_FILL
,2,2);
332 gtk_table_attach( GTK_TABLE(tcd
->main_box
),tcd
->fac_path_entry
,2,6,13,14,GTK_FILL
|GTK_EXPAND
|GTK_SHRINK
,GTK_FILL
,0,0);
334 focus_chain
= g_list_append (focus_chain
, tcd
->username_entry
);
335 focus_chain
= g_list_append (focus_chain
, tcd
->password_entry
);
336 focus_chain
= g_list_append (focus_chain
, tcd
->start_button
);
337 focus_chain
= g_list_append (focus_chain
, tcd
->pause_button
);
338 focus_chain
= g_list_append (focus_chain
, tcd
->unpause_button
);
339 focus_chain
= g_list_append (focus_chain
, tcd
->stop_button
);
340 focus_chain
= g_list_append (focus_chain
, tcd
->channel_dir_entry
);
341 focus_chain
= g_list_append (focus_chain
, tcd
->trace_dir_entry
);
342 focus_chain
= g_list_append (focus_chain
, tcd
->trace_name_entry
);
343 focus_chain
= g_list_append (focus_chain
, tcd
->trace_mode_combo
);
344 focus_chain
= g_list_append (focus_chain
, tcd
->start_daemon_check
);
345 focus_chain
= g_list_append (focus_chain
, tcd
->append_check
);
346 focus_chain
= g_list_append (focus_chain
, tcd
->subbuf_size_entry
);
347 focus_chain
= g_list_append (focus_chain
, tcd
->subbuf_num_entry
);
348 focus_chain
= g_list_append (focus_chain
, tcd
->lttctl_path_entry
);
349 focus_chain
= g_list_append (focus_chain
, tcd
->lttd_path_entry
);
350 focus_chain
= g_list_append (focus_chain
, tcd
->fac_path_entry
);
352 gtk_container_set_focus_chain(GTK_CONTAINER(tcd
->main_box
), focus_chain
);
354 g_signal_connect(G_OBJECT(tcd
->start_button
), "clicked",
355 (GCallback
)start_clicked
, tcd
);
356 g_signal_connect(G_OBJECT(tcd
->pause_button
), "clicked",
357 (GCallback
)pause_clicked
, tcd
);
358 g_signal_connect(G_OBJECT(tcd
->unpause_button
), "clicked",
359 (GCallback
)unpause_clicked
, tcd
);
360 g_signal_connect(G_OBJECT(tcd
->stop_button
), "clicked",
361 (GCallback
)stop_clicked
, tcd
);
364 * show main container
366 gtk_widget_show(tcd
->main_box
);
367 gtk_widget_show(tcd
->window
);
370 g_object_set_data_full(
371 G_OBJECT(guicontrol_get_widget(tcd
)),
372 "control_viewer_data",
374 (GDestroyNotify
)gui_control_destructor
);
376 g_control_list
= g_slist_append(
385 * @fn void gui_control_destructor(ControlData*)
387 * Destructor for the filter gui module
388 * @param tcd The module structure
391 gui_control_destructor(ControlData
*tcd
)
395 /* May already been done by GTK window closing */
396 if(GTK_IS_WIDGET(guicontrol_get_widget(tcd
))){
397 g_info("widget still exists");
400 // lttvwindow_unregister_traceset_notify(tcd->tab,
401 // filter_traceset_changed,
402 // filter_viewer_data);
404 lttvwindowtraces_background_notify_remove(tcd
);
406 g_control_list
= g_slist_remove(g_control_list
, tcd
);
411 static int execute_command(const gchar
*command
, const gchar
*username
,
412 const gchar
*password
, const gchar
*lttd_path
, const gchar
*fac_path
)
416 pid
= forkpty(&fdpty
, NULL
, NULL
, NULL
);
424 /* discuss with su */
425 struct timeval timeout
;
429 struct pollfd pollfd
;
434 /* Read the output from the child terminal before the prompt. If no data in
435 * 200 ms, we stop reading to give the password */
436 g_info("Reading from child console...");
439 pollfd
.events
= POLLIN
|POLLPRI
;
441 num_rdy
= poll(&pollfd
, 1, 200);
444 perror("Poll error");
449 /* Timeout : stop waiting for chars */
450 if(num_rdy
== 0) break;
452 switch(pollfd
.revents
) {
454 g_warning("Error returned in polling fd\n");
458 g_info("Polling FD : hung up.");
462 g_warning("Polling fd tells it is not open");
467 count
= read (fdpty
, buf
, 256);
471 } else if(count
== -1) {
472 perror("Error in read");
478 g_warning("Child hung up too fast");
483 /* Write the password */
484 g_info("Got su prompt, now writing password...");
486 ret
= write(fdpty
, password
, strlen(password
));
487 if(ret
< 0) perror("Error in write");
488 ret
= write(fdpty
, "\n", 1);
489 if(ret
< 0) perror("Error in write");
492 /* Take the output from the terminal and show it on the real console */
493 g_info("Getting data from child terminal...");
497 pollfd
.events
= POLLIN
|POLLPRI
;
499 num_rdy
= poll(&pollfd
, 1, -1);
502 perror("Poll error");
506 if(num_rdy
== 0) break;
508 switch(pollfd
.revents
) {
510 g_warning("Error returned in polling fd\n");
514 g_info("Polling FD : hung up.");
518 g_warning("Polling fd tells it is not open");
523 count
= read (fdpty
, buf
, 256);
527 } else if(count
== -1) {
528 perror("Error in read");
533 if(num_hup
> 0) goto wait_child
;
536 g_info("Waiting for child exit...");
538 ret
= waitpid(pid
, &status
, 0);
540 if(WIFEXITED(status
))
541 if(WEXITSTATUS(status
) != 0) {
542 retval
= WEXITSTATUS(status
);
543 g_warning("An error occured in the su command : %s",
547 g_info("Child exited.");
549 } else if(pid
== 0) {
550 /* Setup environment variables */
551 if(strcmp(lttd_path
, "") != 0)
552 setenv("LTT_DAEMON", lttd_path
, 1);
553 if(strcmp(fac_path
, "") != 0)
554 setenv("LTT_FACILITIES", fac_path
, 1);
556 g_message("Executing (as %s) : %s\n", username
, command
);
558 execlp("su", "su", "-p", "-c", command
, username
, NULL
);
559 exit(-1); /* not supposed to happen! */
561 //gint ret = execvp();
565 g_warning("Error happened when forking for su");
574 void start_clicked (GtkButton
*button
, gpointer user_data
)
576 ControlData
*tcd
= (ControlData
*)user_data
;
578 const gchar
*username
= gtk_entry_get_text(GTK_ENTRY(tcd
->username_entry
));
579 const gchar
*password
= gtk_entry_get_text(GTK_ENTRY(tcd
->password_entry
));
580 const gchar
*channel_dir
=
581 gtk_entry_get_text(GTK_ENTRY(tcd
->channel_dir_entry
));
582 const gchar
*trace_dir
= gtk_entry_get_text(GTK_ENTRY(tcd
->trace_dir_entry
));
583 const gchar
*trace_name
=
584 gtk_entry_get_text(GTK_ENTRY(tcd
->trace_name_entry
));
586 const gchar
*trace_mode_sel
=
587 gtk_combo_box_get_active_text(GTK_COMBO_BOX(tcd
->trace_mode_combo
));
588 const gchar
*trace_mode
;
589 if(strcmp(trace_mode_sel
, "normal") == 0)
590 trace_mode
= "normal";
592 trace_mode
= "flight";
594 gboolean start_daemon
=
595 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(tcd
->start_daemon_check
));
598 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(tcd
->append_check
));
600 const gchar
*subbuf_size
=
601 gtk_entry_get_text(GTK_ENTRY(tcd
->subbuf_size_entry
));
602 const gchar
*subbuf_num
=
603 gtk_entry_get_text(GTK_ENTRY(tcd
->subbuf_num_entry
));
604 const gchar
*lttctl_path
=
605 gtk_entry_get_text(GTK_ENTRY(tcd
->lttctl_path_entry
));
606 const gchar
*lttd_path
= gtk_entry_get_text(GTK_ENTRY(tcd
->lttd_path_entry
));
607 const gchar
*fac_path
= gtk_entry_get_text(GTK_ENTRY(tcd
->fac_path_entry
));
610 /* Setup arguments to su */
612 gchar args
[MAX_ARGS_LEN
];
613 gint args_left
= MAX_ARGS_LEN
- 1; /* for \0 */
618 strncat(args
, "exec", args_left
);
619 args_left
= MAX_ARGS_LEN
- strlen(args
) - 1;
622 strncat(args
, " ", args_left
);
623 args_left
= MAX_ARGS_LEN
- strlen(args
) - 1;
625 if(strcmp(lttctl_path
, "") == 0)
626 strncat(args
, "lttctl", args_left
);
628 strncat(args
, lttctl_path
, args_left
);
629 args_left
= MAX_ARGS_LEN
- strlen(args
) - 1;
632 strncat(args
, " ", args_left
);
633 args_left
= MAX_ARGS_LEN
- strlen(args
) - 1;
636 strncat(args
, "-l ", args_left
);
637 args_left
= MAX_ARGS_LEN
- strlen(args
) - 1;
638 strncat(args
, channel_dir
, args_left
);
639 args_left
= MAX_ARGS_LEN
- strlen(args
) - 1;
642 strncat(args
, " ", args_left
);
643 args_left
= MAX_ARGS_LEN
- strlen(args
) - 1;
646 strncat(args
, "-t ", args_left
);
647 args_left
= MAX_ARGS_LEN
- strlen(args
) - 1;
648 strncat(args
, trace_dir
, args_left
);
649 args_left
= MAX_ARGS_LEN
- strlen(args
) - 1;
652 strncat(args
, " ", args_left
);
653 args_left
= MAX_ARGS_LEN
- strlen(args
) - 1;
656 strncat(args
, "-n ", args_left
);
657 args_left
= MAX_ARGS_LEN
- strlen(args
) - 1;
658 strncat(args
, trace_name
, args_left
);
659 args_left
= MAX_ARGS_LEN
- strlen(args
) - 1;
662 strncat(args
, " ", args_left
);
663 args_left
= MAX_ARGS_LEN
- strlen(args
) - 1;
666 strncat(args
, "-m ", args_left
);
667 args_left
= MAX_ARGS_LEN
- strlen(args
) - 1;
668 strncat(args
, trace_mode
, args_left
);
669 args_left
= MAX_ARGS_LEN
- strlen(args
) - 1;
672 strncat(args
, " ", args_left
);
673 args_left
= MAX_ARGS_LEN
- strlen(args
) - 1;
677 strncat(args
, "-d", args_left
);
678 args_left
= MAX_ARGS_LEN
- strlen(args
) - 1;
680 /* Simply create the channel and then start tracing */
681 strncat(args
, "-b", args_left
);
682 args_left
= MAX_ARGS_LEN
- strlen(args
) - 1;
686 /* Append to trace ? */
689 strncat(args
, " ", args_left
);
690 args_left
= MAX_ARGS_LEN
- strlen(args
) - 1;
691 strncat(args
, "-a", args_left
);
692 args_left
= MAX_ARGS_LEN
- strlen(args
) - 1;
695 /* optional arguments */
697 if(strcmp(subbuf_size
, "") != 0) {
699 strncat(args
, " ", args_left
);
700 args_left
= MAX_ARGS_LEN
- strlen(args
) - 1;
702 strncat(args
, "-z ", args_left
);
703 args_left
= MAX_ARGS_LEN
- strlen(args
) - 1;
704 strncat(args
, subbuf_size
, args_left
);
705 args_left
= MAX_ARGS_LEN
- strlen(args
) - 1;
708 /* number of subbuffers */
709 if(strcmp(subbuf_num
, "") != 0) {
711 strncat(args
, " ", args_left
);
712 args_left
= MAX_ARGS_LEN
- strlen(args
) - 1;
714 strncat(args
, "-x ", args_left
);
715 args_left
= MAX_ARGS_LEN
- strlen(args
) - 1;
716 strncat(args
, subbuf_num
, args_left
);
717 args_left
= MAX_ARGS_LEN
- strlen(args
) - 1;
721 int retval
= execute_command(args
, username
, password
, lttd_path
, fac_path
);
725 guint msg_left
= 256;
727 strcpy(msg
, "A problem occured when executing the su command : ");
728 msg_left
= 256 - strlen(msg
) - 1;
729 strncat(msg
, strerror(retval
), msg_left
);
730 GtkWidget
*dialogue
=
731 gtk_message_dialog_new(
732 GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(button
))),
733 GTK_DIALOG_MODAL
|GTK_DIALOG_DESTROY_WITH_PARENT
,
737 gtk_dialog_run(GTK_DIALOG(dialogue
));
738 gtk_widget_destroy(dialogue
);
744 void pause_clicked (GtkButton
*button
, gpointer user_data
)
746 ControlData
*tcd
= (ControlData
*)user_data
;
748 const gchar
*username
= gtk_entry_get_text(GTK_ENTRY(tcd
->username_entry
));
749 const gchar
*password
= gtk_entry_get_text(GTK_ENTRY(tcd
->password_entry
));
750 const gchar
*trace_name
=
751 gtk_entry_get_text(GTK_ENTRY(tcd
->trace_name_entry
));
752 const gchar
*lttd_path
= "";
753 const gchar
*fac_path
= "";
755 const gchar
*lttctl_path
=
756 gtk_entry_get_text(GTK_ENTRY(tcd
->lttctl_path_entry
));
758 /* Setup arguments to su */
760 gchar args
[MAX_ARGS_LEN
];
761 gint args_left
= MAX_ARGS_LEN
- 1; /* for \0 */
766 strncat(args
, "exec", args_left
);
767 args_left
= MAX_ARGS_LEN
- strlen(args
) - 1;
770 strncat(args
, " ", args_left
);
771 args_left
= MAX_ARGS_LEN
- strlen(args
) - 1;
773 if(strcmp(lttctl_path
, "") == 0)
774 strncat(args
, "lttctl", args_left
);
776 strncat(args
, lttctl_path
, args_left
);
777 args_left
= MAX_ARGS_LEN
- strlen(args
) - 1;
780 strncat(args
, " ", args_left
);
781 args_left
= MAX_ARGS_LEN
- strlen(args
) - 1;
784 strncat(args
, "-n ", args_left
);
785 args_left
= MAX_ARGS_LEN
- strlen(args
) - 1;
786 strncat(args
, trace_name
, args_left
);
787 args_left
= MAX_ARGS_LEN
- strlen(args
) - 1;
790 strncat(args
, " ", args_left
);
791 args_left
= MAX_ARGS_LEN
- strlen(args
) - 1;
793 /* Simply pause tracing */
794 strncat(args
, "-q", args_left
);
795 args_left
= MAX_ARGS_LEN
- strlen(args
) - 1;
797 int retval
= execute_command(args
, username
, password
, lttd_path
, fac_path
);
800 guint msg_left
= 256;
802 strcpy(msg
, "A problem occured when executing the su command : ");
803 msg_left
= 256 - strlen(msg
) - 1;
804 strncat(msg
, strerror(retval
), msg_left
);
805 GtkWidget
*dialogue
=
806 gtk_message_dialog_new(
807 GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(button
))),
808 GTK_DIALOG_MODAL
|GTK_DIALOG_DESTROY_WITH_PARENT
,
812 gtk_dialog_run(GTK_DIALOG(dialogue
));
813 gtk_widget_destroy(dialogue
);
818 void unpause_clicked (GtkButton
*button
, gpointer user_data
)
820 ControlData
*tcd
= (ControlData
*)user_data
;
822 const gchar
*username
= gtk_entry_get_text(GTK_ENTRY(tcd
->username_entry
));
823 const gchar
*password
= gtk_entry_get_text(GTK_ENTRY(tcd
->password_entry
));
824 const gchar
*trace_name
=
825 gtk_entry_get_text(GTK_ENTRY(tcd
->trace_name_entry
));
826 const gchar
*lttd_path
= "";
827 const gchar
*fac_path
= "";
829 const gchar
*lttctl_path
=
830 gtk_entry_get_text(GTK_ENTRY(tcd
->lttctl_path_entry
));
832 /* Setup arguments to su */
834 gchar args
[MAX_ARGS_LEN
];
835 gint args_left
= MAX_ARGS_LEN
- 1; /* for \0 */
840 strncat(args
, "exec", args_left
);
841 args_left
= MAX_ARGS_LEN
- strlen(args
) - 1;
844 strncat(args
, " ", args_left
);
845 args_left
= MAX_ARGS_LEN
- strlen(args
) - 1;
847 if(strcmp(lttctl_path
, "") == 0)
848 strncat(args
, "lttctl", args_left
);
850 strncat(args
, lttctl_path
, args_left
);
851 args_left
= MAX_ARGS_LEN
- strlen(args
) - 1;
854 strncat(args
, " ", args_left
);
855 args_left
= MAX_ARGS_LEN
- strlen(args
) - 1;
858 strncat(args
, "-n ", args_left
);
859 args_left
= MAX_ARGS_LEN
- strlen(args
) - 1;
860 strncat(args
, trace_name
, args_left
);
861 args_left
= MAX_ARGS_LEN
- strlen(args
) - 1;
864 strncat(args
, " ", args_left
);
865 args_left
= MAX_ARGS_LEN
- strlen(args
) - 1;
867 /* Simply unpause tracing */
868 strncat(args
, "-s", args_left
);
869 args_left
= MAX_ARGS_LEN
- strlen(args
) - 1;
871 int retval
= execute_command(args
, username
, password
, lttd_path
, fac_path
);
874 guint msg_left
= 256;
876 strcpy(msg
, "A problem occured when executing the su command : ");
877 msg_left
= 256 - strlen(msg
) - 1;
878 strncat(msg
, strerror(retval
), msg_left
);
879 GtkWidget
*dialogue
=
880 gtk_message_dialog_new(
881 GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(button
))),
882 GTK_DIALOG_MODAL
|GTK_DIALOG_DESTROY_WITH_PARENT
,
886 gtk_dialog_run(GTK_DIALOG(dialogue
));
887 gtk_widget_destroy(dialogue
);
892 void stop_clicked (GtkButton
*button
, gpointer user_data
)
894 ControlData
*tcd
= (ControlData
*)user_data
;
896 const gchar
*username
= gtk_entry_get_text(GTK_ENTRY(tcd
->username_entry
));
897 const gchar
*password
= gtk_entry_get_text(GTK_ENTRY(tcd
->password_entry
));
898 const gchar
*trace_name
=
899 gtk_entry_get_text(GTK_ENTRY(tcd
->trace_name_entry
));
900 const gchar
*lttd_path
= "";
901 const gchar
*fac_path
= "";
903 const gchar
*lttctl_path
=
904 gtk_entry_get_text(GTK_ENTRY(tcd
->lttctl_path_entry
));
905 const gchar
*trace_dir
= gtk_entry_get_text(GTK_ENTRY(tcd
->trace_dir_entry
));
907 /* Setup arguments to su */
909 gchar args
[MAX_ARGS_LEN
];
910 gint args_left
= MAX_ARGS_LEN
- 1; /* for \0 */
915 strncat(args
, "exec", args_left
);
916 args_left
= MAX_ARGS_LEN
- strlen(args
) - 1;
919 strncat(args
, " ", args_left
);
920 args_left
= MAX_ARGS_LEN
- strlen(args
) - 1;
922 if(strcmp(lttctl_path
, "") == 0)
923 strncat(args
, "lttctl", args_left
);
925 strncat(args
, lttctl_path
, args_left
);
926 args_left
= MAX_ARGS_LEN
- strlen(args
) - 1;
929 strncat(args
, " ", args_left
);
930 args_left
= MAX_ARGS_LEN
- strlen(args
) - 1;
933 strncat(args
, "-n ", args_left
);
934 args_left
= MAX_ARGS_LEN
- strlen(args
) - 1;
935 strncat(args
, trace_name
, args_left
);
936 args_left
= MAX_ARGS_LEN
- strlen(args
) - 1;
939 strncat(args
, " ", args_left
);
940 args_left
= MAX_ARGS_LEN
- strlen(args
) - 1;
942 /* Simply stop tracing and destroy channel */
943 strncat(args
, "-R", args_left
);
944 args_left
= MAX_ARGS_LEN
- strlen(args
) - 1;
946 int retval
= execute_command(args
, username
, password
, lttd_path
, fac_path
);
949 guint msg_left
= 256;
951 strcpy(msg
, "A problem occured when executing the su command : ");
952 msg_left
= 256 - strlen(msg
) - 1;
953 strncat(msg
, strerror(retval
), msg_left
);
954 GtkWidget
*dialogue
=
955 gtk_message_dialog_new(
956 GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(button
))),
957 GTK_DIALOG_MODAL
|GTK_DIALOG_DESTROY_WITH_PARENT
,
961 gtk_dialog_run(GTK_DIALOG(dialogue
));
962 gtk_widget_destroy(dialogue
);
967 /* Ask to the user if he wants to open the trace in a new window */
972 dialogue
= gtk_dialog_new_with_buttons("Open trace ?",
973 GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(button
))),
974 GTK_DIALOG_MODAL
| GTK_DIALOG_DESTROY_WITH_PARENT
,
975 GTK_STOCK_YES
,GTK_RESPONSE_ACCEPT
,
976 GTK_STOCK_NO
,GTK_RESPONSE_REJECT
,
978 label
= gtk_label_new("Do you want to open the trace in LTTV ?");
979 gtk_widget_show(label
);
981 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialogue
)->vbox
),
984 id
= gtk_dialog_run(GTK_DIALOG(dialogue
));
987 case GTK_RESPONSE_ACCEPT
:
989 create_main_window_with_trace(trace_dir
);
992 case GTK_RESPONSE_REJECT
:
996 gtk_widget_destroy(dialogue
);
1002 * @fn GtkWidget* h_guicontrol(Tab*)
1004 * Control Module's constructor hook
1006 * This constructor is given as a parameter to the menuitem and toolbar button
1007 * registration. It creates the list.
1008 * @param tab A pointer to the parent window.
1009 * @return The widget created.
1012 h_guicontrol(Tab
*tab
)
1014 ControlData
* f
= gui_control(tab
) ;
1020 * @fn static void init()
1022 * This function initializes the Filter Viewer functionnality through the
1025 static void init() {
1027 lttvwindow_register_constructor("guicontrol",
1029 "Insert Tracing Control Module",
1030 hTraceControlInsert_xpm
,
1031 "Insert Tracing Control Module",
1036 * @fn void control_destroy_walk(gpointer,gpointer)
1038 * Initiate the destruction of the current gui module
1039 * on the GTK Interface
1042 control_destroy_walk(gpointer data
, gpointer user_data
)
1044 ControlData
*tcd
= (ControlData
*)data
;
1046 g_debug("traceontrol.c : control_destroy_walk, %p", tcd
);
1048 /* May already have been done by GTK window closing */
1049 if(GTK_IS_WIDGET(guicontrol_get_widget(tcd
)))
1050 gtk_widget_destroy(guicontrol_get_widget(tcd
));
1054 * @fn static void destroy()
1055 * @brief plugin's destroy function
1057 * This function releases the memory reserved by the module and unregisters
1058 * everything that has been registered in the gtkTraceSet API.
1060 static void destroy() {
1062 g_slist_foreach(g_control_list
, control_destroy_walk
, NULL
);
1064 lttvwindow_unregister_constructor(h_guicontrol
);
1069 LTTV_MODULE("guitracecontrol", "Trace Control Window", \
1070 "Graphical module that let user control kernel tracing", \
1071 init
, destroy
, "lttvwindow")