public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
* [glibc] elf: tst-ldconfig-bad-aux-cache: use support_capture_subprocess
@ 2019-08-05 11:19 Alexandra Hajkova
0 siblings, 0 replies; only message in thread
From: Alexandra Hajkova @ 2019-08-05 11:19 UTC (permalink / raw)
To: glibc-cvs
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="us-ascii", Size: 4123 bytes --]
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=a6c1ce778e5c05a2e6925883b410157ef47654fd
commit a6c1ce778e5c05a2e6925883b410157ef47654fd
Author: Alexandra Hájková <ahajkova@redhat.com>
Date: Mon Aug 5 13:18:57 2019 +0200
elf: tst-ldconfig-bad-aux-cache: use support_capture_subprocess
Diff:
---
ChangeLog | 4 +++
elf/tst-ldconfig-bad-aux-cache.c | 73 +++++++++++++++++++---------------------
2 files changed, 38 insertions(+), 39 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 55e964b..a67110e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2019-08-05 Alexandra Hajkova <ahajkova@redhat.com>
+
+ * elf/tst-ldconfig-bad-aux-cache.c: Use support_capture_subprocess.
+
2019-08-02 Joseph Myers <joseph@codesourcery.com>
* sysdeps/unix/sysv/linux/syscall-names.list: Update comment.
diff --git a/elf/tst-ldconfig-bad-aux-cache.c b/elf/tst-ldconfig-bad-aux-cache.c
index 68ce90a..6e22ff8 100644
--- a/elf/tst-ldconfig-bad-aux-cache.c
+++ b/elf/tst-ldconfig-bad-aux-cache.c
@@ -31,6 +31,7 @@
#include <ftw.h>
#include <stdint.h>
+#include <support/capture_subprocess.h>
#include <support/check.h>
#include <support/support.h>
#include <support/xunistd.h>
@@ -52,6 +53,15 @@ display_info (const char *fpath, const struct stat *sb,
return 0;
}
+static void
+execv_wrapper (void *args)
+{
+ char **argv = args;
+
+ execv (argv[0], argv);
+ FAIL_EXIT1 ("execv: %m");
+}
+
/* Run ldconfig with a corrupt aux-cache, in particular we test for size
truncation that might happen if a previous ldconfig run failed or if
there were storage or power issues while we were writing the file.
@@ -61,53 +71,38 @@ static int
do_test (void)
{
char *prog = xasprintf ("%s/ldconfig", support_install_rootsbindir);
- char *const args[] = { prog, NULL };
+ char *args[] = { prog, NULL };
const char *path = "/var/cache/ldconfig/aux-cache";
struct stat64 fs;
long int size, new_size, i;
- int status;
- pid_t pid;
/* Create the needed directories. */
xmkdirp ("/var/cache/ldconfig", 0777);
- pid = xfork ();
- /* Run ldconfig fist to generate the aux-cache. */
- if (pid == 0)
- {
- execv (args[0], args);
- _exit (1);
- }
- else
+ /* Run ldconfig first to generate the aux-cache. */
+ struct support_capture_subprocess result;
+ result = support_capture_subprocess (execv_wrapper, args);
+ support_capture_subprocess_check (&result, "execv", 0, sc_allow_none);
+ support_capture_subprocess_free (&result);
+
+ xstat (path, &fs);
+
+ size = fs.st_size;
+ /* Run 3 tests, each truncating aux-cache shorter and shorter. */
+ for (i = 3; i > 0; i--)
{
- xwaitpid (pid, &status, 0);
- TEST_COMPARE(status, 0);
- xstat (path, &fs);
-
- size = fs.st_size;
- /* Run 3 tests, each truncating aux-cache shorter and shorter. */
- for (i = 3; i > 0; i--)
- {
- new_size = size * i / 4;
- if (truncate (path, new_size))
- FAIL_EXIT1 ("truncation failed: %m");
- if (nftw (path, display_info, 1000, 0) == -1)
- FAIL_EXIT1 ("nftw failed.");
-
- pid = xfork ();
- /* Verify that ldconfig can run with a truncated
- aux-cache and doesn't crash. */
- if (pid == 0)
- {
- execv (args[0], args);
- _exit (1);
- }
- else
- {
- xwaitpid (pid, &status, 0);
- TEST_COMPARE(status, 0);
- }
- }
+ new_size = size * i / 4;
+ if (truncate (path, new_size))
+ FAIL_EXIT1 ("truncation failed: %m");
+ if (nftw (path, display_info, 1000, 0) == -1)
+ FAIL_EXIT1 ("nftw failed.");
+
+ /* Verify that ldconfig can run with a truncated
+ aux-cache and doesn't crash. */
+ struct support_capture_subprocess result;
+ result = support_capture_subprocess (execv_wrapper, args);
+ support_capture_subprocess_check (&result, "execv", 0, sc_allow_none);
+ support_capture_subprocess_free (&result);
}
free (prog);
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2019-08-05 11:19 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-05 11:19 [glibc] elf: tst-ldconfig-bad-aux-cache: use support_capture_subprocess Alexandra Hajkova
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).