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,
24 #include <glib/gprintf.h>
28 #include <gdk/gdkkeysyms.h>
30 #include <lttv/lttv.h>
31 #include <lttv/module.h>
32 #include <lttv/hook.h>
34 #include <lttvwindow/lttvwindow.h>
35 #include <lttvwindow/lttvwindowtraces.h>
36 #include <lttvwindow/callbacks.h>
37 #include <lttvwindow/lttv_plugin_tab.h>
39 #include "hTraceControlInsert.xpm"
40 #include "TraceControlStart.xpm"
41 #include "TraceControlPause.xpm"
42 #include "TraceControlStop.xpm"
44 #include <sys/types.h>
55 #define MAX_ARGS_LEN PATH_MAX * 10
57 GSList *g_control_list = NULL ;
59 /*! \file lttv/modules/gui/tracecontrol/tracecontrol.c
60 * \brief Graphic trace start/stop control interface.
62 * This plugin interacts with lttctl to start/stop tracing. It needs to take the
63 * root password to be able to interact with lttctl.
67 typedef struct _ControlData ControlData;
72 GtkWidget *guicontrol_get_widget(ControlData *tcd);
73 ControlData *gui_control(LttvPluginTab *ptab);
74 void gui_control_destructor(ControlData *tcd);
75 GtkWidget* h_guicontrol(LttvPlugin *plugin);
76 void control_destroy_walk(gpointer data, gpointer user_data);
82 static void start_clicked (GtkButton *button, gpointer user_data);
83 static void pause_clicked (GtkButton *button, gpointer user_data);
84 static void unpause_clicked (GtkButton *button, gpointer user_data);
85 static void stop_clicked (GtkButton *button, gpointer user_data);
89 * @struct _ControlData
91 * @brief Main structure of gui control
94 Tab *tab; /**< current tab of module */
96 GtkWidget *window; /**< window */
98 GtkWidget *main_box; /**< main container */
99 GtkWidget *start_button;
100 GtkWidget *pause_button;
101 GtkWidget *unpause_button;
102 GtkWidget *stop_button;
103 GtkWidget *username_label;
104 GtkWidget *username_entry;
105 GtkWidget *password_label;
106 GtkWidget *password_entry;
107 GtkWidget *channel_dir_label;
108 GtkWidget *channel_dir_entry;
109 GtkWidget *trace_dir_label;
110 GtkWidget *trace_dir_entry;
111 GtkWidget *trace_name_label;
112 GtkWidget *trace_name_entry;
113 GtkWidget *trace_mode_label;
114 GtkWidget *trace_mode_combo;
115 GtkWidget *start_daemon_label;
116 GtkWidget *start_daemon_check;
117 GtkWidget *append_label;
118 GtkWidget *append_check;
119 GtkWidget *optional_label;
120 GtkWidget *subbuf_size_label;
121 GtkWidget *subbuf_size_entry;
122 GtkWidget *subbuf_num_label;
123 GtkWidget *subbuf_num_entry;
124 GtkWidget *lttd_threads_label;
125 GtkWidget *lttd_threads_entry;
126 GtkWidget *lttctl_path_label;
127 GtkWidget *lttctl_path_entry;
128 GtkWidget *lttd_path_label;
129 GtkWidget *lttd_path_entry;
130 GtkWidget *fac_path_label;
131 GtkWidget *fac_path_entry;
135 * @fn GtkWidget* guicontrol_get_widget(ControlData*)
137 * This function returns the current main widget
138 * used by this module
139 * @param tcd the module struct
140 * @return The main widget
143 guicontrol_get_widget(ControlData *tcd)
149 * @fn ControlData* gui_control(Tab*)
151 * Constructor is used to create ControlData data structure.
152 * @param tab The tab structure used by the widget
153 * @return The Filter viewer data created.
156 gui_control(LttvPluginTab *ptab)
158 Tab *tab = ptab->tab;
159 g_debug("filter::gui_control()");
162 GtkCellRenderer *renderer;
163 GtkTreeViewColumn *column;
165 ControlData* tcd = g_new(ControlData,1);
169 tcd->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
170 gtk_window_set_title(GTK_WINDOW(tcd->window), "LTTng Trace Control");
172 * Initiating GtkTable layout
173 * starts with 2 rows and 5 columns and
174 * expands when expressions added
176 tcd->main_box = gtk_table_new(14,7,FALSE);
177 gtk_table_set_row_spacings(GTK_TABLE(tcd->main_box),5);
178 gtk_table_set_col_spacings(GTK_TABLE(tcd->main_box),5);
180 gtk_container_add(GTK_CONTAINER(tcd->window), GTK_WIDGET(tcd->main_box));
182 GList *focus_chain = NULL;
185 * start/pause/stop buttons
189 pixbuf = gdk_pixbuf_new_from_xpm_data((const char **)TraceControlStart_xpm);
190 image = gtk_image_new_from_pixbuf(pixbuf);
191 tcd->start_button = gtk_button_new_with_label("start");
192 //2.6 gtk_button_set_image(GTK_BUTTON(tcd->start_button), image);
193 g_object_set(G_OBJECT(tcd->start_button), "image", image, NULL);
194 gtk_button_set_alignment(GTK_BUTTON(tcd->start_button), 0.0, 0.0);
195 gtk_widget_show (tcd->start_button);
196 gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->start_button,6,7,0,1,GTK_FILL,GTK_FILL,2,2);
198 pixbuf = gdk_pixbuf_new_from_xpm_data((const char **)TraceControlPause_xpm);
199 image = gtk_image_new_from_pixbuf(pixbuf);
200 tcd->pause_button = gtk_button_new_with_label("pause");
201 //2.6 gtk_button_set_image(GTK_BUTTON(tcd->pause_button), image);
202 g_object_set(G_OBJECT(tcd->pause_button), "image", image, NULL);
203 gtk_button_set_alignment(GTK_BUTTON(tcd->pause_button), 0.0, 0.0);
204 gtk_widget_show (tcd->pause_button);
205 gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->pause_button,6,7,1,2,GTK_FILL,GTK_FILL,2,2);
207 pixbuf = gdk_pixbuf_new_from_xpm_data((const char **)TraceControlPause_xpm);
208 image = gtk_image_new_from_pixbuf(pixbuf);
209 tcd->unpause_button = gtk_button_new_with_label("unpause");
210 //2.6 gtk_button_set_image(GTK_BUTTON(tcd->unpause_button), image);
211 g_object_set(G_OBJECT(tcd->unpause_button), "image", image, NULL);
212 gtk_button_set_alignment(GTK_BUTTON(tcd->unpause_button), 0.0, 0.0);
213 gtk_widget_show (tcd->unpause_button);
214 gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->unpause_button,6,7,2,3,GTK_FILL,GTK_FILL,2,2);
216 pixbuf = gdk_pixbuf_new_from_xpm_data((const char **)TraceControlStop_xpm);
217 image = gtk_image_new_from_pixbuf(pixbuf);
218 tcd->stop_button = gtk_button_new_with_label("stop");
219 //2.6 gtk_button_set_image(GTK_BUTTON(tcd->stop_button), image);
220 g_object_set(G_OBJECT(tcd->stop_button), "image", image, NULL);
221 gtk_button_set_alignment(GTK_BUTTON(tcd->stop_button), 0.0, 0.0);
222 gtk_widget_show (tcd->stop_button);
223 gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->stop_button,6,7,3,4,GTK_FILL,GTK_FILL,2,2);
226 * First half of the filter window
227 * - textual entry of filter expression
228 * - processing button
230 tcd->username_label = gtk_label_new("Username:");
231 gtk_widget_show (tcd->username_label);
232 tcd->username_entry = gtk_entry_new();
233 gtk_entry_set_text(GTK_ENTRY(tcd->username_entry),"root");
234 gtk_widget_show (tcd->username_entry);
235 gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->username_label,0,2,0,1,GTK_FILL,GTK_FILL,2,2);
236 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);
240 tcd->password_label = gtk_label_new("Password:");
241 gtk_widget_show (tcd->password_label);
242 tcd->password_entry = gtk_entry_new();
243 gtk_entry_set_visibility(GTK_ENTRY(tcd->password_entry), FALSE);
244 gtk_widget_show (tcd->password_entry);
245 gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->password_label,0,2,1,2,GTK_FILL,GTK_FILL,2,2);
246 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);
249 tcd->channel_dir_label = gtk_label_new("Channel directory:");
250 gtk_widget_show (tcd->channel_dir_label);
251 tcd->channel_dir_entry = gtk_entry_new();
252 gtk_entry_set_text(GTK_ENTRY(tcd->channel_dir_entry),"/mnt/debugfs/ltt");
253 gtk_widget_show (tcd->channel_dir_entry);
254 gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->channel_dir_label,0,2,2,3,GTK_FILL,GTK_FILL,2,2);
255 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);
257 tcd->trace_dir_label = gtk_label_new("Trace directory:");
258 gtk_widget_show (tcd->trace_dir_label);
259 tcd->trace_dir_entry = gtk_entry_new();
260 gtk_entry_set_text(GTK_ENTRY(tcd->trace_dir_entry),"/tmp/trace1");
261 gtk_widget_show (tcd->trace_dir_entry);
262 gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->trace_dir_label,0,2,3,4,GTK_FILL,GTK_FILL,2,2);
263 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);
265 tcd->trace_name_label = gtk_label_new("Trace name:");
266 gtk_widget_show (tcd->trace_name_label);
267 tcd->trace_name_entry = gtk_entry_new();
268 gtk_entry_set_text(GTK_ENTRY(tcd->trace_name_entry),"trace");
269 gtk_widget_show (tcd->trace_name_entry);
270 gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->trace_name_label,0,2,4,5,GTK_FILL,GTK_FILL,2,2);
271 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);
273 tcd->trace_mode_label = gtk_label_new("Trace mode ");
274 gtk_widget_show (tcd->trace_mode_label);
275 tcd->trace_mode_combo = gtk_combo_box_new_text();
276 gtk_combo_box_append_text(GTK_COMBO_BOX(tcd->trace_mode_combo),
278 gtk_combo_box_append_text(GTK_COMBO_BOX(tcd->trace_mode_combo),
280 gtk_combo_box_set_active(GTK_COMBO_BOX(tcd->trace_mode_combo), 0);
281 gtk_widget_show (tcd->trace_mode_combo);
282 gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->trace_mode_label,0,2,5,6,GTK_FILL,GTK_FILL,2,2);
283 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);
285 tcd->start_daemon_label = gtk_label_new("Start daemon ");
286 gtk_widget_show (tcd->start_daemon_label);
287 tcd->start_daemon_check = gtk_check_button_new();
288 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(tcd->start_daemon_check), TRUE);
289 gtk_widget_show (tcd->start_daemon_check);
290 gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->start_daemon_label,0,2,6,7,GTK_FILL,GTK_FILL,2,2);
291 gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->start_daemon_check,2,6,6,7,GTK_FILL,GTK_FILL,0,0);
293 tcd->append_label = gtk_label_new("Append to trace ");
294 gtk_widget_show (tcd->append_label);
295 tcd->append_check = gtk_check_button_new();
296 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(tcd->append_check), FALSE);
297 gtk_widget_show (tcd->append_check);
298 gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->append_label,0,2,7,8,GTK_FILL,GTK_FILL,2,2);
299 gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->append_check,2,6,7,8,GTK_FILL,GTK_FILL,0,0);
302 tcd->optional_label = gtk_label_new("Optional fields ");
303 gtk_widget_show (tcd->optional_label);
304 gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->optional_label,0,6,8,9,GTK_FILL,GTK_FILL,2,2);
306 tcd->subbuf_size_label = gtk_label_new("Subbuffer size:");
307 gtk_widget_show (tcd->subbuf_size_label);
308 tcd->subbuf_size_entry = gtk_entry_new();
309 gtk_widget_show (tcd->subbuf_size_entry);
310 gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->subbuf_size_label,0,2,9,10,GTK_FILL,GTK_FILL,2,2);
311 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);
313 tcd->subbuf_num_label = gtk_label_new("Number of subbuffers:");
314 gtk_widget_show (tcd->subbuf_num_label);
315 tcd->subbuf_num_entry = gtk_entry_new();
316 gtk_widget_show (tcd->subbuf_num_entry);
317 gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->subbuf_num_label,0,2,10,11,GTK_FILL,GTK_FILL,2,2);
318 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);
320 tcd->lttd_threads_label = gtk_label_new("Number of lttd threads:");
321 gtk_widget_show (tcd->lttd_threads_label);
322 tcd->lttd_threads_entry = gtk_entry_new();
323 gtk_entry_set_text(GTK_ENTRY(tcd->lttd_threads_entry), "1");
324 gtk_widget_show (tcd->lttd_threads_entry);
325 gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->lttd_threads_label,0,2,11,12,GTK_FILL,GTK_FILL,2,2);
326 gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->lttd_threads_entry,2,6,11,12,GTK_FILL|GTK_EXPAND|GTK_SHRINK,GTK_FILL,0,0);
328 tcd->lttctl_path_label = gtk_label_new("path to lttctl:");
329 gtk_widget_show (tcd->lttctl_path_label);
330 tcd->lttctl_path_entry = gtk_entry_new();
331 gtk_entry_set_text(GTK_ENTRY(tcd->lttctl_path_entry),PACKAGE_BIN_DIR "/lttctl");
332 gtk_widget_show (tcd->lttctl_path_entry);
333 gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->lttctl_path_label,0,2,12,13,GTK_FILL,GTK_FILL,2,2);
334 gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->lttctl_path_entry,2,6,12,13,GTK_FILL|GTK_EXPAND|GTK_SHRINK,GTK_FILL,0,0);
337 tcd->lttd_path_label = gtk_label_new("path to lttd:");
338 gtk_widget_show (tcd->lttd_path_label);
339 tcd->lttd_path_entry = gtk_entry_new();
340 gtk_entry_set_text(GTK_ENTRY(tcd->lttd_path_entry),PACKAGE_BIN_DIR "/lttd");
341 gtk_widget_show (tcd->lttd_path_entry);
342 gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->lttd_path_label,0,2,13,14,GTK_FILL,GTK_FILL,2,2);
343 gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->lttd_path_entry,2,6,13,14,GTK_FILL|GTK_EXPAND|GTK_SHRINK,GTK_FILL,0,0);
346 tcd->fac_path_label = gtk_label_new("path to facilities:");
347 gtk_widget_show (tcd->fac_path_label);
348 tcd->fac_path_entry = gtk_entry_new();
349 gtk_entry_set_text(GTK_ENTRY(tcd->fac_path_entry),PACKAGE_DATA_DIR "/" "ltt-control" "/facilities");
350 gtk_widget_set_size_request(tcd->fac_path_entry, 250, -1);
351 gtk_widget_show (tcd->fac_path_entry);
352 gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->fac_path_label,0,2,14,15,GTK_FILL,GTK_FILL,2,2);
353 gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->fac_path_entry,2,6,14,15,GTK_FILL|GTK_EXPAND|GTK_SHRINK,GTK_FILL,0,0);
355 focus_chain = g_list_append (focus_chain, tcd->username_entry);
356 focus_chain = g_list_append (focus_chain, tcd->password_entry);
357 focus_chain = g_list_append (focus_chain, tcd->start_button);
358 focus_chain = g_list_append (focus_chain, tcd->pause_button);
359 focus_chain = g_list_append (focus_chain, tcd->unpause_button);
360 focus_chain = g_list_append (focus_chain, tcd->stop_button);
361 focus_chain = g_list_append (focus_chain, tcd->channel_dir_entry);
362 focus_chain = g_list_append (focus_chain, tcd->trace_dir_entry);
363 focus_chain = g_list_append (focus_chain, tcd->trace_name_entry);
364 focus_chain = g_list_append (focus_chain, tcd->trace_mode_combo);
365 focus_chain = g_list_append (focus_chain, tcd->start_daemon_check);
366 focus_chain = g_list_append (focus_chain, tcd->append_check);
367 focus_chain = g_list_append (focus_chain, tcd->subbuf_size_entry);
368 focus_chain = g_list_append (focus_chain, tcd->subbuf_num_entry);
369 focus_chain = g_list_append (focus_chain, tcd->lttd_threads_entry);
370 focus_chain = g_list_append (focus_chain, tcd->lttctl_path_entry);
371 focus_chain = g_list_append (focus_chain, tcd->lttd_path_entry);
372 focus_chain = g_list_append (focus_chain, tcd->fac_path_entry);
374 gtk_container_set_focus_chain(GTK_CONTAINER(tcd->main_box), focus_chain);
376 g_list_free(focus_chain);
378 g_signal_connect(G_OBJECT(tcd->start_button), "clicked",
379 (GCallback)start_clicked, tcd);
380 g_signal_connect(G_OBJECT(tcd->pause_button), "clicked",
381 (GCallback)pause_clicked, tcd);
382 g_signal_connect(G_OBJECT(tcd->unpause_button), "clicked",
383 (GCallback)unpause_clicked, tcd);
384 g_signal_connect(G_OBJECT(tcd->stop_button), "clicked",
385 (GCallback)stop_clicked, tcd);
388 * show main container
390 gtk_widget_show(tcd->main_box);
391 gtk_widget_show(tcd->window);
394 g_object_set_data_full(
395 G_OBJECT(guicontrol_get_widget(tcd)),
396 "control_viewer_data",
398 (GDestroyNotify)gui_control_destructor);
400 g_control_list = g_slist_append(
409 * @fn void gui_control_destructor(ControlData*)
411 * Destructor for the filter gui module
412 * @param tcd The module structure
415 gui_control_destructor(ControlData *tcd)
419 /* May already been done by GTK window closing */
420 if(GTK_IS_WIDGET(guicontrol_get_widget(tcd))){
421 g_info("widget still exists");
424 // lttvwindow_unregister_traceset_notify(tcd->tab,
425 // filter_traceset_changed,
426 // filter_viewer_data);
428 lttvwindowtraces_background_notify_remove(tcd);
430 g_control_list = g_slist_remove(g_control_list, tcd);
435 static int execute_command(const gchar *command, const gchar *username,
436 const gchar *password, const gchar *lttd_path, const gchar *fac_path)
440 pid = forkpty(&fdpty, NULL, NULL, NULL);
448 /* discuss with su */
449 struct timeval timeout;
453 struct pollfd pollfd;
456 enum read_state { GET_LINE, GET_SEMI, GET_SPACE } read_state = GET_LINE;
458 retval = fcntl(fdpty, F_SETFL, O_WRONLY);
460 perror("Error in fcntl");
464 /* Read the output from the child terminal before the prompt. If no data in
465 * 200 ms, we stop reading to give the password */
466 g_info("Reading from child console...");
469 pollfd.events = POLLIN|POLLPRI|POLLERR|POLLHUP|POLLNVAL;
471 num_rdy = poll(&pollfd, 1, -1);
473 perror("Poll error");
477 /* Timeout : Stop waiting for chars */
478 if(num_rdy == 0) goto wait_child;
480 switch(pollfd.revents) {
482 g_warning("Error returned in polling fd\n");
486 g_info("Polling FD : hung up.");
490 g_warning("Polling fd tells it is not open");
495 count = read (fdpty, buf, 256);
500 for(i=0; i<count; i++) {
504 read_state = GET_SEMI;
505 g_debug("Tracecontrol input line skip\n");
510 g_debug("Tracecontrol input : marker found\n");
511 read_state = GET_SPACE;
516 g_debug("Tracecontrol input space marker found\n");
522 } else if(count == -1) {
523 perror("Error in read");
529 g_warning("Child hung up too fast");
536 pollfd.events = POLLOUT|POLLERR|POLLHUP|POLLNVAL;
538 num_rdy = poll(&pollfd, 1, -1);
540 perror("Poll error");
544 /* Write the password */
545 g_info("Got su prompt, now writing password...");
548 ret = write(fdpty, password, strlen(password));
549 if(ret < 0) perror("Error in write");
550 ret = write(fdpty, "\n", 1);
551 if(ret < 0) perror("Error in write");
553 /* Take the output from the terminal and show it on the real console */
554 g_info("Getting data from child terminal...");
558 pollfd.events = POLLIN|POLLPRI|POLLERR|POLLHUP|POLLNVAL;
560 num_rdy = poll(&pollfd, 1, -1);
562 perror("Poll error");
565 if(num_rdy == 0) break;
567 if(pollfd.revents & (POLLERR|POLLNVAL)) {
568 g_warning("Error returned in polling fd\n");
572 if(pollfd.revents & (POLLIN|POLLPRI) ) {
573 count = read (fdpty, buf, 256);
577 } else if(count == -1) {
578 perror("Error in read");
583 if(pollfd.revents & POLLHUP) {
584 g_info("Polling FD : hung up.");
588 if(num_hup > 0) goto wait_child;
591 g_info("Waiting for child exit...");
593 ret = waitpid(pid, &status, 0);
596 g_warning("An error occured in wait : %s",
599 if(WIFEXITED(status))
600 if(WEXITSTATUS(status) != 0) {
601 retval = WEXITSTATUS(status);
602 g_warning("An error occured in the su command : %s",
607 g_info("Child exited.");
609 } else if(pid == 0) {
610 /* Setup environment variables */
611 if(strcmp(lttd_path, "") != 0)
612 setenv("LTT_DAEMON", lttd_path, 1);
613 if(strcmp(fac_path, "") != 0)
614 setenv("LTT_FACILITIES", fac_path, 1);
616 /* One comment line (must be only one) */
617 g_printf("Executing (as %s) : %s\n", username, command);
619 execlp("su", "su", "-p", "-c", command, username, NULL);
620 exit(-1); /* not supposed to happen! */
622 //gint ret = execvp();
626 g_warning("Error happened when forking for su");
635 void start_clicked (GtkButton *button, gpointer user_data)
637 ControlData *tcd = (ControlData*)user_data;
639 const gchar *username = gtk_entry_get_text(GTK_ENTRY(tcd->username_entry));
640 const gchar *password = gtk_entry_get_text(GTK_ENTRY(tcd->password_entry));
641 const gchar *channel_dir =
642 gtk_entry_get_text(GTK_ENTRY(tcd->channel_dir_entry));
643 const gchar *trace_dir = gtk_entry_get_text(GTK_ENTRY(tcd->trace_dir_entry));
644 const gchar *trace_name =
645 gtk_entry_get_text(GTK_ENTRY(tcd->trace_name_entry));
647 const gchar *trace_mode_sel;
650 gtk_combo_box_get_active_iter(GTK_COMBO_BOX(tcd->trace_mode_combo), &iter);
652 gtk_combo_box_get_model(GTK_COMBO_BOX(tcd->trace_mode_combo)),
653 &iter, 0, &trace_mode_sel, -1);
654 //const gchar *trace_mode_sel =
655 //2.6+ gtk_combo_box_get_active_text(GTK_COMBO_BOX(tcd->trace_mode_combo));
656 const gchar *trace_mode;
657 if(strcmp(trace_mode_sel, "normal") == 0)
658 trace_mode = "normal";
660 trace_mode = "flight";
662 gboolean start_daemon =
663 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(tcd->start_daemon_check));
666 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(tcd->append_check));
668 const gchar *subbuf_size =
669 gtk_entry_get_text(GTK_ENTRY(tcd->subbuf_size_entry));
670 const gchar *subbuf_num =
671 gtk_entry_get_text(GTK_ENTRY(tcd->subbuf_num_entry));
672 const gchar *threads_num =
673 gtk_entry_get_text(GTK_ENTRY(tcd->lttd_threads_entry));
674 const gchar *lttctl_path =
675 gtk_entry_get_text(GTK_ENTRY(tcd->lttctl_path_entry));
676 const gchar *lttd_path = gtk_entry_get_text(GTK_ENTRY(tcd->lttd_path_entry));
677 const gchar *fac_path = gtk_entry_get_text(GTK_ENTRY(tcd->fac_path_entry));
680 /* Setup arguments to su */
682 gchar args[MAX_ARGS_LEN];
683 gint args_left = MAX_ARGS_LEN - 1; /* for \0 */
688 strncat(args, "exec", args_left);
689 args_left = MAX_ARGS_LEN - strlen(args) - 1;
692 strncat(args, " ", args_left);
693 args_left = MAX_ARGS_LEN - strlen(args) - 1;
695 if(strcmp(lttctl_path, "") == 0)
696 strncat(args, "lttctl", args_left);
698 strncat(args, lttctl_path, args_left);
699 args_left = MAX_ARGS_LEN - strlen(args) - 1;
702 strncat(args, " ", args_left);
703 args_left = MAX_ARGS_LEN - strlen(args) - 1;
706 strncat(args, "-l ", args_left);
707 args_left = MAX_ARGS_LEN - strlen(args) - 1;
708 strncat(args, channel_dir, args_left);
709 args_left = MAX_ARGS_LEN - strlen(args) - 1;
712 strncat(args, " ", args_left);
713 args_left = MAX_ARGS_LEN - strlen(args) - 1;
716 strncat(args, "-t ", args_left);
717 args_left = MAX_ARGS_LEN - strlen(args) - 1;
718 strncat(args, trace_dir, args_left);
719 args_left = MAX_ARGS_LEN - strlen(args) - 1;
722 strncat(args, " ", args_left);
723 args_left = MAX_ARGS_LEN - strlen(args) - 1;
726 strncat(args, "-n ", args_left);
727 args_left = MAX_ARGS_LEN - strlen(args) - 1;
728 strncat(args, trace_name, args_left);
729 args_left = MAX_ARGS_LEN - strlen(args) - 1;
732 strncat(args, " ", args_left);
733 args_left = MAX_ARGS_LEN - strlen(args) - 1;
736 strncat(args, "-m ", args_left);
737 args_left = MAX_ARGS_LEN - strlen(args) - 1;
738 strncat(args, trace_mode, args_left);
739 args_left = MAX_ARGS_LEN - strlen(args) - 1;
742 strncat(args, " ", args_left);
743 args_left = MAX_ARGS_LEN - strlen(args) - 1;
747 strncat(args, "-d", args_left);
748 args_left = MAX_ARGS_LEN - strlen(args) - 1;
750 /* Simply create the channel and then start tracing */
751 strncat(args, "-b", args_left);
752 args_left = MAX_ARGS_LEN - strlen(args) - 1;
756 /* Append to trace ? */
759 strncat(args, " ", args_left);
760 args_left = MAX_ARGS_LEN - strlen(args) - 1;
761 strncat(args, "-a", args_left);
762 args_left = MAX_ARGS_LEN - strlen(args) - 1;
765 /* optional arguments */
767 if(strcmp(subbuf_size, "") != 0) {
769 strncat(args, " ", args_left);
770 args_left = MAX_ARGS_LEN - strlen(args) - 1;
772 strncat(args, "-z ", args_left);
773 args_left = MAX_ARGS_LEN - strlen(args) - 1;
774 strncat(args, subbuf_size, args_left);
775 args_left = MAX_ARGS_LEN - strlen(args) - 1;
778 /* number of subbuffers */
779 if(strcmp(subbuf_num, "") != 0) {
781 strncat(args, " ", args_left);
782 args_left = MAX_ARGS_LEN - strlen(args) - 1;
784 strncat(args, "-x ", args_left);
785 args_left = MAX_ARGS_LEN - strlen(args) - 1;
786 strncat(args, subbuf_num, args_left);
787 args_left = MAX_ARGS_LEN - strlen(args) - 1;
790 /* number of lttd threads */
791 if(strcmp(threads_num, "") != 0) {
793 strncat(args, " ", args_left);
794 args_left = MAX_ARGS_LEN - strlen(args) - 1;
796 strncat(args, "-N ", args_left);
797 args_left = MAX_ARGS_LEN - strlen(args) - 1;
798 strncat(args, threads_num, args_left);
799 args_left = MAX_ARGS_LEN - strlen(args) - 1;
803 int retval = execute_command(args, username, password, lttd_path, fac_path);
807 guint msg_left = 256;
809 strcpy(msg, "A problem occured when executing the su command : ");
810 msg_left = 256 - strlen(msg) - 1;
811 strncat(msg, strerror(retval), msg_left);
812 GtkWidget *dialogue =
813 gtk_message_dialog_new(
814 GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(button))),
815 GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
819 gtk_dialog_run(GTK_DIALOG(dialogue));
820 gtk_widget_destroy(dialogue);
826 void pause_clicked (GtkButton *button, gpointer user_data)
828 ControlData *tcd = (ControlData*)user_data;
830 const gchar *username = gtk_entry_get_text(GTK_ENTRY(tcd->username_entry));
831 const gchar *password = gtk_entry_get_text(GTK_ENTRY(tcd->password_entry));
832 const gchar *trace_name =
833 gtk_entry_get_text(GTK_ENTRY(tcd->trace_name_entry));
834 const gchar *lttd_path = "";
835 const gchar *fac_path = "";
837 const gchar *lttctl_path =
838 gtk_entry_get_text(GTK_ENTRY(tcd->lttctl_path_entry));
840 /* Setup arguments to su */
842 gchar args[MAX_ARGS_LEN];
843 gint args_left = MAX_ARGS_LEN - 1; /* for \0 */
848 strncat(args, "exec", args_left);
849 args_left = MAX_ARGS_LEN - strlen(args) - 1;
852 strncat(args, " ", args_left);
853 args_left = MAX_ARGS_LEN - strlen(args) - 1;
855 if(strcmp(lttctl_path, "") == 0)
856 strncat(args, "lttctl", args_left);
858 strncat(args, lttctl_path, args_left);
859 args_left = MAX_ARGS_LEN - strlen(args) - 1;
862 strncat(args, " ", args_left);
863 args_left = MAX_ARGS_LEN - strlen(args) - 1;
866 strncat(args, "-n ", args_left);
867 args_left = MAX_ARGS_LEN - strlen(args) - 1;
868 strncat(args, trace_name, args_left);
869 args_left = MAX_ARGS_LEN - strlen(args) - 1;
872 strncat(args, " ", args_left);
873 args_left = MAX_ARGS_LEN - strlen(args) - 1;
875 /* Simply pause tracing */
876 strncat(args, "-q", args_left);
877 args_left = MAX_ARGS_LEN - strlen(args) - 1;
879 int retval = execute_command(args, username, password, lttd_path, fac_path);
882 guint msg_left = 256;
884 strcpy(msg, "A problem occured when executing the su command : ");
885 msg_left = 256 - strlen(msg) - 1;
886 strncat(msg, strerror(retval), msg_left);
887 GtkWidget *dialogue =
888 gtk_message_dialog_new(
889 GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(button))),
890 GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
894 gtk_dialog_run(GTK_DIALOG(dialogue));
895 gtk_widget_destroy(dialogue);
900 void unpause_clicked (GtkButton *button, gpointer user_data)
902 ControlData *tcd = (ControlData*)user_data;
904 const gchar *username = gtk_entry_get_text(GTK_ENTRY(tcd->username_entry));
905 const gchar *password = gtk_entry_get_text(GTK_ENTRY(tcd->password_entry));
906 const gchar *trace_name =
907 gtk_entry_get_text(GTK_ENTRY(tcd->trace_name_entry));
908 const gchar *lttd_path = "";
909 const gchar *fac_path = "";
911 const gchar *lttctl_path =
912 gtk_entry_get_text(GTK_ENTRY(tcd->lttctl_path_entry));
914 /* Setup arguments to su */
916 gchar args[MAX_ARGS_LEN];
917 gint args_left = MAX_ARGS_LEN - 1; /* for \0 */
922 strncat(args, "exec", args_left);
923 args_left = MAX_ARGS_LEN - strlen(args) - 1;
926 strncat(args, " ", args_left);
927 args_left = MAX_ARGS_LEN - strlen(args) - 1;
929 if(strcmp(lttctl_path, "") == 0)
930 strncat(args, "lttctl", args_left);
932 strncat(args, lttctl_path, args_left);
933 args_left = MAX_ARGS_LEN - strlen(args) - 1;
936 strncat(args, " ", args_left);
937 args_left = MAX_ARGS_LEN - strlen(args) - 1;
940 strncat(args, "-n ", args_left);
941 args_left = MAX_ARGS_LEN - strlen(args) - 1;
942 strncat(args, trace_name, args_left);
943 args_left = MAX_ARGS_LEN - strlen(args) - 1;
946 strncat(args, " ", args_left);
947 args_left = MAX_ARGS_LEN - strlen(args) - 1;
949 /* Simply unpause tracing */
950 strncat(args, "-s", args_left);
951 args_left = MAX_ARGS_LEN - strlen(args) - 1;
953 int retval = execute_command(args, username, password, lttd_path, fac_path);
956 guint msg_left = 256;
958 strcpy(msg, "A problem occured when executing the su command : ");
959 msg_left = 256 - strlen(msg) - 1;
960 strncat(msg, strerror(retval), msg_left);
961 GtkWidget *dialogue =
962 gtk_message_dialog_new(
963 GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(button))),
964 GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
968 gtk_dialog_run(GTK_DIALOG(dialogue));
969 gtk_widget_destroy(dialogue);
974 void stop_clicked (GtkButton *button, gpointer user_data)
976 ControlData *tcd = (ControlData*)user_data;
978 const gchar *username = gtk_entry_get_text(GTK_ENTRY(tcd->username_entry));
979 const gchar *password = gtk_entry_get_text(GTK_ENTRY(tcd->password_entry));
980 const gchar *trace_name =
981 gtk_entry_get_text(GTK_ENTRY(tcd->trace_name_entry));
982 const gchar *lttd_path = "";
983 const gchar *fac_path = "";
985 const gchar *lttctl_path =
986 gtk_entry_get_text(GTK_ENTRY(tcd->lttctl_path_entry));
987 gchar *trace_dir = gtk_entry_get_text(GTK_ENTRY(tcd->trace_dir_entry));
988 GSList * trace_list = NULL;
990 trace_list = g_slist_append(trace_list, trace_dir);
992 /* Setup arguments to su */
994 gchar args[MAX_ARGS_LEN];
995 gint args_left = MAX_ARGS_LEN - 1; /* for \0 */
1000 strncat(args, "exec", args_left);
1001 args_left = MAX_ARGS_LEN - strlen(args) - 1;
1004 strncat(args, " ", args_left);
1005 args_left = MAX_ARGS_LEN - strlen(args) - 1;
1007 if(strcmp(lttctl_path, "") == 0)
1008 strncat(args, "lttctl", args_left);
1010 strncat(args, lttctl_path, args_left);
1011 args_left = MAX_ARGS_LEN - strlen(args) - 1;
1014 strncat(args, " ", args_left);
1015 args_left = MAX_ARGS_LEN - strlen(args) - 1;
1018 strncat(args, "-n ", args_left);
1019 args_left = MAX_ARGS_LEN - strlen(args) - 1;
1020 strncat(args, trace_name, args_left);
1021 args_left = MAX_ARGS_LEN - strlen(args) - 1;
1024 strncat(args, " ", args_left);
1025 args_left = MAX_ARGS_LEN - strlen(args) - 1;
1027 /* Simply stop tracing and destroy channel */
1028 strncat(args, "-R", args_left);
1029 args_left = MAX_ARGS_LEN - strlen(args) - 1;
1031 int retval = execute_command(args, username, password, lttd_path, fac_path);
1034 guint msg_left = 256;
1036 strcpy(msg, "A problem occured when executing the su command : ");
1037 msg_left = 256 - strlen(msg) - 1;
1038 strncat(msg, strerror(retval), msg_left);
1039 GtkWidget *dialogue =
1040 gtk_message_dialog_new(
1041 GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(button))),
1042 GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
1046 gtk_dialog_run(GTK_DIALOG(dialogue));
1047 gtk_widget_destroy(dialogue);
1052 /* Ask to the user if he wants to open the trace in a new window */
1053 GtkWidget *dialogue;
1057 dialogue = gtk_dialog_new_with_buttons("Open trace ?",
1058 GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(button))),
1059 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
1060 GTK_STOCK_YES,GTK_RESPONSE_ACCEPT,
1061 GTK_STOCK_NO,GTK_RESPONSE_REJECT,
1063 label = gtk_label_new("Do you want to open the trace in LTTV ?");
1064 gtk_widget_show(label);
1066 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialogue)->vbox),
1069 id = gtk_dialog_run(GTK_DIALOG(dialogue));
1072 case GTK_RESPONSE_ACCEPT:
1074 create_main_window_with_trace_list(trace_list);
1077 case GTK_RESPONSE_REJECT:
1081 gtk_widget_destroy(dialogue);
1082 g_slist_free(trace_list);
1087 * @fn GtkWidget* h_guicontrol(Tab*)
1089 * Control Module's constructor hook
1091 * This constructor is given as a parameter to the menuitem and toolbar button
1092 * registration. It creates the list.
1093 * @param tab A pointer to the parent window.
1094 * @return The widget created.
1097 h_guicontrol(LttvPlugin *plugin)
1099 LttvPluginTab *ptab = LTTV_PLUGIN_TAB(plugin);
1100 ControlData* f = gui_control(ptab);
1106 * @fn static void init()
1108 * This function initializes the Filter Viewer functionnality through the
1111 static void init() {
1113 lttvwindow_register_constructor("guicontrol",
1115 "Insert Tracing Control Module",
1116 hTraceControlInsert_xpm,
1117 "Insert Tracing Control Module",
1122 * @fn void control_destroy_walk(gpointer,gpointer)
1124 * Initiate the destruction of the current gui module
1125 * on the GTK Interface
1128 control_destroy_walk(gpointer data, gpointer user_data)
1130 ControlData *tcd = (ControlData*)data;
1132 g_debug("traceontrol.c : control_destroy_walk, %p", tcd);
1134 /* May already have been done by GTK window closing */
1135 if(GTK_IS_WIDGET(guicontrol_get_widget(tcd)))
1136 gtk_widget_destroy(guicontrol_get_widget(tcd));
1140 * @fn static void destroy()
1141 * @brief plugin's destroy function
1143 * This function releases the memory reserved by the module and unregisters
1144 * everything that has been registered in the gtkTraceSet API.
1146 static void destroy() {
1148 g_slist_foreach(g_control_list, control_destroy_walk, NULL );
1150 lttvwindow_unregister_constructor(h_guicontrol);
1155 LTTV_MODULE("guitracecontrol", "Trace Control Window", \
1156 "Graphical module that let user control kernel tracing", \
1157 init, destroy, "lttvwindow")