update trace control
[lttv.git] / trunk / lttv / lttv / modules / gui / tracecontrol / tracecontrol.c
CommitLineData
e7c8534e 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>
5e96e7e3 24#include <glib/gprintf.h>
e7c8534e 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>
e7c8534e 33
34#include <lttvwindow/lttvwindow.h>
35#include <lttvwindow/lttvwindowtraces.h>
5e96e7e3 36#include <lttvwindow/callbacks.h>
b154e818 37#include <lttvwindow/lttv_plugin_tab.h>
e7c8534e 38
39#include "hTraceControlInsert.xpm"
381229ee 40#include "TraceControlStart.xpm"
41#include "TraceControlPause.xpm"
42#include "TraceControlStop.xpm"
e7c8534e 43
77ef407f 44#include <sys/types.h>
45#include <unistd.h>
46#include <stdlib.h>
ff430216 47#include <pty.h>
48#include <utmp.h>
49#include <sys/wait.h>
86a65fdb 50#include <sys/poll.h>
6cec4cd2 51#include <errno.h>
b57800a3 52#include <fcntl.h>
53#include <sched.h>
77ef407f 54
f6f6abf0 55#define MAX_ARGS_LEN PATH_MAX * 10
e7c8534e 56
57GSList *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
67typedef struct _ControlData ControlData;
68
69/*
70 * Prototypes
71 */
72GtkWidget *guicontrol_get_widget(ControlData *tcd);
b154e818 73ControlData *gui_control(LttvPluginTab *ptab);
e7c8534e 74void gui_control_destructor(ControlData *tcd);
b154e818 75GtkWidget* h_guicontrol(LttvPlugin *plugin);
e7c8534e 76void control_destroy_walk(gpointer data, gpointer user_data);
77
78/*
79 * Callback functions
80 */
81
77ef407f 82static void start_clicked (GtkButton *button, gpointer user_data);
83static void pause_clicked (GtkButton *button, gpointer user_data);
45653836 84static void unpause_clicked (GtkButton *button, gpointer user_data);
77ef407f 85static void stop_clicked (GtkButton *button, gpointer user_data);
e7c8534e 86
ff430216 87
e7c8534e 88/**
89 * @struct _ControlData
90 *
77ef407f 91 * @brief Main structure of gui control
e7c8534e 92 */
93struct _ControlData {
94 Tab *tab; /**< current tab of module */
95
77ef407f 96 GtkWidget *window; /**< window */
e7c8534e 97
77ef407f 98 GtkWidget *main_box; /**< main container */
99 GtkWidget *start_button;
100 GtkWidget *pause_button;
45653836 101 GtkWidget *unpause_button;
77ef407f 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;
45653836 117 GtkWidget *append_label;
118 GtkWidget *append_check;
77ef407f 119 GtkWidget *optional_label;
120 GtkWidget *subbuf_size_label;
121 GtkWidget *subbuf_size_entry;
122 GtkWidget *subbuf_num_label;
123 GtkWidget *subbuf_num_entry;
e6542e85 124 GtkWidget *lttd_threads_label;
125 GtkWidget *lttd_threads_entry;
77ef407f 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;
e7c8534e 132};
133
134/**
135 * @fn GtkWidget* guicontrol_get_widget(ControlData*)
136 *
137 * This function returns the current main widget
138 * used by this module
139 * @param tcd the module struct
140 * @return The main widget
141 */
142GtkWidget*
143guicontrol_get_widget(ControlData *tcd)
144{
77ef407f 145 return tcd->window;
e7c8534e 146}
147
148/**
149 * @fn ControlData* gui_control(Tab*)
150 *
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.
154 */
155ControlData*
b154e818 156gui_control(LttvPluginTab *ptab)
e7c8534e 157{
b154e818 158 Tab *tab = ptab->tab;
e7c8534e 159 g_debug("filter::gui_control()");
160
161 unsigned i;
162 GtkCellRenderer *renderer;
163 GtkTreeViewColumn *column;
164
165 ControlData* tcd = g_new(ControlData,1);
166
167 tcd->tab = tab;
168
77ef407f 169 tcd->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
170 gtk_window_set_title(GTK_WINDOW(tcd->window), "LTTng Trace Control");
e7c8534e 171 /*
172 * Initiating GtkTable layout
173 * starts with 2 rows and 5 columns and
174 * expands when expressions added
175 */
77ef407f 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);
e7c8534e 179
77ef407f 180 gtk_container_add(GTK_CONTAINER(tcd->window), GTK_WIDGET(tcd->main_box));
e7c8534e 181
ff430216 182 GList *focus_chain = NULL;
183
381229ee 184 /*
185 * start/pause/stop buttons
186 */
187 GdkPixbuf *pixbuf;
188 GtkWidget *image;
189 pixbuf = gdk_pixbuf_new_from_xpm_data((const char **)TraceControlStart_xpm);
190 image = gtk_image_new_from_pixbuf(pixbuf);
77ef407f 191 tcd->start_button = gtk_button_new_with_label("start");
06e9af2d 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);
77ef407f 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);
381229ee 197
198 pixbuf = gdk_pixbuf_new_from_xpm_data((const char **)TraceControlPause_xpm);
199 image = gtk_image_new_from_pixbuf(pixbuf);
77ef407f 200 tcd->pause_button = gtk_button_new_with_label("pause");
06e9af2d 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);
77ef407f 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);
381229ee 206
45653836 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");
06e9af2d 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);
45653836 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);
215
381229ee 216 pixbuf = gdk_pixbuf_new_from_xpm_data((const char **)TraceControlStop_xpm);
217 image = gtk_image_new_from_pixbuf(pixbuf);
77ef407f 218 tcd->stop_button = gtk_button_new_with_label("stop");
06e9af2d 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);
77ef407f 221 gtk_button_set_alignment(GTK_BUTTON(tcd->stop_button), 0.0, 0.0);
222 gtk_widget_show (tcd->stop_button);
45653836 223 gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->stop_button,6,7,3,4,GTK_FILL,GTK_FILL,2,2);
381229ee 224
e7c8534e 225 /*
226 * First half of the filter window
227 * - textual entry of filter expression
228 * - processing button
229 */
77ef407f 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);
237
238
239
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);
247
248
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();
9c86b517 252 gtk_entry_set_text(GTK_ENTRY(tcd->channel_dir_entry),"/mnt/debugfs/ltt");
77ef407f 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);
256
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);
264
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);
272
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),
381229ee 277 "normal");
77ef407f 278 gtk_combo_box_append_text(GTK_COMBO_BOX(tcd->trace_mode_combo),
381229ee 279 "flight recorder");
77ef407f 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);
284
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);
45653836 292
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);
300
77ef407f 301
302 tcd->optional_label = gtk_label_new("Optional fields ");
303 gtk_widget_show (tcd->optional_label);
45653836 304 gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->optional_label,0,6,8,9,GTK_FILL,GTK_FILL,2,2);
77ef407f 305
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);
45653836 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);
77ef407f 312
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);
45653836 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);
77ef407f 319
e6542e85 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);
327
77ef407f 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();
ff430216 331 gtk_entry_set_text(GTK_ENTRY(tcd->lttctl_path_entry),PACKAGE_BIN_DIR "/lttctl");
77ef407f 332 gtk_widget_show (tcd->lttctl_path_entry);
e6542e85 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);
77ef407f 335
336
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();
ff430216 340 gtk_entry_set_text(GTK_ENTRY(tcd->lttd_path_entry),PACKAGE_BIN_DIR "/lttd");
77ef407f 341 gtk_widget_show (tcd->lttd_path_entry);
e6542e85 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);
381229ee 344
345
77ef407f 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();
c56a714e 349 gtk_entry_set_text(GTK_ENTRY(tcd->fac_path_entry),PACKAGE_DATA_DIR "/" "ltt-control" "/facilities");
77ef407f 350 gtk_widget_set_size_request(tcd->fac_path_entry, 250, -1);
351 gtk_widget_show (tcd->fac_path_entry);
e6542e85 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);
ff430216 354
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);
45653836 359 focus_chain = g_list_append (focus_chain, tcd->unpause_button);
ff430216 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);
45653836 366 focus_chain = g_list_append (focus_chain, tcd->append_check);
ff430216 367 focus_chain = g_list_append (focus_chain, tcd->subbuf_size_entry);
368 focus_chain = g_list_append (focus_chain, tcd->subbuf_num_entry);
e6542e85 369 focus_chain = g_list_append (focus_chain, tcd->lttd_threads_entry);
ff430216 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);
373
374 gtk_container_set_focus_chain(GTK_CONTAINER(tcd->main_box), focus_chain);
375
382e4b92 376 g_list_free(focus_chain);
377
77ef407f 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);
45653836 382 g_signal_connect(G_OBJECT(tcd->unpause_button), "clicked",
383 (GCallback)unpause_clicked, tcd);
77ef407f 384 g_signal_connect(G_OBJECT(tcd->stop_button), "clicked",
385 (GCallback)stop_clicked, tcd);
e7c8534e 386
387 /*
388 * show main container
389 */
77ef407f 390 gtk_widget_show(tcd->main_box);
391 gtk_widget_show(tcd->window);
e7c8534e 392
393
394 g_object_set_data_full(
77ef407f 395 G_OBJECT(guicontrol_get_widget(tcd)),
396 "control_viewer_data",
e7c8534e 397 tcd,
398 (GDestroyNotify)gui_control_destructor);
399
400 g_control_list = g_slist_append(
401 g_control_list,
402 tcd);
403
404 return tcd;
405}
406
407
408/**
409 * @fn void gui_control_destructor(ControlData*)
410 *
411 * Destructor for the filter gui module
412 * @param tcd The module structure
413 */
414void
415gui_control_destructor(ControlData *tcd)
416{
417 Tab *tab = tcd->tab;
418
419 /* May already been done by GTK window closing */
77ef407f 420 if(GTK_IS_WIDGET(guicontrol_get_widget(tcd))){
e7c8534e 421 g_info("widget still exists");
422 }
423// if(tab != NULL) {
424// lttvwindow_unregister_traceset_notify(tcd->tab,
425// filter_traceset_changed,
426// filter_viewer_data);
427// }
428 lttvwindowtraces_background_notify_remove(tcd);
429
430 g_control_list = g_slist_remove(g_control_list, tcd);
431
432 g_free(tcd);
433}
434
29e34d6c 435static int execute_command(const gchar *command, const gchar *username,
45653836 436 const gchar *password, const gchar *lttd_path, const gchar *fac_path)
77ef407f 437{
ff430216 438 pid_t pid;
439 int fdpty;
440 pid = forkpty(&fdpty, NULL, NULL, NULL);
29e34d6c 441 int retval = 0;
77ef407f 442
443 if(pid > 0) {
444 /* parent */
ff430216 445 gchar buf[256];
446 int status;
447 ssize_t count;
448 /* discuss with su */
449 struct timeval timeout;
450 timeout.tv_sec = 1;
451 timeout.tv_usec = 0;
ff430216 452
86a65fdb 453 struct pollfd pollfd;
454 int num_rdy;
455 int num_hup = 0;
b57800a3 456 enum read_state { GET_LINE, GET_SEMI, GET_SPACE } read_state = GET_LINE;
86a65fdb 457
b57800a3 458 retval = fcntl(fdpty, F_SETFL, O_WRONLY);
459 if(retval == -1) {
460 perror("Error in fcntl");
461 goto wait_child;
462 }
86a65fdb 463
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...");
467 while(1) {
468 pollfd.fd = fdpty;
75e2f396 469 pollfd.events = POLLIN|POLLPRI|POLLERR|POLLHUP|POLLNVAL;
86a65fdb 470
b57800a3 471 num_rdy = poll(&pollfd, 1, -1);
86a65fdb 472 if(num_rdy == -1) {
473 perror("Poll error");
474 goto wait_child;
475 }
86a65fdb 476
b57800a3 477 /* Timeout : Stop waiting for chars */
478 if(num_rdy == 0) goto wait_child;
86a65fdb 479
480 switch(pollfd.revents) {
481 case POLLERR:
482 g_warning("Error returned in polling fd\n");
483 num_hup++;
484 break;
485 case POLLHUP:
486 g_info("Polling FD : hung up.");
487 num_hup++;
488 break;
489 case POLLNVAL:
490 g_warning("Polling fd tells it is not open");
491 num_hup++;
492 break;
493 case POLLPRI:
494 case POLLIN:
495 count = read (fdpty, buf, 256);
496 if(count > 0) {
b57800a3 497 unsigned int i;
86a65fdb 498 buf[count] = '\0';
b57800a3 499 g_printf("%s", buf);
500 for(i=0; i<count; i++) {
501 switch(read_state) {
502 case GET_LINE:
503 if(buf[i] == '\n') {
504 read_state = GET_SEMI;
505 g_debug("Tracecontrol input line skip\n");
506 }
507 break;
508 case GET_SEMI:
509 if(buf[i] == ':') {
510 g_debug("Tracecontrol input : marker found\n");
511 read_state = GET_SPACE;
512 }
513 break;
514 case GET_SPACE:
515 if(buf[i] == ' ') {
516 g_debug("Tracecontrol input space marker found\n");
517 goto write_password;
518 }
519 break;
520 }
521 }
86a65fdb 522 } else if(count == -1) {
523 perror("Error in read");
524 goto wait_child;
525 }
526 break;
527 }
528 if(num_hup > 0) {
529 g_warning("Child hung up too fast");
530 goto wait_child;
531 }
532 }
b57800a3 533write_password:
534 fsync(fdpty);
535 pollfd.fd = fdpty;
536 pollfd.events = POLLOUT|POLLERR|POLLHUP|POLLNVAL;
537
538 num_rdy = poll(&pollfd, 1, -1);
539 if(num_rdy == -1) {
540 perror("Poll error");
541 goto wait_child;
542 }
543
86a65fdb 544 /* Write the password */
ff430216 545 g_info("Got su prompt, now writing password...");
ff430216 546 int ret;
b57800a3 547 sleep(1);
ff430216 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");
552 fsync(fdpty);
86a65fdb 553 /* Take the output from the terminal and show it on the real console */
554 g_info("Getting data from child terminal...");
555 while(1) {
556 int num_hup = 0;
557 pollfd.fd = fdpty;
75e2f396 558 pollfd.events = POLLIN|POLLPRI|POLLERR|POLLHUP|POLLNVAL;
86a65fdb 559
560 num_rdy = poll(&pollfd, 1, -1);
86a65fdb 561 if(num_rdy == -1) {
562 perror("Poll error");
563 goto wait_child;
564 }
86a65fdb 565 if(num_rdy == 0) break;
b57800a3 566
567 if(pollfd.revents & (POLLERR|POLLNVAL)) {
568 g_warning("Error returned in polling fd\n");
569 num_hup++;
570 }
571
572 if(pollfd.revents & (POLLIN|POLLPRI) ) {
573 count = read (fdpty, buf, 256);
574 if(count > 0) {
575 buf[count] = '\0';
576 printf("%s", buf);
577 } else if(count == -1) {
578 perror("Error in read");
579 goto wait_child;
580 }
581 }
582
583 if(pollfd.revents & POLLHUP) {
584 g_info("Polling FD : hung up.");
585 num_hup++;
586 }
86a65fdb 587
86a65fdb 588 if(num_hup > 0) goto wait_child;
589 }
590wait_child:
591 g_info("Waiting for child exit...");
592
593 ret = waitpid(pid, &status, 0);
6cec4cd2 594
595 if(ret == -1) {
596 g_warning("An error occured in wait : %s",
597 strerror(errno));
598 } else {
599 if(WIFEXITED(status))
600 if(WEXITSTATUS(status) != 0) {
601 retval = WEXITSTATUS(status);
602 g_warning("An error occured in the su command : %s",
603 strerror(retval));
604 }
605 }
77ef407f 606
86a65fdb 607 g_info("Child exited.");
77ef407f 608
609 } else if(pid == 0) {
f6f6abf0 610 /* Setup environment variables */
77ef407f 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);
f6f6abf0 615
b57800a3 616 /* One comment line (must be only one) */
617 g_printf("Executing (as %s) : %s\n", username, command);
ff430216 618
45653836 619 execlp("su", "su", "-p", "-c", command, username, NULL);
620 exit(-1); /* not supposed to happen! */
621
622 //gint ret = execvp();
623
624 } else {
625 /* error */
626 g_warning("Error happened when forking for su");
627 }
86a65fdb 628
29e34d6c 629 return retval;
45653836 630}
86a65fdb 631
86a65fdb 632
45653836 633/* Callbacks */
f6f6abf0 634
45653836 635void start_clicked (GtkButton *button, gpointer user_data)
636{
637 ControlData *tcd = (ControlData*)user_data;
f6f6abf0 638
45653836 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));
646
382e4b92 647 const gchar *trace_mode_sel;
648 GtkTreeIter iter;
649
650 gtk_combo_box_get_active_iter(GTK_COMBO_BOX(tcd->trace_mode_combo), &iter);
651 gtk_tree_model_get(
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));
45653836 656 const gchar *trace_mode;
657 if(strcmp(trace_mode_sel, "normal") == 0)
658 trace_mode = "normal";
659 else
660 trace_mode = "flight";
661
662 gboolean start_daemon =
663 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(tcd->start_daemon_check));
f6f6abf0 664
45653836 665 gboolean append =
666 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(tcd->append_check));
667
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));
e6542e85 672 const gchar *threads_num =
673 gtk_entry_get_text(GTK_ENTRY(tcd->lttd_threads_entry));
45653836 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));
678
679
680 /* Setup arguments to su */
681 /* child */
682 gchar args[MAX_ARGS_LEN];
683 gint args_left = MAX_ARGS_LEN - 1; /* for \0 */
684
685 args[0] = '\0';
686
687 /* Command */
688 strncat(args, "exec", args_left);
689 args_left = MAX_ARGS_LEN - strlen(args) - 1;
690
691 /* space */
692 strncat(args, " ", args_left);
693 args_left = MAX_ARGS_LEN - strlen(args) - 1;
694
695 if(strcmp(lttctl_path, "") == 0)
696 strncat(args, "lttctl", args_left);
697 else
698 strncat(args, lttctl_path, args_left);
699 args_left = MAX_ARGS_LEN - strlen(args) - 1;
700
701 /* space */
702 strncat(args, " ", args_left);
703 args_left = MAX_ARGS_LEN - strlen(args) - 1;
704
e908999c 705 /* Start daemon ? */
706 if(start_daemon) {
707 strncat(args, "-C", args_left);
708 args_left = MAX_ARGS_LEN - strlen(args) - 1;
709 } else {
710 /* Simply create the channel and then start tracing */
711 //strncat(args, "-b", args_left);
712 //args_left = MAX_ARGS_LEN - strlen(args) - 1;
713 }
45653836 714
715 /* space */
716 strncat(args, " ", args_left);
717 args_left = MAX_ARGS_LEN - strlen(args) - 1;
718
e908999c 719 /* channel dir */
720 strncat(args, "--channel_root ", args_left);
45653836 721 args_left = MAX_ARGS_LEN - strlen(args) - 1;
e908999c 722 strncat(args, channel_dir, args_left);
45653836 723 args_left = MAX_ARGS_LEN - strlen(args) - 1;
724
725 /* space */
726 strncat(args, " ", args_left);
727 args_left = MAX_ARGS_LEN - strlen(args) - 1;
728
e908999c 729 /* trace dir */
730 strncat(args, "-w ", args_left);
45653836 731 args_left = MAX_ARGS_LEN - strlen(args) - 1;
e908999c 732 strncat(args, trace_dir, args_left);
45653836 733 args_left = MAX_ARGS_LEN - strlen(args) - 1;
734
735 /* space */
736 strncat(args, " ", args_left);
737 args_left = MAX_ARGS_LEN - strlen(args) - 1;
738
e908999c 739 if(strcmp(trace_mode, "flight") == 0) {
740 strncat(args, "-o channel.all.overwrite=1", args_left);
f6f6abf0 741 args_left = MAX_ARGS_LEN - strlen(args) - 1;
45653836 742 } else {
e908999c 743 strncat(args, "-o channel.all.overwrite=0", args_left);
f6f6abf0 744 args_left = MAX_ARGS_LEN - strlen(args) - 1;
45653836 745 }
746
e908999c 747 /* trace mode */
748 strncat(args, "-m ", args_left);
749 args_left = MAX_ARGS_LEN - strlen(args) - 1;
750 strncat(args, trace_mode, args_left);
751 args_left = MAX_ARGS_LEN - strlen(args) - 1;
f6f6abf0 752
45653836 753 /* Append to trace ? */
754 if(append) {
f6f6abf0 755 /* space */
756 strncat(args, " ", args_left);
757 args_left = MAX_ARGS_LEN - strlen(args) - 1;
45653836 758 strncat(args, "-a", args_left);
f6f6abf0 759 args_left = MAX_ARGS_LEN - strlen(args) - 1;
45653836 760 }
761
762 /* optional arguments */
763 /* subbuffer size */
764 if(strcmp(subbuf_size, "") != 0) {
f6f6abf0 765 /* space */
766 strncat(args, " ", args_left);
767 args_left = MAX_ARGS_LEN - strlen(args) - 1;
768
e908999c 769 strncat(args, "-o channel.all.bufsize=", args_left);
f6f6abf0 770 args_left = MAX_ARGS_LEN - strlen(args) - 1;
45653836 771 strncat(args, subbuf_size, args_left);
f6f6abf0 772 args_left = MAX_ARGS_LEN - strlen(args) - 1;
45653836 773 }
f6f6abf0 774
45653836 775 /* number of subbuffers */
776 if(strcmp(subbuf_num, "") != 0) {
f6f6abf0 777 /* space */
778 strncat(args, " ", args_left);
779 args_left = MAX_ARGS_LEN - strlen(args) - 1;
780
e908999c 781 strncat(args, "-o channel.all.bufnum=", args_left);
45653836 782 args_left = MAX_ARGS_LEN - strlen(args) - 1;
783 strncat(args, subbuf_num, args_left);
784 args_left = MAX_ARGS_LEN - strlen(args) - 1;
785 }
ff430216 786
e6542e85 787 /* number of lttd threads */
788 if(strcmp(threads_num, "") != 0) {
789 /* space */
790 strncat(args, " ", args_left);
791 args_left = MAX_ARGS_LEN - strlen(args) - 1;
792
e908999c 793 strncat(args, "-n ", args_left);
e6542e85 794 args_left = MAX_ARGS_LEN - strlen(args) - 1;
795 strncat(args, threads_num, args_left);
796 args_left = MAX_ARGS_LEN - strlen(args) - 1;
797 }
798
e908999c 799 /* space */
800 strncat(args, " ", args_left);
801 args_left = MAX_ARGS_LEN - strlen(args) - 1;
77ef407f 802
e908999c 803 /* name */
804 strncat(args, trace_name, args_left);
805 args_left = MAX_ARGS_LEN - strlen(args) - 1;
806
29e34d6c 807 int retval = execute_command(args, username, password, lttd_path, fac_path);
808
809 if(retval) {
810 gchar msg[256];
811 guint msg_left = 256;
812
813 strcpy(msg, "A problem occured when executing the su command : ");
814 msg_left = 256 - strlen(msg) - 1;
815 strncat(msg, strerror(retval), msg_left);
816 GtkWidget *dialogue =
817 gtk_message_dialog_new(
818 GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(button))),
819 GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
820 GTK_MESSAGE_ERROR,
821 GTK_BUTTONS_OK,
822 msg);
823 gtk_dialog_run(GTK_DIALOG(dialogue));
824 gtk_widget_destroy(dialogue);
825 }
77ef407f 826
827}
828
829
830void pause_clicked (GtkButton *button, gpointer user_data)
831{
832 ControlData *tcd = (ControlData*)user_data;
833
45653836 834 const gchar *username = gtk_entry_get_text(GTK_ENTRY(tcd->username_entry));
835 const gchar *password = gtk_entry_get_text(GTK_ENTRY(tcd->password_entry));
836 const gchar *trace_name =
837 gtk_entry_get_text(GTK_ENTRY(tcd->trace_name_entry));
838 const gchar *lttd_path = "";
839 const gchar *fac_path = "";
840
841 const gchar *lttctl_path =
842 gtk_entry_get_text(GTK_ENTRY(tcd->lttctl_path_entry));
77ef407f 843
45653836 844 /* Setup arguments to su */
845 /* child */
846 gchar args[MAX_ARGS_LEN];
847 gint args_left = MAX_ARGS_LEN - 1; /* for \0 */
848
849 args[0] = '\0';
850
851 /* Command */
852 strncat(args, "exec", args_left);
853 args_left = MAX_ARGS_LEN - strlen(args) - 1;
854
855 /* space */
856 strncat(args, " ", args_left);
857 args_left = MAX_ARGS_LEN - strlen(args) - 1;
858
859 if(strcmp(lttctl_path, "") == 0)
860 strncat(args, "lttctl", args_left);
861 else
862 strncat(args, lttctl_path, args_left);
863 args_left = MAX_ARGS_LEN - strlen(args) - 1;
864
e908999c 865 /* space */
45653836 866 strncat(args, " ", args_left);
867 args_left = MAX_ARGS_LEN - strlen(args) - 1;
e908999c 868
869 /* Simply pause tracing */
870 strncat(args, "-p", args_left);
45653836 871 args_left = MAX_ARGS_LEN - strlen(args) - 1;
872
873 /* space */
874 strncat(args, " ", args_left);
875 args_left = MAX_ARGS_LEN - strlen(args) - 1;
e908999c 876
877 /* name */
878 strncat(args, trace_name, args_left);
45653836 879 args_left = MAX_ARGS_LEN - strlen(args) - 1;
880
29e34d6c 881 int retval = execute_command(args, username, password, lttd_path, fac_path);
882 if(retval) {
883 gchar msg[256];
884 guint msg_left = 256;
885
886 strcpy(msg, "A problem occured when executing the su command : ");
887 msg_left = 256 - strlen(msg) - 1;
888 strncat(msg, strerror(retval), msg_left);
889 GtkWidget *dialogue =
890 gtk_message_dialog_new(
891 GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(button))),
892 GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
893 GTK_MESSAGE_ERROR,
894 GTK_BUTTONS_OK,
895 msg);
896 gtk_dialog_run(GTK_DIALOG(dialogue));
897 gtk_widget_destroy(dialogue);
898 }
899
45653836 900}
901
902void unpause_clicked (GtkButton *button, gpointer user_data)
903{
904 ControlData *tcd = (ControlData*)user_data;
905
906 const gchar *username = gtk_entry_get_text(GTK_ENTRY(tcd->username_entry));
907 const gchar *password = gtk_entry_get_text(GTK_ENTRY(tcd->password_entry));
908 const gchar *trace_name =
909 gtk_entry_get_text(GTK_ENTRY(tcd->trace_name_entry));
910 const gchar *lttd_path = "";
911 const gchar *fac_path = "";
912
913 const gchar *lttctl_path =
914 gtk_entry_get_text(GTK_ENTRY(tcd->lttctl_path_entry));
915
916 /* Setup arguments to su */
917 /* child */
918 gchar args[MAX_ARGS_LEN];
919 gint args_left = MAX_ARGS_LEN - 1; /* for \0 */
920
921 args[0] = '\0';
922
923 /* Command */
924 strncat(args, "exec", args_left);
925 args_left = MAX_ARGS_LEN - strlen(args) - 1;
926
927 /* space */
928 strncat(args, " ", args_left);
929 args_left = MAX_ARGS_LEN - strlen(args) - 1;
930
931 if(strcmp(lttctl_path, "") == 0)
932 strncat(args, "lttctl", args_left);
933 else
934 strncat(args, lttctl_path, args_left);
935 args_left = MAX_ARGS_LEN - strlen(args) - 1;
936
937 /* space */
938 strncat(args, " ", args_left);
939 args_left = MAX_ARGS_LEN - strlen(args) - 1;
e908999c 940
941 /* Simply unpause tracing */
942 strncat(args, "-s", args_left);
45653836 943 args_left = MAX_ARGS_LEN - strlen(args) - 1;
944
945 /* space */
946 strncat(args, " ", args_left);
947 args_left = MAX_ARGS_LEN - strlen(args) - 1;
e908999c 948
949 /* name */
950 strncat(args, trace_name, args_left);
45653836 951 args_left = MAX_ARGS_LEN - strlen(args) - 1;
952
29e34d6c 953 int retval = execute_command(args, username, password, lttd_path, fac_path);
954 if(retval) {
955 gchar msg[256];
956 guint msg_left = 256;
957
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,
965 GTK_MESSAGE_ERROR,
966 GTK_BUTTONS_OK,
967 msg);
968 gtk_dialog_run(GTK_DIALOG(dialogue));
969 gtk_widget_destroy(dialogue);
970 }
971
77ef407f 972}
973
974void stop_clicked (GtkButton *button, gpointer user_data)
975{
976 ControlData *tcd = (ControlData*)user_data;
977
45653836 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 = "";
984
985 const gchar *lttctl_path =
986 gtk_entry_get_text(GTK_ENTRY(tcd->lttctl_path_entry));
b154e818 987 gchar *trace_dir = gtk_entry_get_text(GTK_ENTRY(tcd->trace_dir_entry));
988 GSList * trace_list = NULL;
989
990 trace_list = g_slist_append(trace_list, trace_dir);
45653836 991
992 /* Setup arguments to su */
993 /* child */
994 gchar args[MAX_ARGS_LEN];
995 gint args_left = MAX_ARGS_LEN - 1; /* for \0 */
996
997 args[0] = '\0';
998
999 /* Command */
1000 strncat(args, "exec", args_left);
1001 args_left = MAX_ARGS_LEN - strlen(args) - 1;
1002
1003 /* space */
1004 strncat(args, " ", args_left);
1005 args_left = MAX_ARGS_LEN - strlen(args) - 1;
1006
1007 if(strcmp(lttctl_path, "") == 0)
1008 strncat(args, "lttctl", args_left);
1009 else
1010 strncat(args, lttctl_path, args_left);
1011 args_left = MAX_ARGS_LEN - strlen(args) - 1;
1012
1013 /* space */
1014 strncat(args, " ", args_left);
1015 args_left = MAX_ARGS_LEN - strlen(args) - 1;
e908999c 1016
1017 /* Simply stop tracing and destroy channel */
1018 strncat(args, "-D", args_left);
45653836 1019 args_left = MAX_ARGS_LEN - strlen(args) - 1;
1020
e908999c 1021 if(strcmp(trace_mode, "flight") == 0) {
1022 /* space */
1023 strncat(args, " ", args_left);
1024 args_left = MAX_ARGS_LEN - strlen(args) - 1;
1025
1026 /* trace dir */
1027 strncat(args, "-w ", args_left);
1028 args_left = MAX_ARGS_LEN - strlen(args) - 1;
1029 strncat(args, trace_dir, args_left);
1030 args_left = MAX_ARGS_LEN - strlen(args) - 1;
1031 }
1032
45653836 1033 /* space */
1034 strncat(args, " ", args_left);
1035 args_left = MAX_ARGS_LEN - strlen(args) - 1;
e908999c 1036
1037 /* name */
1038 strncat(args, trace_name, args_left);
45653836 1039 args_left = MAX_ARGS_LEN - strlen(args) - 1;
1040
29e34d6c 1041 int retval = execute_command(args, username, password, lttd_path, fac_path);
1042 if(retval) {
1043 gchar msg[256];
1044 guint msg_left = 256;
1045
1046 strcpy(msg, "A problem occured when executing the su command : ");
1047 msg_left = 256 - strlen(msg) - 1;
1048 strncat(msg, strerror(retval), msg_left);
1049 GtkWidget *dialogue =
1050 gtk_message_dialog_new(
1051 GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(button))),
1052 GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
1053 GTK_MESSAGE_ERROR,
1054 GTK_BUTTONS_OK,
1055 msg);
1056 gtk_dialog_run(GTK_DIALOG(dialogue));
1057 gtk_widget_destroy(dialogue);
1058 return;
1059 }
1060
77ef407f 1061
8321ae6a 1062 /* Ask to the user if he wants to open the trace in a new window */
1063 GtkWidget *dialogue;
1064 GtkWidget *label;
1065 gint id;
1066
1067 dialogue = gtk_dialog_new_with_buttons("Open trace ?",
1068 GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(button))),
1069 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
1070 GTK_STOCK_YES,GTK_RESPONSE_ACCEPT,
1071 GTK_STOCK_NO,GTK_RESPONSE_REJECT,
1072 NULL);
1073 label = gtk_label_new("Do you want to open the trace in LTTV ?");
1074 gtk_widget_show(label);
1075
1076 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialogue)->vbox),
1077 label);
1078
1079 id = gtk_dialog_run(GTK_DIALOG(dialogue));
1080
1081 switch(id){
1082 case GTK_RESPONSE_ACCEPT:
1083 {
b154e818 1084 create_main_window_with_trace_list(trace_list);
8321ae6a 1085 }
1086 break;
1087 case GTK_RESPONSE_REJECT:
1088 default:
1089 break;
1090 }
1091 gtk_widget_destroy(dialogue);
b154e818 1092 g_slist_free(trace_list);
77ef407f 1093}
1094
e7c8534e 1095
1096/**
1097 * @fn GtkWidget* h_guicontrol(Tab*)
1098 *
1099 * Control Module's constructor hook
1100 *
1101 * This constructor is given as a parameter to the menuitem and toolbar button
1102 * registration. It creates the list.
1103 * @param tab A pointer to the parent window.
1104 * @return The widget created.
1105 */
1106GtkWidget *
b154e818 1107h_guicontrol(LttvPlugin *plugin)
e7c8534e 1108{
b154e818 1109 LttvPluginTab *ptab = LTTV_PLUGIN_TAB(plugin);
1110 ControlData* f = gui_control(ptab);
e7c8534e 1111
1112 return NULL;
1113}
1114
1115/**
1116 * @fn static void init()
1117 *
1118 * This function initializes the Filter Viewer functionnality through the
1119 * gtkTraceSet API.
1120 */
1121static void init() {
1122
1123 lttvwindow_register_constructor("guicontrol",
1124 "/",
1125 "Insert Tracing Control Module",
1126 hTraceControlInsert_xpm,
1127 "Insert Tracing Control Module",
1128 h_guicontrol);
1129}
1130
1131/**
1132 * @fn void control_destroy_walk(gpointer,gpointer)
1133 *
1134 * Initiate the destruction of the current gui module
1135 * on the GTK Interface
1136 */
1137void
1138control_destroy_walk(gpointer data, gpointer user_data)
1139{
1140 ControlData *tcd = (ControlData*)data;
1141
1142 g_debug("traceontrol.c : control_destroy_walk, %p", tcd);
1143
1144 /* May already have been done by GTK window closing */
1145 if(GTK_IS_WIDGET(guicontrol_get_widget(tcd)))
1146 gtk_widget_destroy(guicontrol_get_widget(tcd));
1147}
1148
1149/**
1150 * @fn static void destroy()
1151 * @brief plugin's destroy function
1152 *
1153 * This function releases the memory reserved by the module and unregisters
1154 * everything that has been registered in the gtkTraceSet API.
1155 */
1156static void destroy() {
1157
1158 g_slist_foreach(g_control_list, control_destroy_walk, NULL );
1159
1160 lttvwindow_unregister_constructor(h_guicontrol);
1161
1162}
1163
1164
1165LTTV_MODULE("guitracecontrol", "Trace Control Window", \
1166 "Graphical module that let user control kernel tracing", \
1167 init, destroy, "lttvwindow")
1168
This page took 0.093885 seconds and 4 git commands to generate.