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