From e1358de04977b9da8ddca686059632b85219e902 Mon Sep 17 00:00:00 2001 From: "David B. Cortarello" Date: Thu, 13 Mar 2014 19:06:23 -0300 Subject: [PATCH] Fixed issue where the pty info wasn't read completely --- src/su_backend.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/su_backend.c b/src/su_backend.c index 9833304..15a5a6a 100644 --- a/src/su_backend.c +++ b/src/su_backend.c @@ -170,7 +170,8 @@ void run_su(char *username, char *password, char *command) if (tty) tty_raw(STDIN_FILENO); - while (!waitpid(pid, &status, WNOHANG)) { + while (1) { + waitpid(pid, &status, WNOHANG); /* Ok, the program needs some interaction, so this will do it fine */ tv.tv_sec = 0; @@ -182,8 +183,11 @@ void run_su(char *username, char *password, char *command) if (select(MAX(fdpty, STDIN_FILENO)+1, &rfds, NULL, NULL, &tv) < 0) err(1, "select()"); if (FD_ISSET(fdpty, &rfds)) { - status = read(fdpty, buf, BUFF_SIZE); - write(STDOUT_FILENO, buf, status); + if ((status = read(fdpty, buf, BUFF_SIZE)) > 0) + write(STDOUT_FILENO, buf, status); + else + break; + } else if (FD_ISSET(STDIN_FILENO, &rfds)) { status = read(STDIN_FILENO, buf, BUFF_SIZE);