lib/deploy: Really close testing race condition
authorColin Walters <walters@verbum.org>
Wed, 16 Aug 2017 16:18:22 +0000 (12:18 -0400)
committerAtomic Bot <atomic-devel@projectatomic.io>
Wed, 16 Aug 2017 18:01:04 +0000 (18:01 +0000)
I added `waitpid()`, but that didn't actually help because we were
`daemon()`izing. Don't daemonize if we're testing so that we can `waitpid()`.

Note I still haven't reproduced this race locally, but I'm pretty sure this will
fix it.

While here, actually check the return value from `waitpid()` just in case
something goes wrong there.

Closes: #1084
Approved by: jlebon

src/libostree/ostree-sysroot-deploy.c

index 18624640890bd53bc942600efd990e1e9159fa4d..cb84a87f16bf223de727e44f8171e7dd0738c024 100644 (file)
@@ -1020,10 +1020,14 @@ fsfreeze_thaw_cycle (OstreeSysroot *self,
       (void) close (glnx_steal_fd (&sock_parent));
       /* Daemonize, and mask SIGINT/SIGTERM, so we're likely to survive e.g.
        * someone doing a `systemctl restart rpm-ostreed` or a Ctrl-C of
-       * `ostree admin upgrade`.
+       * `ostree admin upgrade`.  We don't daemonize though if testing so
+       * that we can waitpid().
        */
-      if (daemon (0, debug_fifreeze ? 1 : 0) < 0)
-        err (1, "daemon");
+      if (!debug_fifreeze)
+        {
+          if (daemon (0, 0) < 0)
+            err (1, "daemon");
+        }
       int sigs[] = { SIGINT, SIGTERM };
       for (guint i = 0; i < G_N_ELEMENTS (sigs); i++)
         {
@@ -1086,7 +1090,10 @@ fsfreeze_thaw_cycle (OstreeSysroot *self,
         {
           int wstatus;
           /* Ensure the child has written its data */
-          (void) TEMP_FAILURE_RETRY (waitpid (pid, &wstatus, 0));
+          if (TEMP_FAILURE_RETRY (waitpid (pid, &wstatus, 0)) < 0)
+            return glnx_throw_errno_prefix (error, "waitpid(test-fifreeze)");
+          if (!g_spawn_check_exit_status (wstatus, error))
+            return glnx_prefix_error (error, "test-fifreeze: ");
           return glnx_throw (error, "aborting due to test-fifreeze");
         }
       /* Do a freeze/thaw cycle; TODO add a FIFREEZETHAW ioctl */