Browse Source

procd: Exit askfirst on read error

When running askfirst on an unused tty device askfirst starts
busylooping forever. Fix this by returning an error if we read
an EOF.

Signed-off-by: Helmut Schaa <helmut.schaa@googlemail.com>
Helmut Schaa 10 years ago
parent
commit
f51f9cc573
1 changed files with 9 additions and 2 deletions
  1. 9 2
      askfirst.c

+ 9 - 2
askfirst.c

@@ -42,12 +42,19 @@ static int redirect_output(const char *dev)
 
 int main(int argc, char **argv)
 {
+	int c;
+
 	if (redirect_output(argv[1]))
 		fprintf(stderr, "%s: Failed to open %s\n", argv[0], argv[1]);
 
 	printf("Please press Enter to activate this console.\n");
-	while (getchar() != 0xA)
-		;
+	do {
+		c = getchar();
+		if (c == EOF)
+			return -1;
+	}
+	while (c != 0xA);
+
 	execvp(argv[2], &argv[2]);
 	printf("%s: Failed to execute %s\n", argv[0], argv[2]);