Date: Sun, 10 Oct 1999 20:21:53 +0100 (BST) From: iedowse@maths.tcd.ie To: FreeBSD-gnats-submit@freebsd.org Subject: bin/14250: restore(8) can loop if tty goes away or with -y option Message-ID: <199910102021.aa25552@walton.maths.tcd.ie>
next in thread | raw e-mail | index | archive | help
>Number: 14250 >Category: bin >Synopsis: restore(8) can loop if tty goes away or with -y option >Confidential: no >Severity: serious >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Sun Oct 10 12:30:01 PDT 1999 >Closed-Date: >Last-Modified: >Originator: Ian Dowse >Release: FreeBSD 3.3-STABLE i386 >Organization: School of Mathematics, Trinity College Dublin >Environment: All versions of FreeBSD. >Description: restore(8) can get stuck in a loop under certain conditions: - If run in the background, and the user logs out while it is still running, restore may start looping at the point where it asks if the permissions on "." should be set. It does check for tty EOF conditions with feof(3), but some types of tty errors generate an EIO error rather than an end-of-file condition. As well as looping, restore also fails to set permissions on most of the directories it has extracted. - If the '-y' option is specified, or an end-of-file or error condition occurs on the tty, a truncated pipe input will result in an infinite loop of 'Changing volumes on pipe input?' messages. This problem is related to that in PR bin/4176. >How-To-Repeat: - Run the command: cat dumpfile | restore xf - & and then log out (I used tcsh - but this may not be important). The restore process will loop when it gets to the end, and not set all permissions correctly. - Truncate a dump file, and run the command: cat dumpfile | restore xyf - >Fix: Apply the following patches in src/sbin/restore: --- tape.c 1999/08/28 00:14:08 1.16 +++ tape.c 1999/10/10 18:36:34 @@ -305,8 +305,12 @@ gettingfile = 0; } if (pipein) { - if (nextvol != 1) + if (nextvol != 1) { panic("Changing volumes on pipe input?\n"); + /* Avoid looping if we weren't asking a tty */ + if (yflag || ferror(terminal) || feof(terminal)) + done(1); + } if (volno == 1) return; goto gethdr; @@ -343,10 +347,9 @@ do { fprintf(stderr, "Specify next volume #: "); (void) fflush(stderr); - (void) fgets(buf, BUFSIZ, terminal); - } while (!feof(terminal) && buf[0] == '\n'); - if (feof(terminal)) - done(1); + if (fgets(buf, BUFSIZ, terminal) == NULL) + done(1); + } while (buf[0] == '\n'); newvol = atoi(buf); if (newvol <= 0) { fprintf(stderr, @@ -362,8 +365,7 @@ fprintf(stderr, "Enter ``none'' if there are no more tapes\n"); fprintf(stderr, "otherwise enter tape name (default: %s) ", magtape); (void) fflush(stderr); - (void) fgets(buf, BUFSIZ, terminal); - if (feof(terminal)) + if (fgets(buf, BUFSIZ, terminal) == NULL) done(1); if (!strcmp(buf, "none\n")) { terminateinput(); --- utilities.c 1999/08/28 00:14:09 1.8 +++ utilities.c 1999/10/10 18:06:01 @@ -405,14 +405,14 @@ reply(question) char *question; { - char c; + int c; do { fprintf(stderr, "%s? [yn] ", question); (void) fflush(stderr); c = getc(terminal); while (c != '\n' && getc(terminal) != '\n') - if (feof(terminal)) + if (c == EOF) return (FAIL); } while (c != 'y' && c != 'n'); if (c == 'y') --- interactive.c 1999/08/28 00:14:05 1.8 +++ interactive.c 1999/10/10 18:34:29 @@ -325,12 +325,11 @@ do { fprintf(stderr, "restore > "); (void) fflush(stderr); - (void) fgets(input, BUFSIZ, terminal); - } while (!feof(terminal) && input[0] == '\n'); - if (feof(terminal)) { - (void) strcpy(cmd, "quit"); - return; - } + if (fgets(input, BUFSIZ, terminal) == NULL) { + (void) strcpy(cmd, "quit"); + return; + } + } while (input[0] == '\n'); for (cp = &input[strlen(input) - 2]; *cp == ' ' || *cp == '\t'; cp--) /* trim off trailing white space and newline */; *++cp = '\0'; >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199910102021.aa25552>