vos: Check for tty in vos restore

Currently, vos restore assumes the dump stream is provided via stdin
when the -file option is not specified and does not check to see if
stdin is a tty.

When restoring over an existing volume and the -overwrite is not
specified, vos will try to prompt the user for the overwrite mode
(incremental, full, or abort). Currently, vos will not prompt the user
if the -file option is also absent, since the assumption is the dump is
to be read from stdin.

Instead, read the dump from stdin only when the -file option is absent
and stdin is not a tty, and only prompt the user when stdin is a tty.

This prevents vos restore from hanging when a dump file was not given
with the -file option, a pipeline, or a redirect.

This change also removes the use of the dump "afilename" variable to
determine if an interactive mode should be used.

Change-Id: I33edb69c9c3c6f42fc2270c1c797be862ffa2773
Reviewed-on: https://gerrit.openafs.org/14760
Reviewed-by: Cheyenne Wills <cwills@sinenomine.net>
Reviewed-by: Marcio Brito Barbosa <mbarbosa@sinenomine.net>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Andrew Deason <adeason@sinenomine.net>
This commit is contained in:
Michael Meffie 2021-08-18 14:09:23 -04:00 committed by Andrew Deason
parent a0b0f4bea9
commit 96f1209ea7

View File

@ -3164,6 +3164,10 @@ RestoreVolumeCmd(struct cmd_syndesc *as, void *arock)
exit(1);
}
} else {
if (isatty(STDIN_FILENO)) {
fprintf(STDERR, "Can't read dump from tty.\n");
exit(1);
}
strcpy(afilename, "");
}
@ -3225,7 +3229,7 @@ RestoreVolumeCmd(struct cmd_syndesc *as, void *arock)
vol_elsewhere = 1;
if (aoverwrite == OVERWRITE_ASK) {
if (strcmp(afilename, "") == 0) { /* The file is from standard in */
if (!isatty(STDIN_FILENO)) {
fprintf(STDERR,
"Volume exists and no -overwrite option specified; Aborting restore command\n");
exit(1);