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 | |
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); |
b154e818 |
73 | ControlData *gui_control(LttvPluginTab *ptab); |
e7c8534e |
74 | void gui_control_destructor(ControlData *tcd); |
b154e818 |
75 | GtkWidget* h_guicontrol(LttvPlugin *plugin); |
e7c8534e |
76 | void control_destroy_walk(gpointer data, gpointer user_data); |
77 | |
78 | /* |
79 | * Callback functions |
80 | */ |
81 | |
77ef407f |
82 | static void start_clicked (GtkButton *button, gpointer user_data); |
83 | static void pause_clicked (GtkButton *button, gpointer user_data); |
45653836 |
84 | static void unpause_clicked (GtkButton *button, gpointer user_data); |
77ef407f |
85 | static 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 | */ |
93 | struct _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 | */ |
142 | GtkWidget* |
143 | guicontrol_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 | */ |
155 | ControlData* |
b154e818 |
156 | gui_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 | */ |
414 | void |
415 | gui_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 |
435 | static 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 |
533 | write_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 | } |
590 | wait_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 |
635 | void 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 | |
705 | /* channel dir */ |
706 | strncat(args, "-l ", args_left); |
707 | args_left = MAX_ARGS_LEN - strlen(args) - 1; |
708 | strncat(args, channel_dir, args_left); |
709 | args_left = MAX_ARGS_LEN - strlen(args) - 1; |
710 | |
711 | /* space */ |
712 | strncat(args, " ", args_left); |
713 | args_left = MAX_ARGS_LEN - strlen(args) - 1; |
714 | |
715 | /* trace dir */ |
716 | strncat(args, "-t ", args_left); |
717 | args_left = MAX_ARGS_LEN - strlen(args) - 1; |
718 | strncat(args, trace_dir, args_left); |
719 | args_left = MAX_ARGS_LEN - strlen(args) - 1; |
720 | |
721 | /* space */ |
722 | strncat(args, " ", args_left); |
723 | args_left = MAX_ARGS_LEN - strlen(args) - 1; |
724 | |
725 | /* name */ |
726 | strncat(args, "-n ", args_left); |
727 | args_left = MAX_ARGS_LEN - strlen(args) - 1; |
728 | strncat(args, trace_name, args_left); |
729 | args_left = MAX_ARGS_LEN - strlen(args) - 1; |
730 | |
731 | /* space */ |
732 | strncat(args, " ", args_left); |
733 | args_left = MAX_ARGS_LEN - strlen(args) - 1; |
734 | |
735 | /* trace mode */ |
736 | strncat(args, "-m ", args_left); |
737 | args_left = MAX_ARGS_LEN - strlen(args) - 1; |
738 | strncat(args, trace_mode, args_left); |
739 | args_left = MAX_ARGS_LEN - strlen(args) - 1; |
740 | |
741 | /* space */ |
742 | strncat(args, " ", args_left); |
743 | args_left = MAX_ARGS_LEN - strlen(args) - 1; |
744 | |
745 | /* Start daemon ? */ |
746 | if(start_daemon) { |
747 | strncat(args, "-d", args_left); |
f6f6abf0 |
748 | args_left = MAX_ARGS_LEN - strlen(args) - 1; |
45653836 |
749 | } else { |
750 | /* Simply create the channel and then start tracing */ |
751 | strncat(args, "-b", args_left); |
f6f6abf0 |
752 | args_left = MAX_ARGS_LEN - strlen(args) - 1; |
45653836 |
753 | } |
754 | |
f6f6abf0 |
755 | |
45653836 |
756 | /* Append to trace ? */ |
757 | if(append) { |
f6f6abf0 |
758 | /* space */ |
759 | strncat(args, " ", args_left); |
760 | args_left = MAX_ARGS_LEN - strlen(args) - 1; |
45653836 |
761 | strncat(args, "-a", args_left); |
f6f6abf0 |
762 | args_left = MAX_ARGS_LEN - strlen(args) - 1; |
45653836 |
763 | } |
764 | |
765 | /* optional arguments */ |
766 | /* subbuffer size */ |
767 | if(strcmp(subbuf_size, "") != 0) { |
f6f6abf0 |
768 | /* space */ |
769 | strncat(args, " ", args_left); |
770 | args_left = MAX_ARGS_LEN - strlen(args) - 1; |
771 | |
45653836 |
772 | strncat(args, "-z ", args_left); |
f6f6abf0 |
773 | args_left = MAX_ARGS_LEN - strlen(args) - 1; |
45653836 |
774 | strncat(args, subbuf_size, args_left); |
f6f6abf0 |
775 | args_left = MAX_ARGS_LEN - strlen(args) - 1; |
45653836 |
776 | } |
f6f6abf0 |
777 | |
45653836 |
778 | /* number of subbuffers */ |
779 | if(strcmp(subbuf_num, "") != 0) { |
f6f6abf0 |
780 | /* space */ |
781 | strncat(args, " ", args_left); |
782 | args_left = MAX_ARGS_LEN - strlen(args) - 1; |
783 | |
45653836 |
784 | strncat(args, "-x ", args_left); |
785 | args_left = MAX_ARGS_LEN - strlen(args) - 1; |
786 | strncat(args, subbuf_num, args_left); |
787 | args_left = MAX_ARGS_LEN - strlen(args) - 1; |
788 | } |
ff430216 |
789 | |
e6542e85 |
790 | /* number of lttd threads */ |
791 | if(strcmp(threads_num, "") != 0) { |
792 | /* space */ |
793 | strncat(args, " ", args_left); |
794 | args_left = MAX_ARGS_LEN - strlen(args) - 1; |
795 | |
796 | strncat(args, "-N ", args_left); |
797 | args_left = MAX_ARGS_LEN - strlen(args) - 1; |
798 | strncat(args, threads_num, args_left); |
799 | args_left = MAX_ARGS_LEN - strlen(args) - 1; |
800 | } |
801 | |
77ef407f |
802 | |
29e34d6c |
803 | int retval = execute_command(args, username, password, lttd_path, fac_path); |
804 | |
805 | if(retval) { |
806 | gchar msg[256]; |
807 | guint msg_left = 256; |
808 | |
809 | strcpy(msg, "A problem occured when executing the su command : "); |
810 | msg_left = 256 - strlen(msg) - 1; |
811 | strncat(msg, strerror(retval), msg_left); |
812 | GtkWidget *dialogue = |
813 | gtk_message_dialog_new( |
814 | GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(button))), |
815 | GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT, |
816 | GTK_MESSAGE_ERROR, |
817 | GTK_BUTTONS_OK, |
818 | msg); |
819 | gtk_dialog_run(GTK_DIALOG(dialogue)); |
820 | gtk_widget_destroy(dialogue); |
821 | } |
77ef407f |
822 | |
823 | } |
824 | |
825 | |
826 | void pause_clicked (GtkButton *button, gpointer user_data) |
827 | { |
828 | ControlData *tcd = (ControlData*)user_data; |
829 | |
45653836 |
830 | const gchar *username = gtk_entry_get_text(GTK_ENTRY(tcd->username_entry)); |
831 | const gchar *password = gtk_entry_get_text(GTK_ENTRY(tcd->password_entry)); |
832 | const gchar *trace_name = |
833 | gtk_entry_get_text(GTK_ENTRY(tcd->trace_name_entry)); |
834 | const gchar *lttd_path = ""; |
835 | const gchar *fac_path = ""; |
836 | |
837 | const gchar *lttctl_path = |
838 | gtk_entry_get_text(GTK_ENTRY(tcd->lttctl_path_entry)); |
77ef407f |
839 | |
45653836 |
840 | /* Setup arguments to su */ |
841 | /* child */ |
842 | gchar args[MAX_ARGS_LEN]; |
843 | gint args_left = MAX_ARGS_LEN - 1; /* for \0 */ |
844 | |
845 | args[0] = '\0'; |
846 | |
847 | /* Command */ |
848 | strncat(args, "exec", args_left); |
849 | args_left = MAX_ARGS_LEN - strlen(args) - 1; |
850 | |
851 | /* space */ |
852 | strncat(args, " ", args_left); |
853 | args_left = MAX_ARGS_LEN - strlen(args) - 1; |
854 | |
855 | if(strcmp(lttctl_path, "") == 0) |
856 | strncat(args, "lttctl", args_left); |
857 | else |
858 | strncat(args, lttctl_path, args_left); |
859 | args_left = MAX_ARGS_LEN - strlen(args) - 1; |
860 | |
861 | /* space */ |
862 | strncat(args, " ", args_left); |
863 | args_left = MAX_ARGS_LEN - strlen(args) - 1; |
864 | |
865 | /* name */ |
866 | strncat(args, "-n ", args_left); |
867 | args_left = MAX_ARGS_LEN - strlen(args) - 1; |
868 | strncat(args, trace_name, args_left); |
869 | args_left = MAX_ARGS_LEN - strlen(args) - 1; |
870 | |
871 | /* space */ |
872 | strncat(args, " ", args_left); |
873 | args_left = MAX_ARGS_LEN - strlen(args) - 1; |
874 | |
875 | /* Simply pause tracing */ |
876 | strncat(args, "-q", args_left); |
877 | args_left = MAX_ARGS_LEN - strlen(args) - 1; |
878 | |
29e34d6c |
879 | int retval = execute_command(args, username, password, lttd_path, fac_path); |
880 | if(retval) { |
881 | gchar msg[256]; |
882 | guint msg_left = 256; |
883 | |
884 | strcpy(msg, "A problem occured when executing the su command : "); |
885 | msg_left = 256 - strlen(msg) - 1; |
886 | strncat(msg, strerror(retval), msg_left); |
887 | GtkWidget *dialogue = |
888 | gtk_message_dialog_new( |
889 | GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(button))), |
890 | GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT, |
891 | GTK_MESSAGE_ERROR, |
892 | GTK_BUTTONS_OK, |
893 | msg); |
894 | gtk_dialog_run(GTK_DIALOG(dialogue)); |
895 | gtk_widget_destroy(dialogue); |
896 | } |
897 | |
45653836 |
898 | } |
899 | |
900 | void unpause_clicked (GtkButton *button, gpointer user_data) |
901 | { |
902 | ControlData *tcd = (ControlData*)user_data; |
903 | |
904 | const gchar *username = gtk_entry_get_text(GTK_ENTRY(tcd->username_entry)); |
905 | const gchar *password = gtk_entry_get_text(GTK_ENTRY(tcd->password_entry)); |
906 | const gchar *trace_name = |
907 | gtk_entry_get_text(GTK_ENTRY(tcd->trace_name_entry)); |
908 | const gchar *lttd_path = ""; |
909 | const gchar *fac_path = ""; |
910 | |
911 | const gchar *lttctl_path = |
912 | gtk_entry_get_text(GTK_ENTRY(tcd->lttctl_path_entry)); |
913 | |
914 | /* Setup arguments to su */ |
915 | /* child */ |
916 | gchar args[MAX_ARGS_LEN]; |
917 | gint args_left = MAX_ARGS_LEN - 1; /* for \0 */ |
918 | |
919 | args[0] = '\0'; |
920 | |
921 | /* Command */ |
922 | strncat(args, "exec", args_left); |
923 | args_left = MAX_ARGS_LEN - strlen(args) - 1; |
924 | |
925 | /* space */ |
926 | strncat(args, " ", args_left); |
927 | args_left = MAX_ARGS_LEN - strlen(args) - 1; |
928 | |
929 | if(strcmp(lttctl_path, "") == 0) |
930 | strncat(args, "lttctl", args_left); |
931 | else |
932 | strncat(args, lttctl_path, args_left); |
933 | args_left = MAX_ARGS_LEN - strlen(args) - 1; |
934 | |
935 | /* space */ |
936 | strncat(args, " ", args_left); |
937 | args_left = MAX_ARGS_LEN - strlen(args) - 1; |
938 | |
939 | /* name */ |
940 | strncat(args, "-n ", args_left); |
941 | args_left = MAX_ARGS_LEN - strlen(args) - 1; |
942 | strncat(args, trace_name, args_left); |
943 | args_left = MAX_ARGS_LEN - strlen(args) - 1; |
944 | |
945 | /* space */ |
946 | strncat(args, " ", args_left); |
947 | args_left = MAX_ARGS_LEN - strlen(args) - 1; |
948 | |
949 | /* Simply unpause tracing */ |
950 | strncat(args, "-s", args_left); |
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 | |
974 | void 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; |
1016 | |
1017 | /* name */ |
1018 | strncat(args, "-n ", args_left); |
1019 | args_left = MAX_ARGS_LEN - strlen(args) - 1; |
1020 | strncat(args, trace_name, args_left); |
1021 | args_left = MAX_ARGS_LEN - strlen(args) - 1; |
1022 | |
1023 | /* space */ |
1024 | strncat(args, " ", args_left); |
1025 | args_left = MAX_ARGS_LEN - strlen(args) - 1; |
1026 | |
1027 | /* Simply stop tracing and destroy channel */ |
1028 | strncat(args, "-R", args_left); |
1029 | args_left = MAX_ARGS_LEN - strlen(args) - 1; |
1030 | |
29e34d6c |
1031 | int retval = execute_command(args, username, password, lttd_path, fac_path); |
1032 | if(retval) { |
1033 | gchar msg[256]; |
1034 | guint msg_left = 256; |
1035 | |
1036 | strcpy(msg, "A problem occured when executing the su command : "); |
1037 | msg_left = 256 - strlen(msg) - 1; |
1038 | strncat(msg, strerror(retval), msg_left); |
1039 | GtkWidget *dialogue = |
1040 | gtk_message_dialog_new( |
1041 | GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(button))), |
1042 | GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT, |
1043 | GTK_MESSAGE_ERROR, |
1044 | GTK_BUTTONS_OK, |
1045 | msg); |
1046 | gtk_dialog_run(GTK_DIALOG(dialogue)); |
1047 | gtk_widget_destroy(dialogue); |
1048 | return; |
1049 | } |
1050 | |
77ef407f |
1051 | |
8321ae6a |
1052 | /* Ask to the user if he wants to open the trace in a new window */ |
1053 | GtkWidget *dialogue; |
1054 | GtkWidget *label; |
1055 | gint id; |
1056 | |
1057 | dialogue = gtk_dialog_new_with_buttons("Open trace ?", |
1058 | GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(button))), |
1059 | GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, |
1060 | GTK_STOCK_YES,GTK_RESPONSE_ACCEPT, |
1061 | GTK_STOCK_NO,GTK_RESPONSE_REJECT, |
1062 | NULL); |
1063 | label = gtk_label_new("Do you want to open the trace in LTTV ?"); |
1064 | gtk_widget_show(label); |
1065 | |
1066 | gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialogue)->vbox), |
1067 | label); |
1068 | |
1069 | id = gtk_dialog_run(GTK_DIALOG(dialogue)); |
1070 | |
1071 | switch(id){ |
1072 | case GTK_RESPONSE_ACCEPT: |
1073 | { |
b154e818 |
1074 | create_main_window_with_trace_list(trace_list); |
8321ae6a |
1075 | } |
1076 | break; |
1077 | case GTK_RESPONSE_REJECT: |
1078 | default: |
1079 | break; |
1080 | } |
1081 | gtk_widget_destroy(dialogue); |
b154e818 |
1082 | g_slist_free(trace_list); |
77ef407f |
1083 | } |
1084 | |
e7c8534e |
1085 | |
1086 | /** |
1087 | * @fn GtkWidget* h_guicontrol(Tab*) |
1088 | * |
1089 | * Control Module's constructor hook |
1090 | * |
1091 | * This constructor is given as a parameter to the menuitem and toolbar button |
1092 | * registration. It creates the list. |
1093 | * @param tab A pointer to the parent window. |
1094 | * @return The widget created. |
1095 | */ |
1096 | GtkWidget * |
b154e818 |
1097 | h_guicontrol(LttvPlugin *plugin) |
e7c8534e |
1098 | { |
b154e818 |
1099 | LttvPluginTab *ptab = LTTV_PLUGIN_TAB(plugin); |
1100 | ControlData* f = gui_control(ptab); |
e7c8534e |
1101 | |
1102 | return NULL; |
1103 | } |
1104 | |
1105 | /** |
1106 | * @fn static void init() |
1107 | * |
1108 | * This function initializes the Filter Viewer functionnality through the |
1109 | * gtkTraceSet API. |
1110 | */ |
1111 | static void init() { |
1112 | |
1113 | lttvwindow_register_constructor("guicontrol", |
1114 | "/", |
1115 | "Insert Tracing Control Module", |
1116 | hTraceControlInsert_xpm, |
1117 | "Insert Tracing Control Module", |
1118 | h_guicontrol); |
1119 | } |
1120 | |
1121 | /** |
1122 | * @fn void control_destroy_walk(gpointer,gpointer) |
1123 | * |
1124 | * Initiate the destruction of the current gui module |
1125 | * on the GTK Interface |
1126 | */ |
1127 | void |
1128 | control_destroy_walk(gpointer data, gpointer user_data) |
1129 | { |
1130 | ControlData *tcd = (ControlData*)data; |
1131 | |
1132 | g_debug("traceontrol.c : control_destroy_walk, %p", tcd); |
1133 | |
1134 | /* May already have been done by GTK window closing */ |
1135 | if(GTK_IS_WIDGET(guicontrol_get_widget(tcd))) |
1136 | gtk_widget_destroy(guicontrol_get_widget(tcd)); |
1137 | } |
1138 | |
1139 | /** |
1140 | * @fn static void destroy() |
1141 | * @brief plugin's destroy function |
1142 | * |
1143 | * This function releases the memory reserved by the module and unregisters |
1144 | * everything that has been registered in the gtkTraceSet API. |
1145 | */ |
1146 | static void destroy() { |
1147 | |
1148 | g_slist_foreach(g_control_list, control_destroy_walk, NULL ); |
1149 | |
1150 | lttvwindow_unregister_constructor(h_guicontrol); |
1151 | |
1152 | } |
1153 | |
1154 | |
1155 | LTTV_MODULE("guitracecontrol", "Trace Control Window", \ |
1156 | "Graphical module that let user control kernel tracing", \ |
1157 | init, destroy, "lttvwindow") |
1158 | |