procd: Exit askfirst on read error
authorHelmut Schaa <helmut.schaa@googlemail.com>
Tue, 17 Sep 2013 06:48:48 +0000 (06:48 +0000)
committerJohn Crispin <blogic@openwrt.org>
Tue, 17 Sep 2013 19:30:09 +0000 (21:30 +0200)
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>
askfirst.c

index 99164862e868e54eff2732e128213723b02658c3..6ad77aac5d5fbcc36bf7d553981834c6b568001b 100644 (file)
@@ -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]);