| 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 <string.h> |
| 25 | #include <gtk/gtk.h> |
| 26 | #include <gdk/gdk.h> |
| 27 | #include <gdk/gdkkeysyms.h> |
| 28 | |
| 29 | #include <lttv/lttv.h> |
| 30 | #include <lttv/module.h> |
| 31 | #include <lttv/hook.h> |
| 32 | |
| 33 | #include <lttvwindow/lttvwindow.h> |
| 34 | #include <lttvwindow/lttvwindowtraces.h> |
| 35 | |
| 36 | #include "hTraceControlInsert.xpm" |
| 37 | #include "TraceControlStart.xpm" |
| 38 | #include "TraceControlPause.xpm" |
| 39 | #include "TraceControlStop.xpm" |
| 40 | |
| 41 | #include <sys/types.h> |
| 42 | #include <unistd.h> |
| 43 | #include <stdlib.h> |
| 44 | #include <pty.h> |
| 45 | #include <utmp.h> |
| 46 | #include <sys/wait.h> |
| 47 | #include <sys/select.h> |
| 48 | |
| 49 | #define MAX_ARGS_LEN PATH_MAX * 10 |
| 50 | |
| 51 | GSList *g_control_list = NULL ; |
| 52 | |
| 53 | /*! \file lttv/modules/gui/tracecontrol/tracecontrol.c |
| 54 | * \brief Graphic trace start/stop control interface. |
| 55 | * |
| 56 | * This plugin interacts with lttctl to start/stop tracing. It needs to take the |
| 57 | * root password to be able to interact with lttctl. |
| 58 | * |
| 59 | */ |
| 60 | |
| 61 | typedef struct _ControlData ControlData; |
| 62 | |
| 63 | /* |
| 64 | * Prototypes |
| 65 | */ |
| 66 | GtkWidget *guicontrol_get_widget(ControlData *tcd); |
| 67 | ControlData *gui_control(Tab *tab); |
| 68 | void gui_control_destructor(ControlData *tcd); |
| 69 | GtkWidget* h_guicontrol(Tab *tab); |
| 70 | void control_destroy_walk(gpointer data, gpointer user_data); |
| 71 | |
| 72 | /* |
| 73 | * Callback functions |
| 74 | */ |
| 75 | |
| 76 | static void start_clicked (GtkButton *button, gpointer user_data); |
| 77 | static void pause_clicked (GtkButton *button, gpointer user_data); |
| 78 | static void stop_clicked (GtkButton *button, gpointer user_data); |
| 79 | |
| 80 | |
| 81 | /** |
| 82 | * @struct _ControlData |
| 83 | * |
| 84 | * @brief Main structure of gui control |
| 85 | */ |
| 86 | struct _ControlData { |
| 87 | Tab *tab; /**< current tab of module */ |
| 88 | |
| 89 | GtkWidget *window; /**< window */ |
| 90 | |
| 91 | GtkWidget *main_box; /**< main container */ |
| 92 | GtkWidget *start_button; |
| 93 | GtkWidget *pause_button; |
| 94 | GtkWidget *stop_button; |
| 95 | GtkWidget *username_label; |
| 96 | GtkWidget *username_entry; |
| 97 | GtkWidget *password_label; |
| 98 | GtkWidget *password_entry; |
| 99 | GtkWidget *channel_dir_label; |
| 100 | GtkWidget *channel_dir_entry; |
| 101 | GtkWidget *trace_dir_label; |
| 102 | GtkWidget *trace_dir_entry; |
| 103 | GtkWidget *trace_name_label; |
| 104 | GtkWidget *trace_name_entry; |
| 105 | GtkWidget *trace_mode_label; |
| 106 | GtkWidget *trace_mode_combo; |
| 107 | GtkWidget *start_daemon_label; |
| 108 | GtkWidget *start_daemon_check; |
| 109 | GtkWidget *optional_label; |
| 110 | GtkWidget *subbuf_size_label; |
| 111 | GtkWidget *subbuf_size_entry; |
| 112 | GtkWidget *subbuf_num_label; |
| 113 | GtkWidget *subbuf_num_entry; |
| 114 | GtkWidget *lttctl_path_label; |
| 115 | GtkWidget *lttctl_path_entry; |
| 116 | GtkWidget *lttd_path_label; |
| 117 | GtkWidget *lttd_path_entry; |
| 118 | GtkWidget *fac_path_label; |
| 119 | GtkWidget *fac_path_entry; |
| 120 | }; |
| 121 | |
| 122 | /** |
| 123 | * @fn GtkWidget* guicontrol_get_widget(ControlData*) |
| 124 | * |
| 125 | * This function returns the current main widget |
| 126 | * used by this module |
| 127 | * @param tcd the module struct |
| 128 | * @return The main widget |
| 129 | */ |
| 130 | GtkWidget* |
| 131 | guicontrol_get_widget(ControlData *tcd) |
| 132 | { |
| 133 | return tcd->window; |
| 134 | } |
| 135 | |
| 136 | /** |
| 137 | * @fn ControlData* gui_control(Tab*) |
| 138 | * |
| 139 | * Constructor is used to create ControlData data structure. |
| 140 | * @param tab The tab structure used by the widget |
| 141 | * @return The Filter viewer data created. |
| 142 | */ |
| 143 | ControlData* |
| 144 | gui_control(Tab *tab) |
| 145 | { |
| 146 | g_debug("filter::gui_control()"); |
| 147 | |
| 148 | unsigned i; |
| 149 | GtkCellRenderer *renderer; |
| 150 | GtkTreeViewColumn *column; |
| 151 | |
| 152 | ControlData* tcd = g_new(ControlData,1); |
| 153 | |
| 154 | tcd->tab = tab; |
| 155 | |
| 156 | tcd->window = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
| 157 | gtk_window_set_title(GTK_WINDOW(tcd->window), "LTTng Trace Control"); |
| 158 | /* |
| 159 | * Initiating GtkTable layout |
| 160 | * starts with 2 rows and 5 columns and |
| 161 | * expands when expressions added |
| 162 | */ |
| 163 | tcd->main_box = gtk_table_new(14,7,FALSE); |
| 164 | gtk_table_set_row_spacings(GTK_TABLE(tcd->main_box),5); |
| 165 | gtk_table_set_col_spacings(GTK_TABLE(tcd->main_box),5); |
| 166 | |
| 167 | gtk_container_add(GTK_CONTAINER(tcd->window), GTK_WIDGET(tcd->main_box)); |
| 168 | |
| 169 | GList *focus_chain = NULL; |
| 170 | |
| 171 | /* |
| 172 | * start/pause/stop buttons |
| 173 | */ |
| 174 | GdkPixbuf *pixbuf; |
| 175 | GtkWidget *image; |
| 176 | pixbuf = gdk_pixbuf_new_from_xpm_data((const char **)TraceControlStart_xpm); |
| 177 | image = gtk_image_new_from_pixbuf(pixbuf); |
| 178 | tcd->start_button = gtk_button_new_with_label("start"); |
| 179 | gtk_button_set_image(GTK_BUTTON(tcd->start_button), image); |
| 180 | gtk_button_set_alignment(GTK_BUTTON(tcd->start_button), 0.0, 0.0); |
| 181 | gtk_widget_show (tcd->start_button); |
| 182 | gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->start_button,6,7,0,1,GTK_FILL,GTK_FILL,2,2); |
| 183 | |
| 184 | pixbuf = gdk_pixbuf_new_from_xpm_data((const char **)TraceControlPause_xpm); |
| 185 | image = gtk_image_new_from_pixbuf(pixbuf); |
| 186 | tcd->pause_button = gtk_button_new_with_label("pause"); |
| 187 | gtk_button_set_image(GTK_BUTTON(tcd->pause_button), image); |
| 188 | gtk_button_set_alignment(GTK_BUTTON(tcd->pause_button), 0.0, 0.0); |
| 189 | gtk_widget_show (tcd->pause_button); |
| 190 | gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->pause_button,6,7,1,2,GTK_FILL,GTK_FILL,2,2); |
| 191 | |
| 192 | pixbuf = gdk_pixbuf_new_from_xpm_data((const char **)TraceControlStop_xpm); |
| 193 | image = gtk_image_new_from_pixbuf(pixbuf); |
| 194 | tcd->stop_button = gtk_button_new_with_label("stop"); |
| 195 | gtk_button_set_image(GTK_BUTTON(tcd->stop_button), image); |
| 196 | gtk_button_set_alignment(GTK_BUTTON(tcd->stop_button), 0.0, 0.0); |
| 197 | gtk_widget_show (tcd->stop_button); |
| 198 | gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->stop_button,6,7,2,3,GTK_FILL,GTK_FILL,2,2); |
| 199 | |
| 200 | /* |
| 201 | * First half of the filter window |
| 202 | * - textual entry of filter expression |
| 203 | * - processing button |
| 204 | */ |
| 205 | tcd->username_label = gtk_label_new("Username:"); |
| 206 | gtk_widget_show (tcd->username_label); |
| 207 | tcd->username_entry = gtk_entry_new(); |
| 208 | gtk_entry_set_text(GTK_ENTRY(tcd->username_entry),"root"); |
| 209 | gtk_widget_show (tcd->username_entry); |
| 210 | gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->username_label,0,2,0,1,GTK_FILL,GTK_FILL,2,2); |
| 211 | 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); |
| 212 | |
| 213 | |
| 214 | |
| 215 | tcd->password_label = gtk_label_new("Password:"); |
| 216 | gtk_widget_show (tcd->password_label); |
| 217 | tcd->password_entry = gtk_entry_new(); |
| 218 | gtk_entry_set_visibility(GTK_ENTRY(tcd->password_entry), FALSE); |
| 219 | gtk_widget_show (tcd->password_entry); |
| 220 | gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->password_label,0,2,1,2,GTK_FILL,GTK_FILL,2,2); |
| 221 | 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); |
| 222 | |
| 223 | |
| 224 | tcd->channel_dir_label = gtk_label_new("Channel directory:"); |
| 225 | gtk_widget_show (tcd->channel_dir_label); |
| 226 | tcd->channel_dir_entry = gtk_entry_new(); |
| 227 | gtk_entry_set_text(GTK_ENTRY(tcd->channel_dir_entry),"/mnt/relayfs/ltt"); |
| 228 | gtk_widget_show (tcd->channel_dir_entry); |
| 229 | gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->channel_dir_label,0,2,2,3,GTK_FILL,GTK_FILL,2,2); |
| 230 | 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); |
| 231 | |
| 232 | tcd->trace_dir_label = gtk_label_new("Trace directory:"); |
| 233 | gtk_widget_show (tcd->trace_dir_label); |
| 234 | tcd->trace_dir_entry = gtk_entry_new(); |
| 235 | gtk_entry_set_text(GTK_ENTRY(tcd->trace_dir_entry),"/tmp/trace1"); |
| 236 | gtk_widget_show (tcd->trace_dir_entry); |
| 237 | gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->trace_dir_label,0,2,3,4,GTK_FILL,GTK_FILL,2,2); |
| 238 | 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); |
| 239 | |
| 240 | tcd->trace_name_label = gtk_label_new("Trace name:"); |
| 241 | gtk_widget_show (tcd->trace_name_label); |
| 242 | tcd->trace_name_entry = gtk_entry_new(); |
| 243 | gtk_entry_set_text(GTK_ENTRY(tcd->trace_name_entry),"trace"); |
| 244 | gtk_widget_show (tcd->trace_name_entry); |
| 245 | gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->trace_name_label,0,2,4,5,GTK_FILL,GTK_FILL,2,2); |
| 246 | 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); |
| 247 | |
| 248 | tcd->trace_mode_label = gtk_label_new("Trace mode "); |
| 249 | gtk_widget_show (tcd->trace_mode_label); |
| 250 | tcd->trace_mode_combo = gtk_combo_box_new_text(); |
| 251 | gtk_combo_box_append_text(GTK_COMBO_BOX(tcd->trace_mode_combo), |
| 252 | "normal"); |
| 253 | gtk_combo_box_append_text(GTK_COMBO_BOX(tcd->trace_mode_combo), |
| 254 | "flight recorder"); |
| 255 | gtk_combo_box_set_active(GTK_COMBO_BOX(tcd->trace_mode_combo), 0); |
| 256 | gtk_widget_show (tcd->trace_mode_combo); |
| 257 | gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->trace_mode_label,0,2,5,6,GTK_FILL,GTK_FILL,2,2); |
| 258 | 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); |
| 259 | |
| 260 | tcd->start_daemon_label = gtk_label_new("Start daemon "); |
| 261 | gtk_widget_show (tcd->start_daemon_label); |
| 262 | tcd->start_daemon_check = gtk_check_button_new(); |
| 263 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(tcd->start_daemon_check), TRUE); |
| 264 | gtk_widget_show (tcd->start_daemon_check); |
| 265 | gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->start_daemon_label,0,2,6,7,GTK_FILL,GTK_FILL,2,2); |
| 266 | gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->start_daemon_check,2,6,6,7,GTK_FILL,GTK_FILL,0,0); |
| 267 | |
| 268 | tcd->optional_label = gtk_label_new("Optional fields "); |
| 269 | gtk_widget_show (tcd->optional_label); |
| 270 | gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->optional_label,0,6,7,8,GTK_FILL,GTK_FILL,2,2); |
| 271 | |
| 272 | tcd->subbuf_size_label = gtk_label_new("Subbuffer size:"); |
| 273 | gtk_widget_show (tcd->subbuf_size_label); |
| 274 | tcd->subbuf_size_entry = gtk_entry_new(); |
| 275 | gtk_widget_show (tcd->subbuf_size_entry); |
| 276 | gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->subbuf_size_label,0,2,8,9,GTK_FILL,GTK_FILL,2,2); |
| 277 | gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->subbuf_size_entry,2,6,8,9,GTK_FILL|GTK_EXPAND|GTK_SHRINK,GTK_FILL,0,0); |
| 278 | |
| 279 | tcd->subbuf_num_label = gtk_label_new("Number of subbuffers:"); |
| 280 | gtk_widget_show (tcd->subbuf_num_label); |
| 281 | tcd->subbuf_num_entry = gtk_entry_new(); |
| 282 | gtk_widget_show (tcd->subbuf_num_entry); |
| 283 | gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->subbuf_num_label,0,2,9,10,GTK_FILL,GTK_FILL,2,2); |
| 284 | gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->subbuf_num_entry,2,6,9,10,GTK_FILL|GTK_EXPAND|GTK_SHRINK,GTK_FILL,0,0); |
| 285 | |
| 286 | tcd->lttctl_path_label = gtk_label_new("path to lttctl:"); |
| 287 | gtk_widget_show (tcd->lttctl_path_label); |
| 288 | tcd->lttctl_path_entry = gtk_entry_new(); |
| 289 | gtk_entry_set_text(GTK_ENTRY(tcd->lttctl_path_entry),PACKAGE_BIN_DIR "/lttctl"); |
| 290 | gtk_widget_show (tcd->lttctl_path_entry); |
| 291 | gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->lttctl_path_label,0,2,10,11,GTK_FILL,GTK_FILL,2,2); |
| 292 | gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->lttctl_path_entry,2,6,10,11,GTK_FILL|GTK_EXPAND|GTK_SHRINK,GTK_FILL,0,0); |
| 293 | |
| 294 | |
| 295 | tcd->lttd_path_label = gtk_label_new("path to lttd:"); |
| 296 | gtk_widget_show (tcd->lttd_path_label); |
| 297 | tcd->lttd_path_entry = gtk_entry_new(); |
| 298 | gtk_entry_set_text(GTK_ENTRY(tcd->lttd_path_entry),PACKAGE_BIN_DIR "/lttd"); |
| 299 | gtk_widget_show (tcd->lttd_path_entry); |
| 300 | gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->lttd_path_label,0,2,11,12,GTK_FILL,GTK_FILL,2,2); |
| 301 | gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->lttd_path_entry,2,6,11,12,GTK_FILL|GTK_EXPAND|GTK_SHRINK,GTK_FILL,0,0); |
| 302 | |
| 303 | |
| 304 | tcd->fac_path_label = gtk_label_new("path to facilities:"); |
| 305 | gtk_widget_show (tcd->fac_path_label); |
| 306 | tcd->fac_path_entry = gtk_entry_new(); |
| 307 | gtk_entry_set_text(GTK_ENTRY(tcd->fac_path_entry),PACKAGE_DATA_DIR "/facilities"); |
| 308 | gtk_widget_set_size_request(tcd->fac_path_entry, 250, -1); |
| 309 | gtk_widget_show (tcd->fac_path_entry); |
| 310 | gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->fac_path_label,0,2,12,13,GTK_FILL,GTK_FILL,2,2); |
| 311 | gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->fac_path_entry,2,6,12,13,GTK_FILL|GTK_EXPAND|GTK_SHRINK,GTK_FILL,0,0); |
| 312 | |
| 313 | |
| 314 | GtkWidget *start_button; |
| 315 | GtkWidget *pause_button; |
| 316 | GtkWidget *stop_button; |
| 317 | |
| 318 | GtkWidget *username_entry; |
| 319 | GtkWidget *password_entry; |
| 320 | GtkWidget *channel_dir_entry; |
| 321 | GtkWidget *trace_dir_entry; |
| 322 | GtkWidget *trace_name_entry; |
| 323 | GtkWidget *trace_mode_combo; |
| 324 | GtkWidget *start_daemon_check; |
| 325 | GtkWidget *subbuf_size_entry; |
| 326 | GtkWidget *subbuf_num_entry; |
| 327 | GtkWidget *lttctl_path_entry; |
| 328 | GtkWidget *lttd_path_entry; |
| 329 | GtkWidget *fac_path_entry; |
| 330 | |
| 331 | focus_chain = g_list_append (focus_chain, tcd->username_entry); |
| 332 | focus_chain = g_list_append (focus_chain, tcd->password_entry); |
| 333 | focus_chain = g_list_append (focus_chain, tcd->start_button); |
| 334 | focus_chain = g_list_append (focus_chain, tcd->pause_button); |
| 335 | focus_chain = g_list_append (focus_chain, tcd->stop_button); |
| 336 | focus_chain = g_list_append (focus_chain, tcd->channel_dir_entry); |
| 337 | focus_chain = g_list_append (focus_chain, tcd->trace_dir_entry); |
| 338 | focus_chain = g_list_append (focus_chain, tcd->trace_name_entry); |
| 339 | focus_chain = g_list_append (focus_chain, tcd->trace_mode_combo); |
| 340 | focus_chain = g_list_append (focus_chain, tcd->start_daemon_check); |
| 341 | focus_chain = g_list_append (focus_chain, tcd->subbuf_size_entry); |
| 342 | focus_chain = g_list_append (focus_chain, tcd->subbuf_num_entry); |
| 343 | focus_chain = g_list_append (focus_chain, tcd->lttctl_path_entry); |
| 344 | focus_chain = g_list_append (focus_chain, tcd->lttd_path_entry); |
| 345 | focus_chain = g_list_append (focus_chain, tcd->fac_path_entry); |
| 346 | |
| 347 | gtk_container_set_focus_chain(GTK_CONTAINER(tcd->main_box), focus_chain); |
| 348 | |
| 349 | g_signal_connect(G_OBJECT(tcd->start_button), "clicked", |
| 350 | (GCallback)start_clicked, tcd); |
| 351 | g_signal_connect(G_OBJECT(tcd->pause_button), "clicked", |
| 352 | (GCallback)pause_clicked, tcd); |
| 353 | g_signal_connect(G_OBJECT(tcd->stop_button), "clicked", |
| 354 | (GCallback)stop_clicked, tcd); |
| 355 | |
| 356 | /* |
| 357 | * show main container |
| 358 | */ |
| 359 | gtk_widget_show(tcd->main_box); |
| 360 | gtk_widget_show(tcd->window); |
| 361 | |
| 362 | |
| 363 | g_object_set_data_full( |
| 364 | G_OBJECT(guicontrol_get_widget(tcd)), |
| 365 | "control_viewer_data", |
| 366 | tcd, |
| 367 | (GDestroyNotify)gui_control_destructor); |
| 368 | |
| 369 | g_control_list = g_slist_append( |
| 370 | g_control_list, |
| 371 | tcd); |
| 372 | |
| 373 | return tcd; |
| 374 | } |
| 375 | |
| 376 | |
| 377 | /** |
| 378 | * @fn void gui_control_destructor(ControlData*) |
| 379 | * |
| 380 | * Destructor for the filter gui module |
| 381 | * @param tcd The module structure |
| 382 | */ |
| 383 | void |
| 384 | gui_control_destructor(ControlData *tcd) |
| 385 | { |
| 386 | Tab *tab = tcd->tab; |
| 387 | |
| 388 | /* May already been done by GTK window closing */ |
| 389 | if(GTK_IS_WIDGET(guicontrol_get_widget(tcd))){ |
| 390 | g_info("widget still exists"); |
| 391 | } |
| 392 | // if(tab != NULL) { |
| 393 | // lttvwindow_unregister_traceset_notify(tcd->tab, |
| 394 | // filter_traceset_changed, |
| 395 | // filter_viewer_data); |
| 396 | // } |
| 397 | lttvwindowtraces_background_notify_remove(tcd); |
| 398 | |
| 399 | g_control_list = g_slist_remove(g_control_list, tcd); |
| 400 | |
| 401 | g_free(tcd); |
| 402 | } |
| 403 | |
| 404 | /* Callbacks */ |
| 405 | |
| 406 | void start_clicked (GtkButton *button, gpointer user_data) |
| 407 | { |
| 408 | ControlData *tcd = (ControlData*)user_data; |
| 409 | |
| 410 | const gchar *username = gtk_entry_get_text(GTK_ENTRY(tcd->username_entry)); |
| 411 | const gchar *password = gtk_entry_get_text(GTK_ENTRY(tcd->password_entry)); |
| 412 | const gchar *channel_dir = |
| 413 | gtk_entry_get_text(GTK_ENTRY(tcd->channel_dir_entry)); |
| 414 | const gchar *trace_dir = gtk_entry_get_text(GTK_ENTRY(tcd->trace_dir_entry)); |
| 415 | const gchar *trace_name = |
| 416 | gtk_entry_get_text(GTK_ENTRY(tcd->trace_name_entry)); |
| 417 | |
| 418 | const gchar *trace_mode_sel = |
| 419 | gtk_combo_box_get_active_text(GTK_COMBO_BOX(tcd->trace_mode_combo)); |
| 420 | const gchar *trace_mode; |
| 421 | if(strcmp(trace_mode_sel, "normal") == 0) |
| 422 | trace_mode = "normal"; |
| 423 | else |
| 424 | trace_mode = "flight"; |
| 425 | |
| 426 | gboolean start_daemon = |
| 427 | gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(tcd->start_daemon_check)); |
| 428 | |
| 429 | const gchar *subbuf_size = |
| 430 | gtk_entry_get_text(GTK_ENTRY(tcd->subbuf_size_entry)); |
| 431 | const gchar *subbuf_num = |
| 432 | gtk_entry_get_text(GTK_ENTRY(tcd->subbuf_num_entry)); |
| 433 | const gchar *lttctl_path = |
| 434 | gtk_entry_get_text(GTK_ENTRY(tcd->lttctl_path_entry)); |
| 435 | const gchar *lttd_path = gtk_entry_get_text(GTK_ENTRY(tcd->lttd_path_entry)); |
| 436 | const gchar *fac_path = gtk_entry_get_text(GTK_ENTRY(tcd->fac_path_entry)); |
| 437 | |
| 438 | //pid_t pid = fork(); |
| 439 | pid_t pid; |
| 440 | int fdpty; |
| 441 | pid = forkpty(&fdpty, NULL, NULL, NULL); |
| 442 | |
| 443 | if(pid > 0) { |
| 444 | /* parent */ |
| 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; |
| 452 | int nbdes; |
| 453 | fd_set readfds; |
| 454 | FD_ZERO(&readfds); |
| 455 | FD_SET(fdpty, &readfds); |
| 456 | |
| 457 | nbdes = select(fdpty+1, &readfds, NULL, NULL, &timeout); |
| 458 | |
| 459 | if(nbdes > 0) { |
| 460 | do { |
| 461 | count = read (fdpty, buf, 256); |
| 462 | if(count > 0) { |
| 463 | buf[count] = '\0'; |
| 464 | printf("%s", buf); |
| 465 | } |
| 466 | } while(select(fdpty+1, &readfds, NULL, NULL, &timeout) > 0); |
| 467 | |
| 468 | } else if(nbdes == -1) { |
| 469 | perror("Timeout occured when waiting for su password prompt"); |
| 470 | return; |
| 471 | } else { |
| 472 | g_warning("No data within 2 seconds when waiting for su prompt"); |
| 473 | return; |
| 474 | } |
| 475 | |
| 476 | g_info("Got su prompt, now writing password..."); |
| 477 | sleep(1); |
| 478 | int ret; |
| 479 | ret = write(fdpty, password, strlen(password)); |
| 480 | if(ret < 0) perror("Error in write"); |
| 481 | ret = write(fdpty, "\n", 1); |
| 482 | if(ret < 0) perror("Error in write"); |
| 483 | fsync(fdpty); |
| 484 | |
| 485 | FD_ZERO(&readfds); |
| 486 | FD_SET(fdpty, &readfds); |
| 487 | do { |
| 488 | if (select(fdpty+1, &readfds, NULL, NULL, &timeout) < 0) { |
| 489 | g_warning("Cannot read from child pipe"); |
| 490 | return; |
| 491 | } |
| 492 | if(FD_ISSET(fdpty, &readfds)) { |
| 493 | count = read(fdpty, buf, 256); |
| 494 | buf[count] = '\0'; |
| 495 | printf("%s", buf); |
| 496 | } else FD_SET(fdpty, &readfds); |
| 497 | usleep(200); |
| 498 | } while(!(ret = waitpid(pid, &status, WNOHANG))); |
| 499 | |
| 500 | if(WIFEXITED(ret)) |
| 501 | if(WEXITSTATUS(ret) != 0) |
| 502 | g_warning("An error occured in the su command, exit code : %hhu", |
| 503 | WEXITSTATUS(ret)); |
| 504 | |
| 505 | |
| 506 | } else if(pid == 0) { |
| 507 | /* child */ |
| 508 | gchar args[MAX_ARGS_LEN]; |
| 509 | gint args_left = MAX_ARGS_LEN - 1; /* for \0 */ |
| 510 | |
| 511 | /* Setup environment variables */ |
| 512 | if(strcmp(lttd_path, "") != 0) |
| 513 | setenv("LTT_DAEMON", lttd_path, 1); |
| 514 | if(strcmp(fac_path, "") != 0) |
| 515 | setenv("LTT_FACILITIES", fac_path, 1); |
| 516 | |
| 517 | /* Setup arguments to su */ |
| 518 | strncpy(args, "\"", args_left); |
| 519 | args_left = MAX_ARGS_LEN - strlen(args) - 1; |
| 520 | |
| 521 | if(strcmp(lttctl_path, "") == 0) |
| 522 | lttctl_path = "lttctl"; |
| 523 | |
| 524 | /* channel dir */ |
| 525 | strncat(args, "-l ", args_left); |
| 526 | args_left = MAX_ARGS_LEN - strlen(args) - 1; |
| 527 | strncat(args, channel_dir, args_left); |
| 528 | args_left = MAX_ARGS_LEN - strlen(args) - 1; |
| 529 | |
| 530 | /* space */ |
| 531 | strncat(args, " ", args_left); |
| 532 | args_left = MAX_ARGS_LEN - strlen(args) - 1; |
| 533 | |
| 534 | /* trace dir */ |
| 535 | strncat(args, "-t ", args_left); |
| 536 | args_left = MAX_ARGS_LEN - strlen(args) - 1; |
| 537 | strncat(args, trace_dir, args_left); |
| 538 | args_left = MAX_ARGS_LEN - strlen(args) - 1; |
| 539 | |
| 540 | /* space */ |
| 541 | strncat(args, " ", args_left); |
| 542 | args_left = MAX_ARGS_LEN - strlen(args) - 1; |
| 543 | |
| 544 | /* name */ |
| 545 | strncat(args, "-n ", args_left); |
| 546 | args_left = MAX_ARGS_LEN - strlen(args) - 1; |
| 547 | strncat(args, trace_name, args_left); |
| 548 | args_left = MAX_ARGS_LEN - strlen(args) - 1; |
| 549 | |
| 550 | /* space */ |
| 551 | strncat(args, " ", args_left); |
| 552 | args_left = MAX_ARGS_LEN - strlen(args) - 1; |
| 553 | |
| 554 | /* trace mode */ |
| 555 | strncat(args, "-m ", args_left); |
| 556 | args_left = MAX_ARGS_LEN - strlen(args) - 1; |
| 557 | strncat(args, trace_mode, args_left); |
| 558 | args_left = MAX_ARGS_LEN - strlen(args) - 1; |
| 559 | |
| 560 | /* space */ |
| 561 | strncat(args, " ", args_left); |
| 562 | args_left = MAX_ARGS_LEN - strlen(args) - 1; |
| 563 | |
| 564 | /* Start daemon ? */ |
| 565 | if(start_daemon) { |
| 566 | strncat(args, "-d", args_left); |
| 567 | args_left = MAX_ARGS_LEN - strlen(args) - 1; |
| 568 | } else { |
| 569 | /* Simply create the channel and then start tracing */ |
| 570 | strncat(args, "-b", args_left); |
| 571 | args_left = MAX_ARGS_LEN - strlen(args) - 1; |
| 572 | } |
| 573 | |
| 574 | /* optional arguments */ |
| 575 | /* subbuffer size */ |
| 576 | if(strcmp(subbuf_size, "") != 0) { |
| 577 | /* space */ |
| 578 | strncat(args, " ", args_left); |
| 579 | args_left = MAX_ARGS_LEN - strlen(args) - 1; |
| 580 | |
| 581 | strncat(args, "-z ", args_left); |
| 582 | args_left = MAX_ARGS_LEN - strlen(args) - 1; |
| 583 | strncat(args, subbuf_size, args_left); |
| 584 | args_left = MAX_ARGS_LEN - strlen(args) - 1; |
| 585 | } |
| 586 | |
| 587 | /* number of subbuffers */ |
| 588 | if(strcmp(subbuf_num, "") != 0) { |
| 589 | /* space */ |
| 590 | strncat(args, " ", args_left); |
| 591 | args_left = MAX_ARGS_LEN - strlen(args) - 1; |
| 592 | |
| 593 | strncat(args, "-x ", args_left); |
| 594 | args_left = MAX_ARGS_LEN - strlen(args) - 1; |
| 595 | strncat(args, subbuf_num, args_left); |
| 596 | args_left = MAX_ARGS_LEN - strlen(args) - 1; |
| 597 | } |
| 598 | |
| 599 | strncat(args, "\"", args_left); |
| 600 | args_left = MAX_ARGS_LEN - strlen(args) - 1; |
| 601 | |
| 602 | //printf("Executing (as %s) : %s %s\n", username, lttctl_path, args); |
| 603 | |
| 604 | execlp("su", "su", "-p", "-c", lttctl_path, username, args, NULL); |
| 605 | exit(-1); /* not supposed to happen! */ |
| 606 | //system(args); |
| 607 | //system("echo blah"); |
| 608 | //exit(0); |
| 609 | |
| 610 | //gint ret = execvp(); |
| 611 | |
| 612 | } else { |
| 613 | /* error */ |
| 614 | g_warning("Error happened when forking for su"); |
| 615 | } |
| 616 | |
| 617 | } |
| 618 | |
| 619 | |
| 620 | void pause_clicked (GtkButton *button, gpointer user_data) |
| 621 | { |
| 622 | ControlData *tcd = (ControlData*)user_data; |
| 623 | |
| 624 | |
| 625 | } |
| 626 | |
| 627 | void stop_clicked (GtkButton *button, gpointer user_data) |
| 628 | { |
| 629 | ControlData *tcd = (ControlData*)user_data; |
| 630 | |
| 631 | |
| 632 | } |
| 633 | |
| 634 | |
| 635 | /** |
| 636 | * @fn GtkWidget* h_guicontrol(Tab*) |
| 637 | * |
| 638 | * Control Module's constructor hook |
| 639 | * |
| 640 | * This constructor is given as a parameter to the menuitem and toolbar button |
| 641 | * registration. It creates the list. |
| 642 | * @param tab A pointer to the parent window. |
| 643 | * @return The widget created. |
| 644 | */ |
| 645 | GtkWidget * |
| 646 | h_guicontrol(Tab *tab) |
| 647 | { |
| 648 | ControlData* f = gui_control(tab) ; |
| 649 | |
| 650 | return NULL; |
| 651 | } |
| 652 | |
| 653 | /** |
| 654 | * @fn static void init() |
| 655 | * |
| 656 | * This function initializes the Filter Viewer functionnality through the |
| 657 | * gtkTraceSet API. |
| 658 | */ |
| 659 | static void init() { |
| 660 | |
| 661 | lttvwindow_register_constructor("guicontrol", |
| 662 | "/", |
| 663 | "Insert Tracing Control Module", |
| 664 | hTraceControlInsert_xpm, |
| 665 | "Insert Tracing Control Module", |
| 666 | h_guicontrol); |
| 667 | } |
| 668 | |
| 669 | /** |
| 670 | * @fn void control_destroy_walk(gpointer,gpointer) |
| 671 | * |
| 672 | * Initiate the destruction of the current gui module |
| 673 | * on the GTK Interface |
| 674 | */ |
| 675 | void |
| 676 | control_destroy_walk(gpointer data, gpointer user_data) |
| 677 | { |
| 678 | ControlData *tcd = (ControlData*)data; |
| 679 | |
| 680 | g_debug("traceontrol.c : control_destroy_walk, %p", tcd); |
| 681 | |
| 682 | /* May already have been done by GTK window closing */ |
| 683 | if(GTK_IS_WIDGET(guicontrol_get_widget(tcd))) |
| 684 | gtk_widget_destroy(guicontrol_get_widget(tcd)); |
| 685 | } |
| 686 | |
| 687 | /** |
| 688 | * @fn static void destroy() |
| 689 | * @brief plugin's destroy function |
| 690 | * |
| 691 | * This function releases the memory reserved by the module and unregisters |
| 692 | * everything that has been registered in the gtkTraceSet API. |
| 693 | */ |
| 694 | static void destroy() { |
| 695 | |
| 696 | g_slist_foreach(g_control_list, control_destroy_walk, NULL ); |
| 697 | |
| 698 | lttvwindow_unregister_constructor(h_guicontrol); |
| 699 | |
| 700 | } |
| 701 | |
| 702 | |
| 703 | LTTV_MODULE("guitracecontrol", "Trace Control Window", \ |
| 704 | "Graphical module that let user control kernel tracing", \ |
| 705 | init, destroy, "lttvwindow") |
| 706 | |