283674b726650428a6ffc1d66f4db1bd51173617
[lttv.git] / lttv / modules / gui / tracecontrol / tracecontrol.c
1 /* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2005 Mathieu Desnoyers
3 *
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;
7 *
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.
12 *
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,
16 * MA 02111-1307, USA.
17 */
18
19 #ifdef HAVE_CONFIG_H
20 #include <config.h>
21 #endif
22
23 #include <glib.h>
24 #include <glib/gprintf.h>
25 #include <string.h>
26 #include <gtk/gtk.h>
27 #include <gdk/gdk.h>
28 #include <gdk/gdkkeysyms.h>
29
30 #include <lttv/lttv.h>
31 #include <lttv/module.h>
32 #include <lttv/hook.h>
33
34 #include <lttvwindow/lttvwindow.h>
35 #include <lttvwindow/lttvwindowtraces.h>
36 #include <lttvwindow/callbacks.h>
37 #include <lttvwindow/lttv_plugin_tab.h>
38
39 #include "hTraceControlInsert.xpm"
40 #include "TraceControlStart.xpm"
41 #include "TraceControlPause.xpm"
42 #include "TraceControlStop.xpm"
43
44 #include <sys/types.h>
45 #include <unistd.h>
46 #include <stdlib.h>
47 #include <pty.h>
48 #include <utmp.h>
49 #include <sys/wait.h>
50 #include <sys/poll.h>
51 #include <errno.h>
52 #include <fcntl.h>
53 #include <sched.h>
54
55 #define MAX_ARGS_LEN PATH_MAX * 10
56
57 GSList *g_control_list = NULL ;
58
59 /*! \file lttv/modules/gui/tracecontrol/tracecontrol.c
60 * \brief Graphic trace start/stop control interface.
61 *
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.
64 *
65 */
66
67 typedef struct _ControlData ControlData;
68
69 /*
70 * Prototypes
71 */
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);
77
78 /*
79 * Callback functions
80 */
81
82 static void arm_clicked (GtkButton *button, gpointer user_data);
83 static void disarm_clicked (GtkButton *button, gpointer user_data);
84 static void start_clicked (GtkButton *button, gpointer user_data);
85 static void pause_clicked (GtkButton *button, gpointer user_data);
86 static void unpause_clicked (GtkButton *button, gpointer user_data);
87 static void stop_clicked (GtkButton *button, gpointer user_data);
88
89
90 /**
91 * @struct _ControlData
92 *
93 * @brief Main structure of gui control
94 */
95 struct _ControlData {
96 Tab *tab; /**< current tab of module */
97
98 GtkWidget *window; /**< window */
99
100 GtkWidget *main_box; /**< main container */
101 GtkWidget *ltt_armall_button;
102 GtkWidget *ltt_disarmall_button;
103 GtkWidget *start_button;
104 GtkWidget *pause_button;
105 GtkWidget *unpause_button;
106 GtkWidget *stop_button;
107 GtkWidget *username_label;
108 GtkWidget *username_entry;
109 GtkWidget *password_label;
110 GtkWidget *password_entry;
111 GtkWidget *channel_dir_label;
112 GtkWidget *channel_dir_entry;
113 GtkWidget *trace_dir_label;
114 GtkWidget *trace_dir_entry;
115 GtkWidget *trace_name_label;
116 GtkWidget *trace_name_entry;
117 GtkWidget *trace_mode_label;
118 GtkWidget *trace_mode_combo;
119 GtkWidget *start_daemon_label;
120 GtkWidget *start_daemon_check;
121 GtkWidget *append_label;
122 GtkWidget *append_check;
123 GtkWidget *optional_label;
124 GtkWidget *subbuf_size_label;
125 GtkWidget *subbuf_size_entry;
126 GtkWidget *subbuf_num_label;
127 GtkWidget *subbuf_num_entry;
128 GtkWidget *lttd_threads_label;
129 GtkWidget *lttd_threads_entry;
130 GtkWidget *lttctl_path_label;
131 GtkWidget *lttctl_path_entry;
132 GtkWidget *lttd_path_label;
133 GtkWidget *lttd_path_entry;
134 GtkWidget *ltt_armall_path_label;
135 GtkWidget *ltt_armall_path_entry;
136 GtkWidget *ltt_disarmall_path_label;
137 GtkWidget *ltt_disarmall_path_entry;
138 };
139
140 /**
141 * @fn GtkWidget* guicontrol_get_widget(ControlData*)
142 *
143 * This function returns the current main widget
144 * used by this module
145 * @param tcd the module struct
146 * @return The main widget
147 */
148 GtkWidget*
149 guicontrol_get_widget(ControlData *tcd)
150 {
151 return tcd->window;
152 }
153
154 /**
155 * @fn ControlData* gui_control(Tab*)
156 *
157 * Constructor is used to create ControlData data structure.
158 * @param tab The tab structure used by the widget
159 * @return The Filter viewer data created.
160 */
161 ControlData*
162 gui_control(LttvPluginTab *ptab)
163 {
164 Tab *tab = ptab->tab;
165 g_debug("filter::gui_control()");
166
167 unsigned i;
168 GtkCellRenderer *renderer;
169 GtkTreeViewColumn *column;
170
171 ControlData* tcd = g_new(ControlData,1);
172
173 tcd->tab = tab;
174
175 tcd->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
176 gtk_window_set_title(GTK_WINDOW(tcd->window), "LTTng Trace Control");
177 /*
178 * Initiating GtkTable layout
179 * starts with 2 rows and 5 columns and
180 * expands when expressions added
181 */
182 tcd->main_box = gtk_table_new(14,7,FALSE);
183 gtk_table_set_row_spacings(GTK_TABLE(tcd->main_box),5);
184 gtk_table_set_col_spacings(GTK_TABLE(tcd->main_box),5);
185
186 gtk_container_add(GTK_CONTAINER(tcd->window), GTK_WIDGET(tcd->main_box));
187
188 GList *focus_chain = NULL;
189
190 /*
191 * start/pause/stop buttons
192 */
193
194 GdkPixbuf *pixbuf;
195 GtkWidget *image;
196 pixbuf = gdk_pixbuf_new_from_xpm_data((const char **)TraceControlStart_xpm);
197 image = gtk_image_new_from_pixbuf(pixbuf);
198 tcd->ltt_armall_button = gtk_button_new_with_label("Arm LTTng kernel probes");
199 //2.6 gtk_button_set_image(GTK_BUTTON(tcd->ltt_armall_button), image);
200 g_object_set(G_OBJECT(tcd->ltt_armall_button), "image", image, NULL);
201 gtk_button_set_alignment(GTK_BUTTON(tcd->ltt_armall_button), 0.0, 0.0);
202 gtk_widget_show (tcd->ltt_armall_button);
203 gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->ltt_armall_button,6,7,0,1,GTK_FILL,GTK_FILL,2,2);
204
205 pixbuf = gdk_pixbuf_new_from_xpm_data((const char **)TraceControlStop_xpm);
206 image = gtk_image_new_from_pixbuf(pixbuf);
207 tcd->ltt_disarmall_button = gtk_button_new_with_label("Disarm LTTng kernel probes");
208 //2.6 gtk_button_set_image(GTK_BUTTON(tcd->ltt_disarmall_button), image);
209 g_object_set(G_OBJECT(tcd->ltt_disarmall_button), "image", image, NULL);
210 gtk_button_set_alignment(GTK_BUTTON(tcd->ltt_disarmall_button), 0.0, 0.0);
211 gtk_widget_show (tcd->ltt_disarmall_button);
212 gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->ltt_disarmall_button,6,7,1,2,GTK_FILL,GTK_FILL,2,2);
213
214 pixbuf = gdk_pixbuf_new_from_xpm_data((const char **)TraceControlStart_xpm);
215 image = gtk_image_new_from_pixbuf(pixbuf);
216 tcd->start_button = gtk_button_new_with_label("start");
217 //2.6 gtk_button_set_image(GTK_BUTTON(tcd->start_button), image);
218 g_object_set(G_OBJECT(tcd->start_button), "image", image, NULL);
219 gtk_button_set_alignment(GTK_BUTTON(tcd->start_button), 0.0, 0.0);
220 gtk_widget_show (tcd->start_button);
221 gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->start_button,6,7,2,3,GTK_FILL,GTK_FILL,2,2);
222
223 pixbuf = gdk_pixbuf_new_from_xpm_data((const char **)TraceControlPause_xpm);
224 image = gtk_image_new_from_pixbuf(pixbuf);
225 tcd->pause_button = gtk_button_new_with_label("pause");
226 //2.6 gtk_button_set_image(GTK_BUTTON(tcd->pause_button), image);
227 g_object_set(G_OBJECT(tcd->pause_button), "image", image, NULL);
228 gtk_button_set_alignment(GTK_BUTTON(tcd->pause_button), 0.0, 0.0);
229 gtk_widget_show (tcd->pause_button);
230 gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->pause_button,6,7,3,4,GTK_FILL,GTK_FILL,2,2);
231
232 pixbuf = gdk_pixbuf_new_from_xpm_data((const char **)TraceControlPause_xpm);
233 image = gtk_image_new_from_pixbuf(pixbuf);
234 tcd->unpause_button = gtk_button_new_with_label("unpause");
235 //2.6 gtk_button_set_image(GTK_BUTTON(tcd->unpause_button), image);
236 g_object_set(G_OBJECT(tcd->unpause_button), "image", image, NULL);
237 gtk_button_set_alignment(GTK_BUTTON(tcd->unpause_button), 0.0, 0.0);
238 gtk_widget_show (tcd->unpause_button);
239 gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->unpause_button,6,7,4,5,GTK_FILL,GTK_FILL,2,2);
240
241 pixbuf = gdk_pixbuf_new_from_xpm_data((const char **)TraceControlStop_xpm);
242 image = gtk_image_new_from_pixbuf(pixbuf);
243 tcd->stop_button = gtk_button_new_with_label("stop");
244 //2.6 gtk_button_set_image(GTK_BUTTON(tcd->stop_button), image);
245 g_object_set(G_OBJECT(tcd->stop_button), "image", image, NULL);
246 gtk_button_set_alignment(GTK_BUTTON(tcd->stop_button), 0.0, 0.0);
247 gtk_widget_show (tcd->stop_button);
248 gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->stop_button,6,7,5,6,GTK_FILL,GTK_FILL,2,2);
249
250 /*
251 * First half of the filter window
252 * - textual entry of filter expression
253 * - processing button
254 */
255 tcd->username_label = gtk_label_new("Username:");
256 gtk_widget_show (tcd->username_label);
257 tcd->username_entry = gtk_entry_new();
258 gtk_entry_set_text(GTK_ENTRY(tcd->username_entry),"root");
259 gtk_widget_show (tcd->username_entry);
260 gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->username_label,0,2,0,1,GTK_FILL,GTK_FILL,2,2);
261 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);
262
263
264
265 tcd->password_label = gtk_label_new("Password:");
266 gtk_widget_show (tcd->password_label);
267 tcd->password_entry = gtk_entry_new();
268 gtk_entry_set_visibility(GTK_ENTRY(tcd->password_entry), FALSE);
269 gtk_widget_show (tcd->password_entry);
270 gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->password_label,0,2,1,2,GTK_FILL,GTK_FILL,2,2);
271 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);
272
273
274 tcd->channel_dir_label = gtk_label_new("Channel directory:");
275 gtk_widget_show (tcd->channel_dir_label);
276 tcd->channel_dir_entry = gtk_entry_new();
277 gtk_entry_set_text(GTK_ENTRY(tcd->channel_dir_entry),"/mnt/debugfs/ltt");
278 gtk_widget_show (tcd->channel_dir_entry);
279 gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->channel_dir_label,0,2,2,3,GTK_FILL,GTK_FILL,2,2);
280 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);
281
282 tcd->trace_dir_label = gtk_label_new("Trace directory:");
283 gtk_widget_show (tcd->trace_dir_label);
284 tcd->trace_dir_entry = gtk_entry_new();
285 gtk_entry_set_text(GTK_ENTRY(tcd->trace_dir_entry),"/tmp/trace1");
286 gtk_widget_show (tcd->trace_dir_entry);
287 gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->trace_dir_label,0,2,3,4,GTK_FILL,GTK_FILL,2,2);
288 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);
289
290 tcd->trace_name_label = gtk_label_new("Trace name:");
291 gtk_widget_show (tcd->trace_name_label);
292 tcd->trace_name_entry = gtk_entry_new();
293 gtk_entry_set_text(GTK_ENTRY(tcd->trace_name_entry),"trace");
294 gtk_widget_show (tcd->trace_name_entry);
295 gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->trace_name_label,0,2,4,5,GTK_FILL,GTK_FILL,2,2);
296 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);
297
298 tcd->trace_mode_label = gtk_label_new("Trace mode ");
299 gtk_widget_show (tcd->trace_mode_label);
300 tcd->trace_mode_combo = gtk_combo_box_new_text();
301 gtk_combo_box_append_text(GTK_COMBO_BOX(tcd->trace_mode_combo),
302 "normal");
303 gtk_combo_box_append_text(GTK_COMBO_BOX(tcd->trace_mode_combo),
304 "flight recorder");
305 gtk_combo_box_set_active(GTK_COMBO_BOX(tcd->trace_mode_combo), 0);
306 gtk_widget_show (tcd->trace_mode_combo);
307 gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->trace_mode_label,0,2,5,6,GTK_FILL,GTK_FILL,2,2);
308 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);
309
310 tcd->start_daemon_label = gtk_label_new("Start daemon ");
311 gtk_widget_show (tcd->start_daemon_label);
312 tcd->start_daemon_check = gtk_check_button_new();
313 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(tcd->start_daemon_check), TRUE);
314 gtk_widget_show (tcd->start_daemon_check);
315 gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->start_daemon_label,0,2,6,7,GTK_FILL,GTK_FILL,2,2);
316 gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->start_daemon_check,2,6,6,7,GTK_FILL,GTK_FILL,0,0);
317
318 tcd->append_label = gtk_label_new("Append to trace ");
319 gtk_widget_show (tcd->append_label);
320 tcd->append_check = gtk_check_button_new();
321 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(tcd->append_check), FALSE);
322 gtk_widget_show (tcd->append_check);
323 gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->append_label,0,2,7,8,GTK_FILL,GTK_FILL,2,2);
324 gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->append_check,2,6,7,8,GTK_FILL,GTK_FILL,0,0);
325
326
327 tcd->optional_label = gtk_label_new("Optional fields ");
328 gtk_widget_show (tcd->optional_label);
329 gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->optional_label,0,6,8,9,GTK_FILL,GTK_FILL,2,2);
330
331 tcd->subbuf_size_label = gtk_label_new("Subbuffer size:");
332 gtk_widget_show (tcd->subbuf_size_label);
333 tcd->subbuf_size_entry = gtk_entry_new();
334 gtk_widget_show (tcd->subbuf_size_entry);
335 gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->subbuf_size_label,0,2,9,10,GTK_FILL,GTK_FILL,2,2);
336 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);
337
338 tcd->subbuf_num_label = gtk_label_new("Number of subbuffers:");
339 gtk_widget_show (tcd->subbuf_num_label);
340 tcd->subbuf_num_entry = gtk_entry_new();
341 gtk_widget_show (tcd->subbuf_num_entry);
342 gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->subbuf_num_label,0,2,10,11,GTK_FILL,GTK_FILL,2,2);
343 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);
344
345 tcd->lttd_threads_label = gtk_label_new("Number of lttd threads:");
346 gtk_widget_show (tcd->lttd_threads_label);
347 tcd->lttd_threads_entry = gtk_entry_new();
348 gtk_entry_set_text(GTK_ENTRY(tcd->lttd_threads_entry), "1");
349 gtk_widget_show (tcd->lttd_threads_entry);
350 gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->lttd_threads_label,0,2,11,12,GTK_FILL,GTK_FILL,2,2);
351 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);
352
353 tcd->lttctl_path_label = gtk_label_new("path to lttctl:");
354 gtk_widget_show (tcd->lttctl_path_label);
355 tcd->lttctl_path_entry = gtk_entry_new();
356 gtk_entry_set_text(GTK_ENTRY(tcd->lttctl_path_entry),PACKAGE_BIN_DIR "/lttctl");
357 gtk_widget_show (tcd->lttctl_path_entry);
358 gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->lttctl_path_label,0,2,12,13,GTK_FILL,GTK_FILL,2,2);
359 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);
360
361
362 tcd->lttd_path_label = gtk_label_new("path to lttd:");
363 gtk_widget_show (tcd->lttd_path_label);
364 tcd->lttd_path_entry = gtk_entry_new();
365 gtk_entry_set_text(GTK_ENTRY(tcd->lttd_path_entry),PACKAGE_BIN_DIR "/lttd");
366 gtk_widget_show (tcd->lttd_path_entry);
367 gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->lttd_path_label,0,2,13,14,GTK_FILL,GTK_FILL,2,2);
368 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);
369
370 tcd->ltt_armall_path_label = gtk_label_new("path to ltt_armall:");
371 gtk_widget_show (tcd->ltt_armall_path_label);
372 tcd->ltt_armall_path_entry = gtk_entry_new();
373 gtk_entry_set_text(GTK_ENTRY(tcd->ltt_armall_path_entry),PACKAGE_BIN_DIR "/ltt-armall");
374 gtk_widget_show (tcd->ltt_armall_path_entry);
375 gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->ltt_armall_path_label,0,2,14,15,GTK_FILL,GTK_FILL,2,2);
376 gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->ltt_armall_path_entry,2,6,14,15,GTK_FILL|GTK_EXPAND|GTK_SHRINK,GTK_FILL,0,0);
377
378 tcd->ltt_disarmall_path_label = gtk_label_new("path to ltt_disarmall:");
379 gtk_widget_show (tcd->ltt_disarmall_path_label);
380 tcd->ltt_disarmall_path_entry = gtk_entry_new();
381 gtk_entry_set_text(GTK_ENTRY(tcd->ltt_disarmall_path_entry),PACKAGE_BIN_DIR "/ltt-disarmall");
382 gtk_widget_show (tcd->ltt_disarmall_path_entry);
383 gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->ltt_disarmall_path_label,0,2,15,16,GTK_FILL,GTK_FILL,2,2);
384 gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->ltt_disarmall_path_entry,2,6,15,16,GTK_FILL|GTK_EXPAND|GTK_SHRINK,GTK_FILL,0,0);
385
386 focus_chain = g_list_append (focus_chain, tcd->username_entry);
387 focus_chain = g_list_append (focus_chain, tcd->password_entry);
388 focus_chain = g_list_append (focus_chain, tcd->ltt_armall_path_entry);
389 focus_chain = g_list_append (focus_chain, tcd->ltt_disarmall_path_entry);
390 focus_chain = g_list_append (focus_chain, tcd->start_button);
391 focus_chain = g_list_append (focus_chain, tcd->pause_button);
392 focus_chain = g_list_append (focus_chain, tcd->unpause_button);
393 focus_chain = g_list_append (focus_chain, tcd->stop_button);
394 focus_chain = g_list_append (focus_chain, tcd->channel_dir_entry);
395 focus_chain = g_list_append (focus_chain, tcd->trace_dir_entry);
396 focus_chain = g_list_append (focus_chain, tcd->trace_name_entry);
397 focus_chain = g_list_append (focus_chain, tcd->trace_mode_combo);
398 focus_chain = g_list_append (focus_chain, tcd->start_daemon_check);
399 focus_chain = g_list_append (focus_chain, tcd->append_check);
400 focus_chain = g_list_append (focus_chain, tcd->subbuf_size_entry);
401 focus_chain = g_list_append (focus_chain, tcd->subbuf_num_entry);
402 focus_chain = g_list_append (focus_chain, tcd->lttd_threads_entry);
403 focus_chain = g_list_append (focus_chain, tcd->lttctl_path_entry);
404 focus_chain = g_list_append (focus_chain, tcd->lttd_path_entry);
405
406 gtk_container_set_focus_chain(GTK_CONTAINER(tcd->main_box), focus_chain);
407
408 g_list_free(focus_chain);
409
410 g_signal_connect(G_OBJECT(tcd->start_button), "clicked",
411 (GCallback)start_clicked, tcd);
412 g_signal_connect(G_OBJECT(tcd->pause_button), "clicked",
413 (GCallback)pause_clicked, tcd);
414 g_signal_connect(G_OBJECT(tcd->unpause_button), "clicked",
415 (GCallback)unpause_clicked, tcd);
416 g_signal_connect(G_OBJECT(tcd->stop_button), "clicked",
417 (GCallback)stop_clicked, tcd);
418 g_signal_connect(G_OBJECT(tcd->ltt_armall_button), "clicked",
419 (GCallback)arm_clicked, tcd);
420 g_signal_connect(G_OBJECT(tcd->ltt_disarmall_button), "clicked",
421 (GCallback)disarm_clicked, tcd);
422
423 /*
424 * show main container
425 */
426 gtk_widget_show(tcd->main_box);
427 gtk_widget_show(tcd->window);
428
429
430 g_object_set_data_full(
431 G_OBJECT(guicontrol_get_widget(tcd)),
432 "control_viewer_data",
433 tcd,
434 (GDestroyNotify)gui_control_destructor);
435
436 g_control_list = g_slist_append(
437 g_control_list,
438 tcd);
439
440 return tcd;
441 }
442
443
444 /**
445 * @fn void gui_control_destructor(ControlData*)
446 *
447 * Destructor for the filter gui module
448 * @param tcd The module structure
449 */
450 void
451 gui_control_destructor(ControlData *tcd)
452 {
453 Tab *tab = tcd->tab;
454
455 /* May already been done by GTK window closing */
456 if(GTK_IS_WIDGET(guicontrol_get_widget(tcd))){
457 g_info("widget still exists");
458 }
459 // if(tab != NULL) {
460 // lttvwindow_unregister_traceset_notify(tcd->tab,
461 // filter_traceset_changed,
462 // filter_viewer_data);
463 // }
464 lttvwindowtraces_background_notify_remove(tcd);
465
466 g_control_list = g_slist_remove(g_control_list, tcd);
467
468 g_free(tcd);
469 }
470
471 static int execute_command(const gchar *command, const gchar *username,
472 const gchar *password, const gchar *lttd_path)
473 {
474 pid_t pid;
475 int fdpty;
476 pid = forkpty(&fdpty, NULL, NULL, NULL);
477 int retval = 0;
478
479 if(pid > 0) {
480 /* parent */
481 gchar buf[256];
482 int status;
483 ssize_t count;
484 /* discuss with su */
485 struct timeval timeout;
486 timeout.tv_sec = 1;
487 timeout.tv_usec = 0;
488
489 struct pollfd pollfd;
490 int num_rdy;
491 int num_hup = 0;
492 enum read_state { GET_LINE, GET_SEMI, GET_SPACE } read_state = GET_LINE;
493
494 retval = fcntl(fdpty, F_SETFL, O_WRONLY);
495 if(retval == -1) {
496 perror("Error in fcntl");
497 goto wait_child;
498 }
499
500 /* Read the output from the child terminal before the prompt. If no data in
501 * 200 ms, we stop reading to give the password */
502 g_info("Reading from child console...");
503 while(1) {
504 pollfd.fd = fdpty;
505 pollfd.events = POLLIN|POLLPRI|POLLERR|POLLHUP|POLLNVAL;
506
507 num_rdy = poll(&pollfd, 1, -1);
508 if(num_rdy == -1) {
509 perror("Poll error");
510 goto wait_child;
511 }
512
513 /* Timeout : Stop waiting for chars */
514 if(num_rdy == 0) goto wait_child;
515
516 /* Check for fatal errors */
517 if(pollfd.revents & POLLERR) {
518 g_warning("Error returned in polling fd\n");
519 num_hup++;
520 }
521 if(pollfd.revents & POLLNVAL) {
522 g_warning("Polling fd tells it is not open");
523 num_hup++;
524 }
525
526 if(pollfd.revents & POLLHUP) {
527
528 g_info("Polling FD : hung up.");
529 num_hup++;
530
531 }
532
533 if(pollfd.revents & (POLLIN | POLLPRI)) {
534 int count;
535 count = read (fdpty, buf, 256);
536 if(count > 0) {
537 unsigned int i;
538 buf[count] = '\0';
539 g_printf("%s", buf);
540 for(i=0; i<count; i++) {
541 switch(read_state) {
542 case GET_LINE:
543 if(buf[i] == '\n') {
544 read_state = GET_SEMI;
545 g_debug("Tracecontrol input line skip\n");
546 }
547 break;
548 case GET_SEMI:
549 if(buf[i] == ':') {
550 g_debug("Tracecontrol input : marker found\n");
551 read_state = GET_SPACE;
552 }
553 break;
554 case GET_SPACE:
555 if(buf[i] == ' ') {
556 g_debug("Tracecontrol input space marker found\n");
557 goto write_password;
558 }
559 break;
560 }
561 }
562 } else if(count == -1) {
563 perror("Error in read");
564 goto wait_child;
565 }
566
567 }
568
569 if(num_hup > 0) {
570 g_warning("Child hung up without returning a full reply");
571 goto wait_child;
572 }
573 }
574 write_password:
575 fsync(fdpty);
576 pollfd.fd = fdpty;
577 pollfd.events = POLLOUT|POLLERR|POLLHUP|POLLNVAL;
578
579 num_rdy = poll(&pollfd, 1, -1);
580 if(num_rdy == -1) {
581 perror("Poll error");
582 goto wait_child;
583 }
584
585 /* Write the password */
586 g_info("Got su prompt, now writing password...");
587 int ret;
588 sleep(1);
589 ret = write(fdpty, password, strlen(password));
590 if(ret < 0) perror("Error in write");
591 ret = write(fdpty, "\n", 1);
592 if(ret < 0) perror("Error in write");
593 fsync(fdpty);
594 /* Take the output from the terminal and show it on the real console */
595 g_info("Getting data from child terminal...");
596 while(1) {
597 int num_hup = 0;
598 pollfd.fd = fdpty;
599 pollfd.events = POLLIN|POLLPRI|POLLERR|POLLHUP|POLLNVAL;
600
601 num_rdy = poll(&pollfd, 1, -1);
602 if(num_rdy == -1) {
603 perror("Poll error");
604 goto wait_child;
605 }
606 if(num_rdy == 0) break;
607
608 if(pollfd.revents & (POLLERR|POLLNVAL)) {
609 g_warning("Error returned in polling fd\n");
610 num_hup++;
611 }
612
613 if(pollfd.revents & (POLLIN|POLLPRI) ) {
614 count = read (fdpty, buf, 256);
615 if(count > 0) {
616 buf[count] = '\0';
617 printf("%s", buf);
618 } else if(count == -1) {
619 perror("Error in read");
620 goto wait_child;
621 }
622 }
623
624 if(pollfd.revents & POLLHUP) {
625 g_info("Polling FD : hung up.");
626 num_hup++;
627 }
628
629 if(num_hup > 0) goto wait_child;
630 }
631 wait_child:
632 g_info("Waiting for child exit...");
633
634 ret = waitpid(pid, &status, 0);
635
636 if(ret == -1) {
637 g_warning("An error occured in wait : %s",
638 strerror(errno));
639 } else {
640 if(WIFEXITED(status))
641 if(WEXITSTATUS(status) != 0) {
642 retval = WEXITSTATUS(status);
643 g_warning("An error occured in the su command : %s",
644 strerror(retval));
645 }
646 }
647
648 g_info("Child exited.");
649
650 } else if(pid == 0) {
651 /* Setup environment variables */
652 if(strcmp(lttd_path, "") != 0)
653 setenv("LTT_DAEMON", lttd_path, 1);
654
655 /* One comment line (must be only one) */
656 g_printf("Executing (as %s) : %s\n", username, command);
657
658 execlp("su", "su", "-p", "-c", command, username, NULL);
659 exit(-1); /* not supposed to happen! */
660
661 //gint ret = execvp();
662
663 } else {
664 /* error */
665 g_warning("Error happened when forking for su");
666 }
667
668 return retval;
669 }
670
671
672 /* Callbacks */
673
674 void start_clicked (GtkButton *button, gpointer user_data)
675 {
676 ControlData *tcd = (ControlData*)user_data;
677
678 const gchar *username = gtk_entry_get_text(GTK_ENTRY(tcd->username_entry));
679 const gchar *password = gtk_entry_get_text(GTK_ENTRY(tcd->password_entry));
680 const gchar *channel_dir =
681 gtk_entry_get_text(GTK_ENTRY(tcd->channel_dir_entry));
682 const gchar *trace_dir = gtk_entry_get_text(GTK_ENTRY(tcd->trace_dir_entry));
683 const gchar *trace_name =
684 gtk_entry_get_text(GTK_ENTRY(tcd->trace_name_entry));
685
686 const gchar *trace_mode_sel;
687 GtkTreeIter iter;
688
689 gtk_combo_box_get_active_iter(GTK_COMBO_BOX(tcd->trace_mode_combo), &iter);
690 gtk_tree_model_get(
691 gtk_combo_box_get_model(GTK_COMBO_BOX(tcd->trace_mode_combo)),
692 &iter, 0, &trace_mode_sel, -1);
693 //const gchar *trace_mode_sel =
694 //2.6+ gtk_combo_box_get_active_text(GTK_COMBO_BOX(tcd->trace_mode_combo));
695 const gchar *trace_mode;
696 if(strcmp(trace_mode_sel, "normal") == 0)
697 trace_mode = "normal";
698 else
699 trace_mode = "flight";
700
701 gboolean start_daemon =
702 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(tcd->start_daemon_check));
703
704 gboolean append =
705 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(tcd->append_check));
706
707 const gchar *subbuf_size =
708 gtk_entry_get_text(GTK_ENTRY(tcd->subbuf_size_entry));
709 const gchar *subbuf_num =
710 gtk_entry_get_text(GTK_ENTRY(tcd->subbuf_num_entry));
711 const gchar *threads_num =
712 gtk_entry_get_text(GTK_ENTRY(tcd->lttd_threads_entry));
713 const gchar *lttctl_path =
714 gtk_entry_get_text(GTK_ENTRY(tcd->lttctl_path_entry));
715 const gchar *lttd_path = gtk_entry_get_text(GTK_ENTRY(tcd->lttd_path_entry));
716
717 /* Setup arguments to su */
718 /* child */
719 gchar args[MAX_ARGS_LEN];
720 gint args_left = MAX_ARGS_LEN - 1; /* for \0 */
721
722 args[0] = '\0';
723
724 /* Command */
725 strncat(args, "exec", args_left);
726 args_left = MAX_ARGS_LEN - strlen(args) - 1;
727
728 /* space */
729 strncat(args, " ", args_left);
730 args_left = MAX_ARGS_LEN - strlen(args) - 1;
731
732 if(strcmp(lttctl_path, "") == 0)
733 strncat(args, "lttctl", args_left);
734 else
735 strncat(args, lttctl_path, args_left);
736 args_left = MAX_ARGS_LEN - strlen(args) - 1;
737
738 /* space */
739 strncat(args, " ", args_left);
740 args_left = MAX_ARGS_LEN - strlen(args) - 1;
741
742 /* Start daemon ? */
743 if(start_daemon) {
744 strncat(args, "-C", args_left);
745 args_left = MAX_ARGS_LEN - strlen(args) - 1;
746 } else {
747 /* Simply create the channel and then start tracing */
748 //strncat(args, "-b", args_left);
749 //args_left = MAX_ARGS_LEN - strlen(args) - 1;
750 }
751
752 /* space */
753 strncat(args, " ", args_left);
754 args_left = MAX_ARGS_LEN - strlen(args) - 1;
755
756 /* channel dir */
757 strncat(args, "--channel_root ", args_left);
758 args_left = MAX_ARGS_LEN - strlen(args) - 1;
759 strncat(args, channel_dir, args_left);
760 args_left = MAX_ARGS_LEN - strlen(args) - 1;
761
762 /* space */
763 strncat(args, " ", args_left);
764 args_left = MAX_ARGS_LEN - strlen(args) - 1;
765
766 /* trace dir */
767 strncat(args, "-w ", args_left);
768 args_left = MAX_ARGS_LEN - strlen(args) - 1;
769 strncat(args, trace_dir, args_left);
770 args_left = MAX_ARGS_LEN - strlen(args) - 1;
771
772 /* space */
773 strncat(args, " ", args_left);
774 args_left = MAX_ARGS_LEN - strlen(args) - 1;
775
776 if(strcmp(trace_mode, "flight") == 0) {
777 strncat(args, "-o channel.all.overwrite=1", args_left);
778 args_left = MAX_ARGS_LEN - strlen(args) - 1;
779 } else {
780 strncat(args, "-o channel.all.overwrite=0", args_left);
781 args_left = MAX_ARGS_LEN - strlen(args) - 1;
782 }
783
784 /* Append to trace ? */
785 if(append) {
786 /* space */
787 strncat(args, " ", args_left);
788 args_left = MAX_ARGS_LEN - strlen(args) - 1;
789 strncat(args, "-a", args_left);
790 args_left = MAX_ARGS_LEN - strlen(args) - 1;
791 }
792
793 /* optional arguments */
794 /* subbuffer size */
795 if(strcmp(subbuf_size, "") != 0) {
796 /* space */
797 strncat(args, " ", args_left);
798 args_left = MAX_ARGS_LEN - strlen(args) - 1;
799
800 strncat(args, "-o channel.all.bufsize=", args_left);
801 args_left = MAX_ARGS_LEN - strlen(args) - 1;
802 strncat(args, subbuf_size, args_left);
803 args_left = MAX_ARGS_LEN - strlen(args) - 1;
804 }
805
806 /* number of subbuffers */
807 if(strcmp(subbuf_num, "") != 0) {
808 /* space */
809 strncat(args, " ", args_left);
810 args_left = MAX_ARGS_LEN - strlen(args) - 1;
811
812 strncat(args, "-o channel.all.bufnum=", args_left);
813 args_left = MAX_ARGS_LEN - strlen(args) - 1;
814 strncat(args, subbuf_num, args_left);
815 args_left = MAX_ARGS_LEN - strlen(args) - 1;
816 }
817
818 /* number of lttd threads */
819 if(strcmp(threads_num, "") != 0) {
820 /* space */
821 strncat(args, " ", args_left);
822 args_left = MAX_ARGS_LEN - strlen(args) - 1;
823
824 strncat(args, "-n ", args_left);
825 args_left = MAX_ARGS_LEN - strlen(args) - 1;
826 strncat(args, threads_num, args_left);
827 args_left = MAX_ARGS_LEN - strlen(args) - 1;
828 }
829
830 /* space */
831 strncat(args, " ", args_left);
832 args_left = MAX_ARGS_LEN - strlen(args) - 1;
833
834 /* name */
835 strncat(args, trace_name, args_left);
836 args_left = MAX_ARGS_LEN - strlen(args) - 1;
837
838 int retval = execute_command(args, username, password, lttd_path);
839
840 if(retval) {
841 gchar msg[256];
842 guint msg_left = 256;
843
844 strcpy(msg, "A problem occured when executing the su command : ");
845 msg_left = 256 - strlen(msg) - 1;
846 strncat(msg, strerror(retval), msg_left);
847 GtkWidget *dialogue =
848 gtk_message_dialog_new(
849 GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(button))),
850 GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
851 GTK_MESSAGE_ERROR,
852 GTK_BUTTONS_OK,
853 msg);
854 gtk_dialog_run(GTK_DIALOG(dialogue));
855 gtk_widget_destroy(dialogue);
856 }
857
858 }
859
860
861 void pause_clicked (GtkButton *button, gpointer user_data)
862 {
863 ControlData *tcd = (ControlData*)user_data;
864
865 const gchar *username = gtk_entry_get_text(GTK_ENTRY(tcd->username_entry));
866 const gchar *password = gtk_entry_get_text(GTK_ENTRY(tcd->password_entry));
867 const gchar *trace_name =
868 gtk_entry_get_text(GTK_ENTRY(tcd->trace_name_entry));
869 const gchar *lttd_path = "";
870
871 const gchar *lttctl_path =
872 gtk_entry_get_text(GTK_ENTRY(tcd->lttctl_path_entry));
873
874 /* Setup arguments to su */
875 /* child */
876 gchar args[MAX_ARGS_LEN];
877 gint args_left = MAX_ARGS_LEN - 1; /* for \0 */
878
879 args[0] = '\0';
880
881 /* Command */
882 strncat(args, "exec", args_left);
883 args_left = MAX_ARGS_LEN - strlen(args) - 1;
884
885 /* space */
886 strncat(args, " ", args_left);
887 args_left = MAX_ARGS_LEN - strlen(args) - 1;
888
889 if(strcmp(lttctl_path, "") == 0)
890 strncat(args, "lttctl", args_left);
891 else
892 strncat(args, lttctl_path, args_left);
893 args_left = MAX_ARGS_LEN - strlen(args) - 1;
894
895 /* space */
896 strncat(args, " ", args_left);
897 args_left = MAX_ARGS_LEN - strlen(args) - 1;
898
899 /* Simply pause tracing */
900 strncat(args, "-p", args_left);
901 args_left = MAX_ARGS_LEN - strlen(args) - 1;
902
903 /* space */
904 strncat(args, " ", args_left);
905 args_left = MAX_ARGS_LEN - strlen(args) - 1;
906
907 /* name */
908 strncat(args, trace_name, args_left);
909 args_left = MAX_ARGS_LEN - strlen(args) - 1;
910
911 int retval = execute_command(args, username, password, lttd_path);
912 if(retval) {
913 gchar msg[256];
914 guint msg_left = 256;
915
916 strcpy(msg, "A problem occured when executing the su command : ");
917 msg_left = 256 - strlen(msg) - 1;
918 strncat(msg, strerror(retval), msg_left);
919 GtkWidget *dialogue =
920 gtk_message_dialog_new(
921 GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(button))),
922 GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
923 GTK_MESSAGE_ERROR,
924 GTK_BUTTONS_OK,
925 msg);
926 gtk_dialog_run(GTK_DIALOG(dialogue));
927 gtk_widget_destroy(dialogue);
928 }
929
930 }
931
932 void unpause_clicked (GtkButton *button, gpointer user_data)
933 {
934 ControlData *tcd = (ControlData*)user_data;
935
936 const gchar *username = gtk_entry_get_text(GTK_ENTRY(tcd->username_entry));
937 const gchar *password = gtk_entry_get_text(GTK_ENTRY(tcd->password_entry));
938 const gchar *trace_name =
939 gtk_entry_get_text(GTK_ENTRY(tcd->trace_name_entry));
940 const gchar *lttd_path = "";
941
942 const gchar *lttctl_path =
943 gtk_entry_get_text(GTK_ENTRY(tcd->lttctl_path_entry));
944
945 /* Setup arguments to su */
946 /* child */
947 gchar args[MAX_ARGS_LEN];
948 gint args_left = MAX_ARGS_LEN - 1; /* for \0 */
949
950 args[0] = '\0';
951
952 /* Command */
953 strncat(args, "exec", args_left);
954 args_left = MAX_ARGS_LEN - strlen(args) - 1;
955
956 /* space */
957 strncat(args, " ", args_left);
958 args_left = MAX_ARGS_LEN - strlen(args) - 1;
959
960 if(strcmp(lttctl_path, "") == 0)
961 strncat(args, "lttctl", args_left);
962 else
963 strncat(args, lttctl_path, args_left);
964 args_left = MAX_ARGS_LEN - strlen(args) - 1;
965
966 /* space */
967 strncat(args, " ", args_left);
968 args_left = MAX_ARGS_LEN - strlen(args) - 1;
969
970 /* Simply unpause tracing */
971 strncat(args, "-s", args_left);
972 args_left = MAX_ARGS_LEN - strlen(args) - 1;
973
974 /* space */
975 strncat(args, " ", args_left);
976 args_left = MAX_ARGS_LEN - strlen(args) - 1;
977
978 /* name */
979 strncat(args, trace_name, args_left);
980 args_left = MAX_ARGS_LEN - strlen(args) - 1;
981
982 int retval = execute_command(args, username, password, lttd_path);
983 if(retval) {
984 gchar msg[256];
985 guint msg_left = 256;
986
987 strcpy(msg, "A problem occured when executing the su command : ");
988 msg_left = 256 - strlen(msg) - 1;
989 strncat(msg, strerror(retval), msg_left);
990 GtkWidget *dialogue =
991 gtk_message_dialog_new(
992 GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(button))),
993 GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
994 GTK_MESSAGE_ERROR,
995 GTK_BUTTONS_OK,
996 msg);
997 gtk_dialog_run(GTK_DIALOG(dialogue));
998 gtk_widget_destroy(dialogue);
999 }
1000
1001 }
1002
1003 void stop_clicked (GtkButton *button, gpointer user_data)
1004 {
1005 ControlData *tcd = (ControlData*)user_data;
1006
1007 const gchar *username = gtk_entry_get_text(GTK_ENTRY(tcd->username_entry));
1008 const gchar *password = gtk_entry_get_text(GTK_ENTRY(tcd->password_entry));
1009 const gchar *trace_name =
1010 gtk_entry_get_text(GTK_ENTRY(tcd->trace_name_entry));
1011 const gchar *lttd_path = "";
1012 const gchar *trace_mode;
1013 const gchar *trace_mode_sel;
1014 GtkTreeIter iter;
1015
1016 gtk_combo_box_get_active_iter(GTK_COMBO_BOX(tcd->trace_mode_combo), &iter);
1017 gtk_tree_model_get(
1018 gtk_combo_box_get_model(GTK_COMBO_BOX(tcd->trace_mode_combo)),
1019 &iter, 0, &trace_mode_sel, -1);
1020 if(strcmp(trace_mode_sel, "normal") == 0)
1021 trace_mode = "normal";
1022 else
1023 trace_mode = "flight";
1024
1025 const gchar *lttctl_path =
1026 gtk_entry_get_text(GTK_ENTRY(tcd->lttctl_path_entry));
1027 gchar *trace_dir = gtk_entry_get_text(GTK_ENTRY(tcd->trace_dir_entry));
1028 GSList * trace_list = NULL;
1029
1030 trace_list = g_slist_append(trace_list, trace_dir);
1031
1032 /* Setup arguments to su */
1033 /* child */
1034 gchar args[MAX_ARGS_LEN];
1035 gint args_left = MAX_ARGS_LEN - 1; /* for \0 */
1036
1037 args[0] = '\0';
1038
1039 /* Command */
1040 strncat(args, "exec", args_left);
1041 args_left = MAX_ARGS_LEN - strlen(args) - 1;
1042
1043 /* space */
1044 strncat(args, " ", args_left);
1045 args_left = MAX_ARGS_LEN - strlen(args) - 1;
1046
1047 if(strcmp(lttctl_path, "") == 0)
1048 strncat(args, "lttctl", args_left);
1049 else
1050 strncat(args, lttctl_path, args_left);
1051 args_left = MAX_ARGS_LEN - strlen(args) - 1;
1052
1053 /* space */
1054 strncat(args, " ", args_left);
1055 args_left = MAX_ARGS_LEN - strlen(args) - 1;
1056
1057 /* Simply stop tracing and destroy channel */
1058 strncat(args, "-D", args_left);
1059 args_left = MAX_ARGS_LEN - strlen(args) - 1;
1060
1061 if(strcmp(trace_mode, "flight") == 0) {
1062 /* space */
1063 strncat(args, " ", args_left);
1064 args_left = MAX_ARGS_LEN - strlen(args) - 1;
1065
1066 /* trace dir */
1067 strncat(args, "-w ", args_left);
1068 args_left = MAX_ARGS_LEN - strlen(args) - 1;
1069 strncat(args, trace_dir, args_left);
1070 args_left = MAX_ARGS_LEN - strlen(args) - 1;
1071 }
1072
1073 /* space */
1074 strncat(args, " ", args_left);
1075 args_left = MAX_ARGS_LEN - strlen(args) - 1;
1076
1077 /* name */
1078 strncat(args, trace_name, args_left);
1079 args_left = MAX_ARGS_LEN - strlen(args) - 1;
1080
1081 int retval = execute_command(args, username, password, lttd_path);
1082 if(retval) {
1083 gchar msg[256];
1084 guint msg_left = 256;
1085
1086 strcpy(msg, "A problem occured when executing the su command : ");
1087 msg_left = 256 - strlen(msg) - 1;
1088 strncat(msg, strerror(retval), msg_left);
1089 GtkWidget *dialogue =
1090 gtk_message_dialog_new(
1091 GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(button))),
1092 GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
1093 GTK_MESSAGE_ERROR,
1094 GTK_BUTTONS_OK,
1095 msg);
1096 gtk_dialog_run(GTK_DIALOG(dialogue));
1097 gtk_widget_destroy(dialogue);
1098 return;
1099 }
1100
1101
1102 /* Ask to the user if he wants to open the trace in a new window */
1103 GtkWidget *dialogue;
1104 GtkWidget *label;
1105 gint id;
1106
1107 dialogue = gtk_dialog_new_with_buttons("Open trace ?",
1108 GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(button))),
1109 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
1110 GTK_STOCK_YES,GTK_RESPONSE_ACCEPT,
1111 GTK_STOCK_NO,GTK_RESPONSE_REJECT,
1112 NULL);
1113 label = gtk_label_new("Do you want to open the trace in LTTV ?");
1114 gtk_widget_show(label);
1115
1116 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialogue)->vbox),
1117 label);
1118
1119 id = gtk_dialog_run(GTK_DIALOG(dialogue));
1120
1121 switch(id){
1122 case GTK_RESPONSE_ACCEPT:
1123 {
1124 create_main_window_with_trace_list(trace_list);
1125 }
1126 break;
1127 case GTK_RESPONSE_REJECT:
1128 default:
1129 break;
1130 }
1131 gtk_widget_destroy(dialogue);
1132 g_slist_free(trace_list);
1133 }
1134
1135 void arm_clicked (GtkButton *button, gpointer user_data)
1136 {
1137 ControlData *tcd = (ControlData*)user_data;
1138
1139 const gchar *username = gtk_entry_get_text(GTK_ENTRY(tcd->username_entry));
1140 const gchar *password = gtk_entry_get_text(GTK_ENTRY(tcd->password_entry));
1141 const gchar *ltt_armall_path =
1142 gtk_entry_get_text(GTK_ENTRY(tcd->ltt_armall_path_entry));
1143
1144 /* Setup arguments to su */
1145 /* child */
1146 gchar args[MAX_ARGS_LEN];
1147 gint args_left = MAX_ARGS_LEN - 1; /* for \0 */
1148
1149 args[0] = '\0';
1150
1151 /* Command */
1152 strncat(args, "exec", args_left);
1153 args_left = MAX_ARGS_LEN - strlen(args) - 1;
1154
1155 /* space */
1156 strncat(args, " ", args_left);
1157 args_left = MAX_ARGS_LEN - strlen(args) - 1;
1158
1159 if(strcmp(ltt_armall_path, "") == 0)
1160 strncat(args, "ltt-armall", args_left);
1161 else
1162 strncat(args, ltt_armall_path, args_left);
1163 args_left = MAX_ARGS_LEN - strlen(args) - 1;
1164
1165 int retval = execute_command(args, username, password, "");
1166 if(retval) {
1167 gchar msg[256];
1168 guint msg_left = 256;
1169
1170 strcpy(msg, "A problem occured when executing the su command : ");
1171 msg_left = 256 - strlen(msg) - 1;
1172 strncat(msg, strerror(retval), msg_left);
1173 GtkWidget *dialogue =
1174 gtk_message_dialog_new(
1175 GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(button))),
1176 GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
1177 GTK_MESSAGE_ERROR,
1178 GTK_BUTTONS_OK,
1179 msg);
1180 gtk_dialog_run(GTK_DIALOG(dialogue));
1181 gtk_widget_destroy(dialogue);
1182 }
1183
1184 }
1185
1186 void disarm_clicked (GtkButton *button, gpointer user_data)
1187 {
1188 ControlData *tcd = (ControlData*)user_data;
1189
1190 const gchar *username = gtk_entry_get_text(GTK_ENTRY(tcd->username_entry));
1191 const gchar *password = gtk_entry_get_text(GTK_ENTRY(tcd->password_entry));
1192 const gchar *ltt_disarmall_path =
1193 gtk_entry_get_text(GTK_ENTRY(tcd->ltt_disarmall_path_entry));
1194
1195 /* Setup arguments to su */
1196 /* child */
1197 gchar args[MAX_ARGS_LEN];
1198 gint args_left = MAX_ARGS_LEN - 1; /* for \0 */
1199
1200 args[0] = '\0';
1201
1202 /* Command */
1203 strncat(args, "exec", args_left);
1204 args_left = MAX_ARGS_LEN - strlen(args) - 1;
1205
1206 /* space */
1207 strncat(args, " ", args_left);
1208 args_left = MAX_ARGS_LEN - strlen(args) - 1;
1209
1210 if(strcmp(ltt_disarmall_path, "") == 0)
1211 strncat(args, "ltt-disarmall", args_left);
1212 else
1213 strncat(args, ltt_disarmall_path, args_left);
1214 args_left = MAX_ARGS_LEN - strlen(args) - 1;
1215
1216 int retval = execute_command(args, username, password, "");
1217 if(retval) {
1218 gchar msg[256];
1219 guint msg_left = 256;
1220
1221 strcpy(msg, "A problem occured when executing the su command : ");
1222 msg_left = 256 - strlen(msg) - 1;
1223 strncat(msg, strerror(retval), msg_left);
1224 GtkWidget *dialogue =
1225 gtk_message_dialog_new(
1226 GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(button))),
1227 GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
1228 GTK_MESSAGE_ERROR,
1229 GTK_BUTTONS_OK,
1230 msg);
1231 gtk_dialog_run(GTK_DIALOG(dialogue));
1232 gtk_widget_destroy(dialogue);
1233 }
1234
1235 }
1236
1237
1238 /**
1239 * @fn GtkWidget* h_guicontrol(Tab*)
1240 *
1241 * Control Module's constructor hook
1242 *
1243 * This constructor is given as a parameter to the menuitem and toolbar button
1244 * registration. It creates the list.
1245 * @param tab A pointer to the parent window.
1246 * @return The widget created.
1247 */
1248 GtkWidget *
1249 h_guicontrol(LttvPlugin *plugin)
1250 {
1251 LttvPluginTab *ptab = LTTV_PLUGIN_TAB(plugin);
1252 ControlData* f = gui_control(ptab);
1253
1254 return NULL;
1255 }
1256
1257 /**
1258 * @fn static void init()
1259 *
1260 * This function initializes the Filter Viewer functionnality through the
1261 * gtkTraceSet API.
1262 */
1263 static void init() {
1264
1265 lttvwindow_register_constructor("guicontrol",
1266 "/",
1267 "Insert Tracing Control Module",
1268 hTraceControlInsert_xpm,
1269 "Insert Tracing Control Module",
1270 h_guicontrol);
1271 }
1272
1273 /**
1274 * @fn void control_destroy_walk(gpointer,gpointer)
1275 *
1276 * Initiate the destruction of the current gui module
1277 * on the GTK Interface
1278 */
1279 void
1280 control_destroy_walk(gpointer data, gpointer user_data)
1281 {
1282 ControlData *tcd = (ControlData*)data;
1283
1284 g_debug("traceontrol.c : control_destroy_walk, %p", tcd);
1285
1286 /* May already have been done by GTK window closing */
1287 if(GTK_IS_WIDGET(guicontrol_get_widget(tcd)))
1288 gtk_widget_destroy(guicontrol_get_widget(tcd));
1289 }
1290
1291 /**
1292 * @fn static void destroy()
1293 * @brief plugin's destroy function
1294 *
1295 * This function releases the memory reserved by the module and unregisters
1296 * everything that has been registered in the gtkTraceSet API.
1297 */
1298 static void destroy() {
1299
1300 g_slist_foreach(g_control_list, control_destroy_walk, NULL );
1301
1302 lttvwindow_unregister_constructor(h_guicontrol);
1303
1304 }
1305
1306
1307 LTTV_MODULE("guitracecontrol", "Trace Control Window", \
1308 "Graphical module that let user control kernel tracing", \
1309 init, destroy, "lttvwindow")
1310
This page took 0.061846 seconds and 3 git commands to generate.