]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
export-tar: check tar result as well
authorLennart Poettering <lennart@poettering.net>
Fri, 26 Oct 2018 16:02:09 +0000 (18:02 +0200)
committerLennart Poettering <lennart@poettering.net>
Mon, 26 Nov 2018 17:09:01 +0000 (18:09 +0100)
Let's make sure we properly notice when tar doesn't actually work: let's
propagate the error.

src/import/export-tar.c

index 5acb09432a69ea4537546277df108d2021df6a47..3aab390637a4c1e890cd58a7ea13e70d15f78d9e 100644 (file)
@@ -141,6 +141,26 @@ static void tar_export_report_progress(TarExport *e) {
         e->last_percent = percent;
 }
 
+static int tar_export_finish(TarExport *e) {
+        int r;
+
+        assert(e);
+        assert(e->tar_fd >= 0);
+
+        if (e->tar_pid > 0) {
+                r = wait_for_terminate_and_check("tar", e->tar_pid, WAIT_LOG);
+                e->tar_pid = 0;
+                if (r < 0)
+                        return r;
+                if (r != EXIT_SUCCESS)
+                        return -EPROTO;
+        }
+
+        e->tar_fd = safe_close(e->tar_fd);
+
+        return 0;
+}
+
 static int tar_export_process(TarExport *e) {
         ssize_t l;
         int r;
@@ -156,7 +176,7 @@ static int tar_export_process(TarExport *e) {
 
                         e->tried_splice = true;
                 } else if (l == 0) {
-                        r = 0;
+                        r = tar_export_finish(e);
                         goto finish;
                 } else {
                         e->written_uncompressed += l;
@@ -172,7 +192,7 @@ static int tar_export_process(TarExport *e) {
                 uint8_t input[COPY_BUFFER_SIZE];
 
                 if (e->eof) {
-                        r = 0;
+                        r = tar_export_finish(e);
                         goto finish;
                 }