From b57800a3d1160296471f7054345aeb01ca92bb26 Mon Sep 17 00:00:00 2001 From: compudj Date: Wed, 8 Feb 2006 01:28:09 +0000 Subject: [PATCH] fix tracontrol timing problem with su git-svn-id: http://ltt.polymtl.ca/svn@1518 04897980-b3bd-0310-b5e0-8ef037075253 --- .../modules/gui/tracecontrol/tracecontrol.c | 107 ++++++++++++------ 1 file changed, 70 insertions(+), 37 deletions(-) diff --git a/ltt/branches/poly/lttv/modules/gui/tracecontrol/tracecontrol.c b/ltt/branches/poly/lttv/modules/gui/tracecontrol/tracecontrol.c index 0617174f..e3f1ff85 100644 --- a/ltt/branches/poly/lttv/modules/gui/tracecontrol/tracecontrol.c +++ b/ltt/branches/poly/lttv/modules/gui/tracecontrol/tracecontrol.c @@ -46,6 +46,8 @@ #include #include #include +#include +#include #define MAX_ARGS_LEN PATH_MAX * 10 @@ -447,26 +449,29 @@ static int 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..."); - sleep(1); /* make sure the child is ready */ while(1) { pollfd.fd = fdpty; 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: @@ -485,8 +490,31 @@ static int 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: @@ -577,7 +609,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! */ -- 2.34.1