X-Git-Url: http://git.lttng.org./?a=blobdiff_plain;f=ltt%2Fbranches%2Fpoly%2Flttv%2Fmodules%2Fgui%2Ftracecontrol%2Ftracecontrol.c;h=1407aa88bbd4850429f2e356c38af5a51b6b63dd;hb=75e2f3963d4718dd6a629b761966704f6443e597;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..1407aa88 100644 --- a/ltt/branches/poly/lttv/modules/gui/tracecontrol/tracecontrol.c +++ b/ltt/branches/poly/lttv/modules/gui/tracecontrol/tracecontrol.c @@ -45,6 +45,7 @@ #include #include #include +#include #define MAX_ARGS_LEN PATH_MAX * 10 @@ -408,12 +409,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 */ @@ -433,9 +435,10 @@ static void execute_command(const gchar *command, const gchar *username, /* 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..."); + sleep(1); /* make sure the child is ready */ while(1) { pollfd.fd = fdpty; - pollfd.events = POLLIN|POLLPRI; + pollfd.events = POLLIN|POLLPRI|POLLERR|POLLHUP|POLLNVAL; num_rdy = poll(&pollfd, 1, 200); #if 0 @@ -493,7 +496,7 @@ static void execute_command(const gchar *command, const gchar *username, while(1) { int num_hup = 0; pollfd.fd = fdpty; - pollfd.events = POLLIN|POLLPRI; + pollfd.events = POLLIN|POLLPRI|POLLERR|POLLHUP|POLLNVAL; num_rdy = poll(&pollfd, 1, -1); #if 0 @@ -535,11 +538,18 @@ 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."); @@ -562,6 +572,7 @@ wait_child: g_warning("Error happened when forking for su"); } + return retval; } @@ -714,8 +725,25 @@ void start_clicked (GtkButton *button, gpointer user_data) } - 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); + } } @@ -773,8 +801,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 +875,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 +909,7 @@ void stop_clicked (GtkButton *button, gpointer user_data) const gchar *lttctl_path = gtk_entry_get_text(GTK_ENTRY(tcd->lttctl_path_entry)); + const gchar *trace_dir = gtk_entry_get_text(GTK_ENTRY(tcd->trace_dir_entry)); /* Setup arguments to su */ /* child */ @@ -886,8 +950,57 @@ 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(trace_dir); + } + break; + case GTK_RESPONSE_REJECT: + default: + break; + } + gtk_widget_destroy(dialogue); }