X-Git-Url: http://git.lttng.org./?a=blobdiff_plain;f=ltt%2Fbranches%2Fpoly%2Flttv%2Fmodules%2Fgui%2Ftracecontrol%2Ftracecontrol.c;h=768095cd387124fa6093e9b7c2d9d74771d302da;hb=37b0f1ed7982a8995d29da17a5b1b6b8127eb162;hp=e852ee711a0690d15a1af2a9e22df045c50c1e56;hpb=45653836d75635b5b841d0d03f1f0789348adc56;p=lttv.git diff --git a/ltt/branches/poly/lttv/modules/gui/tracecontrol/tracecontrol.c b/ltt/branches/poly/lttv/modules/gui/tracecontrol/tracecontrol.c index e852ee71..768095cd 100644 --- a/ltt/branches/poly/lttv/modules/gui/tracecontrol/tracecontrol.c +++ b/ltt/branches/poly/lttv/modules/gui/tracecontrol/tracecontrol.c @@ -21,6 +21,7 @@ #endif #include +#include #include #include #include @@ -32,6 +33,8 @@ #include #include +#include +#include #include "hTraceControlInsert.xpm" #include "TraceControlStart.xpm" @@ -45,6 +48,9 @@ #include #include #include +#include +#include +#include #define MAX_ARGS_LEN PATH_MAX * 10 @@ -64,9 +70,9 @@ typedef struct _ControlData ControlData; * Prototypes */ GtkWidget *guicontrol_get_widget(ControlData *tcd); -ControlData *gui_control(Tab *tab); +ControlData *gui_control(LttvPluginTab *ptab); void gui_control_destructor(ControlData *tcd); -GtkWidget* h_guicontrol(Tab *tab); +GtkWidget* h_guicontrol(LttvPlugin *plugin); void control_destroy_walk(gpointer data, gpointer user_data); /* @@ -115,6 +121,8 @@ struct _ControlData { GtkWidget *subbuf_size_entry; GtkWidget *subbuf_num_label; GtkWidget *subbuf_num_entry; + GtkWidget *lttd_threads_label; + GtkWidget *lttd_threads_entry; GtkWidget *lttctl_path_label; GtkWidget *lttctl_path_entry; GtkWidget *lttd_path_label; @@ -145,8 +153,9 @@ guicontrol_get_widget(ControlData *tcd) * @return The Filter viewer data created. */ ControlData* -gui_control(Tab *tab) +gui_control(LttvPluginTab *ptab) { + Tab *tab = ptab->tab; g_debug("filter::gui_control()"); unsigned i; @@ -180,7 +189,8 @@ gui_control(Tab *tab) pixbuf = gdk_pixbuf_new_from_xpm_data((const char **)TraceControlStart_xpm); image = gtk_image_new_from_pixbuf(pixbuf); tcd->start_button = gtk_button_new_with_label("start"); - gtk_button_set_image(GTK_BUTTON(tcd->start_button), image); + //2.6 gtk_button_set_image(GTK_BUTTON(tcd->start_button), image); + g_object_set(G_OBJECT(tcd->start_button), "image", image, NULL); gtk_button_set_alignment(GTK_BUTTON(tcd->start_button), 0.0, 0.0); gtk_widget_show (tcd->start_button); gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->start_button,6,7,0,1,GTK_FILL,GTK_FILL,2,2); @@ -188,7 +198,8 @@ gui_control(Tab *tab) pixbuf = gdk_pixbuf_new_from_xpm_data((const char **)TraceControlPause_xpm); image = gtk_image_new_from_pixbuf(pixbuf); tcd->pause_button = gtk_button_new_with_label("pause"); - gtk_button_set_image(GTK_BUTTON(tcd->pause_button), image); + //2.6 gtk_button_set_image(GTK_BUTTON(tcd->pause_button), image); + g_object_set(G_OBJECT(tcd->pause_button), "image", image, NULL); gtk_button_set_alignment(GTK_BUTTON(tcd->pause_button), 0.0, 0.0); gtk_widget_show (tcd->pause_button); gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->pause_button,6,7,1,2,GTK_FILL,GTK_FILL,2,2); @@ -196,7 +207,8 @@ gui_control(Tab *tab) pixbuf = gdk_pixbuf_new_from_xpm_data((const char **)TraceControlPause_xpm); image = gtk_image_new_from_pixbuf(pixbuf); tcd->unpause_button = gtk_button_new_with_label("unpause"); - gtk_button_set_image(GTK_BUTTON(tcd->unpause_button), image); + //2.6 gtk_button_set_image(GTK_BUTTON(tcd->unpause_button), image); + g_object_set(G_OBJECT(tcd->unpause_button), "image", image, NULL); gtk_button_set_alignment(GTK_BUTTON(tcd->unpause_button), 0.0, 0.0); gtk_widget_show (tcd->unpause_button); gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->unpause_button,6,7,2,3,GTK_FILL,GTK_FILL,2,2); @@ -204,7 +216,8 @@ gui_control(Tab *tab) pixbuf = gdk_pixbuf_new_from_xpm_data((const char **)TraceControlStop_xpm); image = gtk_image_new_from_pixbuf(pixbuf); tcd->stop_button = gtk_button_new_with_label("stop"); - gtk_button_set_image(GTK_BUTTON(tcd->stop_button), image); + //2.6 gtk_button_set_image(GTK_BUTTON(tcd->stop_button), image); + g_object_set(G_OBJECT(tcd->stop_button), "image", image, NULL); gtk_button_set_alignment(GTK_BUTTON(tcd->stop_button), 0.0, 0.0); gtk_widget_show (tcd->stop_button); gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->stop_button,6,7,3,4,GTK_FILL,GTK_FILL,2,2); @@ -236,7 +249,7 @@ gui_control(Tab *tab) tcd->channel_dir_label = gtk_label_new("Channel directory:"); gtk_widget_show (tcd->channel_dir_label); tcd->channel_dir_entry = gtk_entry_new(); - gtk_entry_set_text(GTK_ENTRY(tcd->channel_dir_entry),"/mnt/relayfs/ltt"); + gtk_entry_set_text(GTK_ENTRY(tcd->channel_dir_entry),"/mnt/debugfs/ltt"); gtk_widget_show (tcd->channel_dir_entry); gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->channel_dir_label,0,2,2,3,GTK_FILL,GTK_FILL,2,2); 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); @@ -304,13 +317,21 @@ gui_control(Tab *tab) gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->subbuf_num_label,0,2,10,11,GTK_FILL,GTK_FILL,2,2); 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); + tcd->lttd_threads_label = gtk_label_new("Number of lttd threads:"); + gtk_widget_show (tcd->lttd_threads_label); + tcd->lttd_threads_entry = gtk_entry_new(); + gtk_entry_set_text(GTK_ENTRY(tcd->lttd_threads_entry), "1"); + gtk_widget_show (tcd->lttd_threads_entry); + gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->lttd_threads_label,0,2,11,12,GTK_FILL,GTK_FILL,2,2); + 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); + tcd->lttctl_path_label = gtk_label_new("path to lttctl:"); gtk_widget_show (tcd->lttctl_path_label); tcd->lttctl_path_entry = gtk_entry_new(); gtk_entry_set_text(GTK_ENTRY(tcd->lttctl_path_entry),PACKAGE_BIN_DIR "/lttctl"); gtk_widget_show (tcd->lttctl_path_entry); - gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->lttctl_path_label,0,2,11,12,GTK_FILL,GTK_FILL,2,2); - gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->lttctl_path_entry,2,6,11,12,GTK_FILL|GTK_EXPAND|GTK_SHRINK,GTK_FILL,0,0); + gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->lttctl_path_label,0,2,12,13,GTK_FILL,GTK_FILL,2,2); + 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); tcd->lttd_path_label = gtk_label_new("path to lttd:"); @@ -318,18 +339,18 @@ gui_control(Tab *tab) tcd->lttd_path_entry = gtk_entry_new(); gtk_entry_set_text(GTK_ENTRY(tcd->lttd_path_entry),PACKAGE_BIN_DIR "/lttd"); gtk_widget_show (tcd->lttd_path_entry); - gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->lttd_path_label,0,2,12,13,GTK_FILL,GTK_FILL,2,2); - gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->lttd_path_entry,2,6,12,13,GTK_FILL|GTK_EXPAND|GTK_SHRINK,GTK_FILL,0,0); + gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->lttd_path_label,0,2,13,14,GTK_FILL,GTK_FILL,2,2); + 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); tcd->fac_path_label = gtk_label_new("path to facilities:"); gtk_widget_show (tcd->fac_path_label); tcd->fac_path_entry = gtk_entry_new(); - gtk_entry_set_text(GTK_ENTRY(tcd->fac_path_entry),PACKAGE_DATA_DIR "/" PACKAGE "/facilities"); + gtk_entry_set_text(GTK_ENTRY(tcd->fac_path_entry),PACKAGE_DATA_DIR "/" "ltt-control" "/facilities"); gtk_widget_set_size_request(tcd->fac_path_entry, 250, -1); gtk_widget_show (tcd->fac_path_entry); - gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->fac_path_label,0,2,13,14,GTK_FILL,GTK_FILL,2,2); - gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->fac_path_entry,2,6,13,14,GTK_FILL|GTK_EXPAND|GTK_SHRINK,GTK_FILL,0,0); + gtk_table_attach( GTK_TABLE(tcd->main_box),tcd->fac_path_label,0,2,14,15,GTK_FILL,GTK_FILL,2,2); + 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); focus_chain = g_list_append (focus_chain, tcd->username_entry); focus_chain = g_list_append (focus_chain, tcd->password_entry); @@ -345,12 +366,15 @@ gui_control(Tab *tab) focus_chain = g_list_append (focus_chain, tcd->append_check); focus_chain = g_list_append (focus_chain, tcd->subbuf_size_entry); focus_chain = g_list_append (focus_chain, tcd->subbuf_num_entry); + focus_chain = g_list_append (focus_chain, tcd->lttd_threads_entry); focus_chain = g_list_append (focus_chain, tcd->lttctl_path_entry); focus_chain = g_list_append (focus_chain, tcd->lttd_path_entry); focus_chain = g_list_append (focus_chain, tcd->fac_path_entry); gtk_container_set_focus_chain(GTK_CONTAINER(tcd->main_box), focus_chain); + g_list_free(focus_chain); + g_signal_connect(G_OBJECT(tcd->start_button), "clicked", (GCallback)start_clicked, tcd); g_signal_connect(G_OBJECT(tcd->pause_button), "clicked", @@ -408,12 +432,13 @@ gui_control_destructor(ControlData *tcd) g_free(tcd); } -static void execute_command(const gchar *command, const gchar *username, +static int execute_command(const gchar *command, const gchar *username, const gchar *password, const gchar *lttd_path, const gchar *fac_path) { pid_t pid; int fdpty; pid = forkpty(&fdpty, NULL, NULL, NULL); + int retval = 0; if(pid > 0) { /* parent */ @@ -428,25 +453,29 @@ static void execute_command(const gchar *command, const gchar *username, struct pollfd pollfd; int num_rdy; int num_hup = 0; + enum read_state { GET_LINE, GET_SEMI, GET_SPACE } read_state = GET_LINE; + retval = fcntl(fdpty, F_SETFL, O_WRONLY); + if(retval == -1) { + perror("Error in fcntl"); + goto wait_child; + } /* Read the output from the child terminal before the prompt. If no data in * 200 ms, we stop reading to give the password */ g_info("Reading from child console..."); while(1) { pollfd.fd = fdpty; - pollfd.events = POLLIN|POLLPRI; + pollfd.events = POLLIN|POLLPRI|POLLERR|POLLHUP|POLLNVAL; - num_rdy = poll(&pollfd, 1, 200); -#if 0 + num_rdy = poll(&pollfd, 1, -1); if(num_rdy == -1) { perror("Poll error"); goto wait_child; } -#endif //0 - /* Timeout : stop waiting for chars */ - if(num_rdy == 0) break; + /* Timeout : Stop waiting for chars */ + if(num_rdy == 0) goto wait_child; switch(pollfd.revents) { case POLLERR: @@ -465,8 +494,31 @@ static void execute_command(const gchar *command, const gchar *username, case POLLIN: count = read (fdpty, buf, 256); if(count > 0) { + unsigned int i; buf[count] = '\0'; - printf("%s", buf); + g_printf("%s", buf); + for(i=0; i 0) { + buf[count] = '\0'; + printf("%s", buf); + } else if(count == -1) { + perror("Error in read"); + goto wait_child; + } + } + + if(pollfd.revents & POLLHUP) { + g_info("Polling FD : hung up."); + num_hup++; + } - switch(pollfd.revents) { - case POLLERR: - g_warning("Error returned in polling fd\n"); - num_hup++; - break; - case POLLHUP: - g_info("Polling FD : hung up."); - num_hup++; - break; - case POLLNVAL: - g_warning("Polling fd tells it is not open"); - num_hup++; - break; - case POLLPRI: - case POLLIN: - count = read (fdpty, buf, 256); - if(count > 0) { - buf[count] = '\0'; - printf("%s", buf); - } else if(count == -1) { - perror("Error in read"); - goto wait_child; - } - break; - } if(num_hup > 0) goto wait_child; } wait_child: g_info("Waiting for child exit..."); ret = waitpid(pid, &status, 0); - - if(WIFEXITED(ret)) - if(WEXITSTATUS(ret) != 0) - g_warning("An error occured in the su command : %s", - strerror(WEXITSTATUS(ret))); + + if(ret == -1) { + g_warning("An error occured in wait : %s", + strerror(errno)); + } else { + if(WIFEXITED(status)) + if(WEXITSTATUS(status) != 0) { + retval = WEXITSTATUS(status); + g_warning("An error occured in the su command : %s", + strerror(retval)); + } + } g_info("Child exited."); @@ -550,7 +613,8 @@ wait_child: if(strcmp(fac_path, "") != 0) setenv("LTT_FACILITIES", fac_path, 1); - g_message("Executing (as %s) : %s\n", username, command); + /* One comment line (must be only one) */ + g_printf("Executing (as %s) : %s\n", username, command); execlp("su", "su", "-p", "-c", command, username, NULL); exit(-1); /* not supposed to happen! */ @@ -562,6 +626,7 @@ wait_child: g_warning("Error happened when forking for su"); } + return retval; } @@ -579,8 +644,15 @@ void start_clicked (GtkButton *button, gpointer user_data) const gchar *trace_name = gtk_entry_get_text(GTK_ENTRY(tcd->trace_name_entry)); - const gchar *trace_mode_sel = - gtk_combo_box_get_active_text(GTK_COMBO_BOX(tcd->trace_mode_combo)); + const gchar *trace_mode_sel; + GtkTreeIter iter; + + gtk_combo_box_get_active_iter(GTK_COMBO_BOX(tcd->trace_mode_combo), &iter); + gtk_tree_model_get( + gtk_combo_box_get_model(GTK_COMBO_BOX(tcd->trace_mode_combo)), + &iter, 0, &trace_mode_sel, -1); + //const gchar *trace_mode_sel = + //2.6+ gtk_combo_box_get_active_text(GTK_COMBO_BOX(tcd->trace_mode_combo)); const gchar *trace_mode; if(strcmp(trace_mode_sel, "normal") == 0) trace_mode = "normal"; @@ -597,6 +669,8 @@ void start_clicked (GtkButton *button, gpointer user_data) gtk_entry_get_text(GTK_ENTRY(tcd->subbuf_size_entry)); const gchar *subbuf_num = gtk_entry_get_text(GTK_ENTRY(tcd->subbuf_num_entry)); + const gchar *threads_num = + gtk_entry_get_text(GTK_ENTRY(tcd->lttd_threads_entry)); const gchar *lttctl_path = gtk_entry_get_text(GTK_ENTRY(tcd->lttctl_path_entry)); const gchar *lttd_path = gtk_entry_get_text(GTK_ENTRY(tcd->lttd_path_entry)); @@ -713,10 +787,39 @@ void start_clicked (GtkButton *button, gpointer user_data) args_left = MAX_ARGS_LEN - strlen(args) - 1; } - - execute_command(args, username, password, lttd_path, fac_path); + /* number of lttd threads */ + if(strcmp(threads_num, "") != 0) { + /* space */ + strncat(args, " ", args_left); + args_left = MAX_ARGS_LEN - strlen(args) - 1; + + strncat(args, "-N ", args_left); + args_left = MAX_ARGS_LEN - strlen(args) - 1; + strncat(args, threads_num, args_left); + args_left = MAX_ARGS_LEN - strlen(args) - 1; + } + int retval = execute_command(args, username, password, lttd_path, fac_path); + + if(retval) { + gchar msg[256]; + guint msg_left = 256; + + strcpy(msg, "A problem occured when executing the su command : "); + msg_left = 256 - strlen(msg) - 1; + strncat(msg, strerror(retval), msg_left); + GtkWidget *dialogue = + gtk_message_dialog_new( + GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(button))), + GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_OK, + msg); + gtk_dialog_run(GTK_DIALOG(dialogue)); + gtk_widget_destroy(dialogue); + } + } @@ -773,8 +876,25 @@ void pause_clicked (GtkButton *button, gpointer user_data) strncat(args, "-q", args_left); args_left = MAX_ARGS_LEN - strlen(args) - 1; - execute_command(args, username, password, lttd_path, fac_path); - + int retval = execute_command(args, username, password, lttd_path, fac_path); + if(retval) { + gchar msg[256]; + guint msg_left = 256; + + strcpy(msg, "A problem occured when executing the su command : "); + msg_left = 256 - strlen(msg) - 1; + strncat(msg, strerror(retval), msg_left); + GtkWidget *dialogue = + gtk_message_dialog_new( + GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(button))), + GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_OK, + msg); + gtk_dialog_run(GTK_DIALOG(dialogue)); + gtk_widget_destroy(dialogue); + } + } void unpause_clicked (GtkButton *button, gpointer user_data) @@ -830,7 +950,25 @@ void unpause_clicked (GtkButton *button, gpointer user_data) strncat(args, "-s", args_left); args_left = MAX_ARGS_LEN - strlen(args) - 1; - execute_command(args, username, password, lttd_path, fac_path); + int retval = execute_command(args, username, password, lttd_path, fac_path); + if(retval) { + gchar msg[256]; + guint msg_left = 256; + + strcpy(msg, "A problem occured when executing the su command : "); + msg_left = 256 - strlen(msg) - 1; + strncat(msg, strerror(retval), msg_left); + GtkWidget *dialogue = + gtk_message_dialog_new( + GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(button))), + GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_OK, + msg); + gtk_dialog_run(GTK_DIALOG(dialogue)); + gtk_widget_destroy(dialogue); + } + } void stop_clicked (GtkButton *button, gpointer user_data) @@ -846,6 +984,10 @@ void stop_clicked (GtkButton *button, gpointer user_data) const gchar *lttctl_path = gtk_entry_get_text(GTK_ENTRY(tcd->lttctl_path_entry)); + gchar *trace_dir = gtk_entry_get_text(GTK_ENTRY(tcd->trace_dir_entry)); + GSList * trace_list = NULL; + + trace_list = g_slist_append(trace_list, trace_dir); /* Setup arguments to su */ /* child */ @@ -886,9 +1028,58 @@ void stop_clicked (GtkButton *button, gpointer user_data) strncat(args, "-R", args_left); args_left = MAX_ARGS_LEN - strlen(args) - 1; - execute_command(args, username, password, lttd_path, fac_path); - + int retval = execute_command(args, username, password, lttd_path, fac_path); + if(retval) { + gchar msg[256]; + guint msg_left = 256; + + strcpy(msg, "A problem occured when executing the su command : "); + msg_left = 256 - strlen(msg) - 1; + strncat(msg, strerror(retval), msg_left); + GtkWidget *dialogue = + gtk_message_dialog_new( + GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(button))), + GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_OK, + msg); + gtk_dialog_run(GTK_DIALOG(dialogue)); + gtk_widget_destroy(dialogue); + return; + } + + /* Ask to the user if he wants to open the trace in a new window */ + GtkWidget *dialogue; + GtkWidget *label; + gint id; + + dialogue = gtk_dialog_new_with_buttons("Open trace ?", + GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(button))), + GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_STOCK_YES,GTK_RESPONSE_ACCEPT, + GTK_STOCK_NO,GTK_RESPONSE_REJECT, + NULL); + label = gtk_label_new("Do you want to open the trace in LTTV ?"); + gtk_widget_show(label); + + gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialogue)->vbox), + label); + + id = gtk_dialog_run(GTK_DIALOG(dialogue)); + + switch(id){ + case GTK_RESPONSE_ACCEPT: + { + create_main_window_with_trace_list(trace_list); + } + break; + case GTK_RESPONSE_REJECT: + default: + break; + } + gtk_widget_destroy(dialogue); + g_slist_free(trace_list); } @@ -903,9 +1094,10 @@ void stop_clicked (GtkButton *button, gpointer user_data) * @return The widget created. */ GtkWidget * -h_guicontrol(Tab *tab) +h_guicontrol(LttvPlugin *plugin) { - ControlData* f = gui_control(tab) ; + LttvPluginTab *ptab = LTTV_PLUGIN_TAB(plugin); + ControlData* f = gui_control(ptab); return NULL; }