Przeglądaj źródła

restore: improve error handling

Olivier MEDOC 10 lat temu
rodzic
commit
42c40d399b
2 zmienionych plików z 18 dodań i 14 usunięć
  1. 10 9
      qubes-rpc/qubes.Restore
  2. 8 5
      qubes-rpc/tar2qfile.c

+ 10 - 9
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
+

+ 8 - 5
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);
 	}