From patchwork Thu Aug 1 14:47:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alexandra_H=C3=A1jkov=C3=A1?= X-Patchwork-Id: 33893 Received: (qmail 60343 invoked by alias); 1 Aug 2019 14:47:35 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 60012 invoked by uid 89); 1 Aug 2019 14:47:35 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=alexandra, HContent-Transfer-Encoding:8bit X-HELO: mail-wr1-f67.google.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=QfXGcKr0a5f4sAZpQTMZT6jZ8lLMxXM70VNQ3VCg1H0=; b=jGvDDW9Tdco7uVvl7ygFYaZDQi8wJ8qjrQhEZ1jLnf/q4bFU3lvopIsd80Zsr9CYpD tNx75UEQ9ZFJ+Q7SD7RJLvJSPNUrcBf5RYcDAlccBqZs5DxGZD7ztfh4TI5bzwFB7PTT 4MmueaWwbLfDzGBBoQPrCS3SPEhw/or4T7swYl52FonZwiUWSPhG3rre/7YEiBERyb8A cLOR85gNUk0qOUfceMmHnhQkgDhz+dtTx5YZ8yokSUnnmnLAo7+yAureVublNTV//zpd Pt1P/KVyvCPCA6aTLPhA6DjXx7qMPJzsUCSci7H7bizgBcQ3126HkmJ4mTL1Kpvuwh6Y pXiw== Return-Path: From: =?UTF-8?Q?Alexandra_H=C3=A1jkov=C3=A1?= To: libc-alpha@sourceware.org Cc: =?UTF-8?q?Alexandra=20H=C3=A1jkov=C3=A1?= Subject: [PATCH] elf: tst-ldconfig-bad-aux-cache: use support_capture_subprocess Date: Thu, 1 Aug 2019 16:47:13 +0200 Message-Id: <20190801144713.12287-1-ahajkova@redhat.com> MIME-Version: 1.0 From: Alexandra Hájková --- elf/tst-ldconfig-bad-aux-cache.c | 70 ++++++++++++++------------------ 1 file changed, 30 insertions(+), 40 deletions(-) diff --git a/elf/tst-ldconfig-bad-aux-cache.c b/elf/tst-ldconfig-bad-aux-cache.c index 68ce90a956..45b1010b20 100644 --- a/elf/tst-ldconfig-bad-aux-cache.c +++ b/elf/tst-ldconfig-bad-aux-cache.c @@ -31,6 +31,7 @@ #include #include +#include #include #include #include @@ -52,6 +53,12 @@ display_info (const char *fpath, const struct stat *sb, return 0; } +static void +execv_wrapper(void *args) +{ + execv(((char **)args)[0], (char **)args); +} + /* 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,54 +68,37 @@ 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 - { - 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); - } - } - } + struct support_capture_subprocess result; + result = support_capture_subprocess (execv_wrapper, args); + support_capture_subprocess_check (&result, "execv", 0, sc_allow_none); + + 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."); + + /* 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); + } free (prog); return 0;