From 42c40d399b76f08e0c99af7de3077d2aecc50845 Mon Sep 17 00:00:00 2001 From: Olivier MEDOC Date: Tue, 19 Nov 2013 13:35:51 +0100 Subject: [PATCH] restore: improve error handling --- qubes-rpc/qubes.Restore | 19 ++++++++++--------- qubes-rpc/tar2qfile.c | 13 ++++++++----- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/qubes-rpc/qubes.Restore b/qubes-rpc/qubes.Restore index 4befc0d..d1f3303 100644 --- a/qubes-rpc/qubes.Restore +++ b/qubes-rpc/qubes.Restore @@ -1,21 +1,21 @@ -echo Starting Restorecopy >2 +echo Starting Restorecopy >&2 read args read paths -echo Arguments: $args >2 -echo Paths: $paths >2 +echo Arguments: $args >&2 +echo Paths: $paths >&2 if [ -f "$args" ] ; then - echo "Performing restore from backup file $args" >2 + echo "Performing restore from backup file $args" >&2 TARGET="$args" - echo "Copying $TARGET to STDOUT" >2 + echo "Copying $TARGET to STDOUT" >&2 /usr/lib/qubes/tar2qfile $TARGET $paths else - echo "Checking if arguments is matching a command" >2 + echo "Checking if arguments is matching a command" >&2 COMMAND=`echo $args | cut -d ' ' -f 1` TYPE=`type -t $COMMAND` if [ "$TYPE" == "file" ] ; then tmpdir=`mktemp -d` mkfifo $tmpdir/backup-data - echo "Redirecting $args to STDOUT" >2 + echo "Redirecting $args to STDOUT" >&2 # Parsing args to handle quotes correctly # Dangerous method if args are uncontrolled eval "set -- $args" @@ -28,7 +28,8 @@ else rmdir $tmpdir exit $retcode else - echo "Invalid command $COMMAND" >2 - exit 1 + echo "Invalid command $COMMAND" >&2 + exit 2 fi fi + diff --git a/qubes-rpc/tar2qfile.c b/qubes-rpc/tar2qfile.c index cd47d4f..cd27f3e 100644 --- a/qubes-rpc/tar2qfile.c +++ b/qubes-rpc/tar2qfile.c @@ -863,24 +863,27 @@ int main(int argc, char **argv) fprintf(stderr,"Parsing file %s\n",entry); fd = open(entry, O_RDONLY); - if (fd < 0) + if (fd < 0) { fprintf(stderr,"Error opening file %s\n",entry); + exit(2); + } // At least two arguments can be found in the command line // (process name and the file to extract) - tar_file_processor(fd, argc-2, argv[2]); + tar_file_processor(fd, argc, argv); + break; } } - if (i <= 1 || use_stdin == 1) { + if (use_stdin == 1) { // No argument specified. Use STDIN fprintf(stderr,"Using STDIN\n"); set_block(0); // If at least one argument has been found ( process name and - ) if (use_stdin) - tar_file_processor(fileno(stdin), argc-2, argv[2]); + tar_file_processor(fileno(stdin), argc, argv); else - tar_file_processor(fileno(stdin), argc-1, argv[1]); + tar_file_processor(fileno(stdin), argc, argv); }