elf: tst-ldconfig-bad-aux-cache: use support_capture_subprocess

This commit is contained in:
Alexandra Hájková 2019-08-05 13:18:57 +02:00
parent 9c37bde5a2
commit a6c1ce778e
2 changed files with 37 additions and 38 deletions

View File

@ -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> 2019-08-02 Joseph Myers <joseph@codesourcery.com>
* sysdeps/unix/sysv/linux/syscall-names.list: Update comment. * sysdeps/unix/sysv/linux/syscall-names.list: Update comment.

View File

@ -31,6 +31,7 @@
#include <ftw.h> #include <ftw.h>
#include <stdint.h> #include <stdint.h>
#include <support/capture_subprocess.h>
#include <support/check.h> #include <support/check.h>
#include <support/support.h> #include <support/support.h>
#include <support/xunistd.h> #include <support/xunistd.h>
@ -52,6 +53,15 @@ display_info (const char *fpath, const struct stat *sb,
return 0; 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 /* 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 truncation that might happen if a previous ldconfig run failed or if
there were storage or power issues while we were writing the file. there were storage or power issues while we were writing the file.
@ -61,27 +71,20 @@ static int
do_test (void) do_test (void)
{ {
char *prog = xasprintf ("%s/ldconfig", support_install_rootsbindir); 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"; const char *path = "/var/cache/ldconfig/aux-cache";
struct stat64 fs; struct stat64 fs;
long int size, new_size, i; long int size, new_size, i;
int status;
pid_t pid;
/* Create the needed directories. */ /* Create the needed directories. */
xmkdirp ("/var/cache/ldconfig", 0777); xmkdirp ("/var/cache/ldconfig", 0777);
pid = xfork (); /* Run ldconfig first to generate the aux-cache. */
/* Run ldconfig fist to generate the aux-cache. */ struct support_capture_subprocess result;
if (pid == 0) result = support_capture_subprocess (execv_wrapper, args);
{ support_capture_subprocess_check (&result, "execv", 0, sc_allow_none);
execv (args[0], args); support_capture_subprocess_free (&result);
_exit (1);
}
else
{
xwaitpid (pid, &status, 0);
TEST_COMPARE(status, 0);
xstat (path, &fs); xstat (path, &fs);
size = fs.st_size; size = fs.st_size;
@ -94,20 +97,12 @@ do_test (void)
if (nftw (path, display_info, 1000, 0) == -1) if (nftw (path, display_info, 1000, 0) == -1)
FAIL_EXIT1 ("nftw failed."); FAIL_EXIT1 ("nftw failed.");
pid = xfork ();
/* Verify that ldconfig can run with a truncated /* Verify that ldconfig can run with a truncated
aux-cache and doesn't crash. */ aux-cache and doesn't crash. */
if (pid == 0) struct support_capture_subprocess result;
{ result = support_capture_subprocess (execv_wrapper, args);
execv (args[0], args); support_capture_subprocess_check (&result, "execv", 0, sc_allow_none);
_exit (1); support_capture_subprocess_free (&result);
}
else
{
xwaitpid (pid, &status, 0);
TEST_COMPARE(status, 0);
}
}
} }
free (prog); free (prog);