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