d8307d
commit a6c1ce778e5c05a2e6925883b410157ef47654fd
d8307d
Author: Alexandra Hájková <ahajkova@redhat.com>
d8307d
Date:   Mon Aug 5 13:18:57 2019 +0200
d8307d
d8307d
    elf: tst-ldconfig-bad-aux-cache: use support_capture_subprocess
d8307d
d8307d
diff --git a/elf/tst-ldconfig-bad-aux-cache.c b/elf/tst-ldconfig-bad-aux-cache.c
d8307d
index 68ce90a95648f6ab..6e22ff815eaaa817 100644
d8307d
--- a/elf/tst-ldconfig-bad-aux-cache.c
d8307d
+++ b/elf/tst-ldconfig-bad-aux-cache.c
d8307d
@@ -31,6 +31,7 @@
d8307d
 #include <ftw.h>
d8307d
 #include <stdint.h>
d8307d
 
d8307d
+#include <support/capture_subprocess.h>
d8307d
 #include <support/check.h>
d8307d
 #include <support/support.h>
d8307d
 #include <support/xunistd.h>
d8307d
@@ -52,6 +53,15 @@ display_info (const char *fpath, const struct stat *sb,
d8307d
   return 0;
d8307d
 }
d8307d
 
d8307d
+static void
d8307d
+execv_wrapper (void *args)
d8307d
+{
d8307d
+  char **argv = args;
d8307d
+
d8307d
+  execv (argv[0], argv);
d8307d
+  FAIL_EXIT1 ("execv: %m");
d8307d
+}
d8307d
+
d8307d
 /* Run ldconfig with a corrupt aux-cache, in particular we test for size
d8307d
    truncation that might happen if a previous ldconfig run failed or if
d8307d
    there were storage or power issues while we were writing the file.
d8307d
@@ -61,53 +71,38 @@ static int
d8307d
 do_test (void)
d8307d
 {
d8307d
   char *prog = xasprintf ("%s/ldconfig", support_install_rootsbindir);
d8307d
-  char *const args[] = { prog, NULL };
d8307d
+  char *args[] = { prog, NULL };
d8307d
   const char *path = "/var/cache/ldconfig/aux-cache";
d8307d
   struct stat64 fs;
d8307d
   long int size, new_size, i;
d8307d
-  int status;
d8307d
-  pid_t pid;
d8307d
 
d8307d
   /* Create the needed directories. */
d8307d
   xmkdirp ("/var/cache/ldconfig", 0777);
d8307d
 
d8307d
-  pid = xfork ();
d8307d
-  /* Run ldconfig fist to generate the aux-cache.  */
d8307d
-  if (pid == 0)
d8307d
-    {
d8307d
-      execv (args[0], args);
d8307d
-      _exit (1);
d8307d
-    }
d8307d
-  else
d8307d
+  /* Run ldconfig first to generate the aux-cache.  */
d8307d
+  struct support_capture_subprocess result;
d8307d
+  result = support_capture_subprocess (execv_wrapper, args);
d8307d
+  support_capture_subprocess_check (&result, "execv", 0, sc_allow_none);
d8307d
+  support_capture_subprocess_free (&result);
d8307d
+
d8307d
+  xstat (path, &fs);
d8307d
+
d8307d
+  size = fs.st_size;
d8307d
+  /* Run 3 tests, each truncating aux-cache shorter and shorter.  */
d8307d
+  for (i = 3; i > 0; i--)
d8307d
     {
d8307d
-      xwaitpid (pid, &status, 0);
d8307d
-      TEST_COMPARE(status, 0);
d8307d
-      xstat (path, &fs);
d8307d
-
d8307d
-      size = fs.st_size;
d8307d
-      /* Run 3 tests, each truncating aux-cache shorter and shorter.  */
d8307d
-      for (i = 3; i > 0; i--)
d8307d
-        {
d8307d
-          new_size = size * i / 4;
d8307d
-          if (truncate (path, new_size))
d8307d
-              FAIL_EXIT1 ("truncation failed: %m");
d8307d
-          if (nftw (path, display_info, 1000, 0) == -1)
d8307d
-              FAIL_EXIT1 ("nftw failed.");
d8307d
-
d8307d
-          pid = xfork ();
d8307d
-          /* Verify that ldconfig can run with a truncated
d8307d
-             aux-cache and doesn't crash.  */
d8307d
-          if (pid == 0)
d8307d
-            {
d8307d
-              execv (args[0], args);
d8307d
-              _exit (1);
d8307d
-            }
d8307d
-          else
d8307d
-            {
d8307d
-              xwaitpid (pid, &status, 0);
d8307d
-              TEST_COMPARE(status, 0);
d8307d
-            }
d8307d
-        }
d8307d
+      new_size = size * i / 4;
d8307d
+      if (truncate (path, new_size))
d8307d
+        FAIL_EXIT1 ("truncation failed: %m");
d8307d
+      if (nftw (path, display_info, 1000, 0) == -1)
d8307d
+        FAIL_EXIT1 ("nftw failed.");
d8307d
+
d8307d
+      /* Verify that ldconfig can run with a truncated
d8307d
+         aux-cache and doesn't crash.  */
d8307d
+      struct support_capture_subprocess result;
d8307d
+      result = support_capture_subprocess (execv_wrapper, args);
d8307d
+      support_capture_subprocess_check (&result, "execv", 0, sc_allow_none);
d8307d
+      support_capture_subprocess_free (&result);
d8307d
     }
d8307d
 
d8307d
   free (prog);