Skip to content

Commit

Permalink
Fixed issue where the pty info wasn't read completely
Browse files Browse the repository at this point in the history
  • Loading branch information
nomius committed Mar 13, 2014
1 parent aba2038 commit e1358de
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/su_backend.c
Expand Up @@ -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;
Expand All @@ -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);
Expand Down

0 comments on commit e1358de

Please sign in to comment.