From patchwork Thu Aug 1 15:59:14 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: 1140568 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-104105-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="Dena4oHl"; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="QE4QOHEn"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 45zw386Q06z9sDQ for ; Fri, 2 Aug 2019 01:59:32 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id :mime-version:content-type:content-transfer-encoding; q=dns; s= default; b=BR37brUQn48Q1Nb21jXuPA/iDi9lmwIXgV2aWU2qPwQRAMnDouHe5 zF1baSq2FuCQN0RCAr8WPGQ+/0t3EGehYXi0cxILUySZcyRmyXiT3NJVI2aplNm1 UpsQzY6di+/iGJNX9ZCRpGugdJEHxgQgY+Ye5/up2Ydm2yJkt6VavY= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id :mime-version:content-type:content-transfer-encoding; s=default; bh=IuqHGFYwFHtetQmKqceiSO80ysA=; b=Dena4oHlkdi0y6gRUIvuyP3zNFhj yOmaxlAn4kX/nDpdUaaBK2jcuzSo/DOBdK2FE7eTtXeJ8wTbTHIvr2YMg0uz3gJX WPcBwAeflQBAWdOgcaKkydq5mrpt+3o9VPN1OAdsiXBNnR42KH7vtfiolmjPWVfH 3PLRIcGe37pI7mY= Received: (qmail 46923 invoked by alias); 1 Aug 2019 15:59:26 -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 46914 invoked by uid 89); 1 Aug 2019 15:59:25 -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= 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=wjMDt4R5L1y0WvbAyBIhqSAAAtYZTG1pmyEUI6EvMEU=; b=QE4QOHEnu4teskNhDnJ/cmjOW56EOaK1h8U3jZ/DozrgROY9ZiQl8KVVTnBKfeWCyG l1MYPH7dQNi9pzQj/H3HjMLZk9NDmO/K13ggqRMyNcb06fX/owWtMbc4RNHqhDcZwW3s vIFf1apMv0NL78XMHp5uUBQQimUL00q0x5tTIJnbRayxx1TW8rvvL2iEFiuiYn08GUeo 2dxbfjMnQ5G0BSO5YLJobDKpFjX2B39Bk1dkqsdrlI7CfAY95BayptTN31DC2zdE+G9r 9jf4GMkOtNyGPmhJgjlCC+m+3isQj9mSOJ83CQcPZQwBWYCDfu58Jdmyrwi5DOpesVl7 q7tw== From: =?utf-8?q?Alexandra_H=C3=A1jkov=C3=A1?= To: libc-alpha@sourceware.org Cc: =?utf-8?q?Alexandra_H=C3=A1jkov=C3=A1?= Subject: [PATCH v2] elf: tst-ldconfig-bad-aux-cache: use support_capture_subprocess Date: Thu, 1 Aug 2019 17:59:14 +0200 Message-Id: <20190801155914.13528-1-ahajkova@redhat.com> MIME-Version: 1.0 From: Alexandra Hájková --- elf/tst-ldconfig-bad-aux-cache.c | 71 ++++++++++++++------------------ 1 file changed, 31 insertions(+), 40 deletions(-) diff --git a/elf/tst-ldconfig-bad-aux-cache.c b/elf/tst-ldconfig-bad-aux-cache.c index 68ce90a956..0c4d9830ea 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,13 @@ display_info (const char *fpath, const struct stat *sb, return 0; } +static void +execv_wrapper(void *args) +{ + execv (((char **)args)[0], (char **)args); + 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,54 +69,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;