From 96f1209ea7d2b1f7cd44325314fbe6d63004465d Mon Sep 17 00:00:00 2001 From: Michael Meffie Date: Wed, 18 Aug 2021 14:09:23 -0400 Subject: [PATCH] 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 Reviewed-by: Marcio Brito Barbosa Tested-by: BuildBot Reviewed-by: Andrew Deason --- src/volser/vos.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/volser/vos.c b/src/volser/vos.c index a38c686e15..7a220736ec 100644 --- a/src/volser/vos.c +++ b/src/volser/vos.c @@ -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);