copy-blockdev: Fix progress printing 29/320429/3
authora.adaszkiewi <a.adaszkiewi@samsung.com>
Fri, 28 Feb 2025 12:31:32 +0000 (13:31 +0100)
committera.adaszkiewi <a.adaszkiewi@samsung.com>
Fri, 28 Feb 2025 14:59:43 +0000 (15:59 +0100)
Upgrade progress status is set by calling a binary in a child process.
Its output messes with that of the parent.

Change-Id: I9b73c129e35b57d955183f3298ad76db17b2f1a0

src/copy-blockdev/lib.c

index bbd6a97451f00badee85c77c80c4b57b243fa2a3..fab5d8eda1b609669799821e8623beb59c70966c 100644 (file)
@@ -253,6 +253,14 @@ static int set_upgrade_progress_status(int progress)
     }
 
     if (pid == 0) {
+        // The binary we are about to launch prints unnecessary stuff to stdout
+        int fd;
+        if (((fd = open("/dev/null", O_WRONLY)) < 0) || (dup2(fd, STDOUT_FILENO) < 0)
+                || (close(fd) < 0)) {
+            fprintf(stderr, "Child failed to redirect stdout\n");
+            exit(EXIT_FAILURE);
+        }
+
         // Max value for progress is 100
         char buf[4];
         snprintf(buf, sizeof(buf), "%d", progress);