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