From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) by sourceware.org (Postfix) with ESMTPS id 55E383858C41 for ; Wed, 27 Sep 2023 19:20:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 55E383858C41 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-693375d2028so1855630b3a.2 for ; Wed, 27 Sep 2023 12:20:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1695842418; x=1696447218; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=894z+Dl1Hf854xBwuLknTFLA3TI283fAgAFIlysXXk4=; b=GCxDLLmRNAZF2aCuuOp5zAq/sxufZxipEnQQ8LQzgewP6Ay6Gdf37cx/kXbu2XPv0E 7bz0CgaseFCwmVAstoVhZl2GScu1pGRvNFfhigdeVZZRn/cq+cuT47Efy3F3XbeJCA+g X8FiwqHKcCv0XDOr4KK4aqbK1uJV6TX1ppxJaJw84heShdXYYXGr5ArwoNJHJEfXKZRo sFSF5a1JkHPAMPeUAcTJoFkYCMptsGwHNyplyxsrUw4IIKKWcOe+3pP+wDkytLmaizl7 7GTsZiCbi48obDIu6f64RuIrZxYd3TWLBZHSSLQFjelrBbfK4yE0Ld80nGAP58U3GJWO ftcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695842418; x=1696447218; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=894z+Dl1Hf854xBwuLknTFLA3TI283fAgAFIlysXXk4=; b=DrOpuLzTbL3LRnwz2lux6rMMkl/sTpWcO5OdsFVp8FXBjLe2ndCBtqyniqaYSh/rk6 LPfBTU1PlsDyQNbWjczmDk3/meWCBph0IoNlxfDYxJWSGXIzq8FjGqFEPmXCEbna9tF6 db6HG/VIbAuGmMVVcpTBi1ngI9dCBuBtyQMp83rdSbovwMdwFvWkAIJnzmqH5HZASm/a UsBRzlX1SjIHb8Ws0qaqAVuTkP35YocA1mx6IwB9hGudFCSsMXSlMLwKuxY3hCZBLHO0 O/S41Vt3HErD6+Dp4XFx0T4nCdyKUe33M4NA0Ha/gsc1Ud+OWx/LjmKSNZRPRYzm0tMk cpyw== X-Gm-Message-State: AOJu0Yz6J4dHfTOSPq+LnCFxPUetoTp7iK5Ix3OOmLJyPY+6uddazgiE lZLb8w9279celPYzs9Vt7z1e0BnpzWcGs5ExHYZcCw== X-Google-Smtp-Source: AGHT+IFVq3ZrnMFKxrzxeB7ZpXGxDvedDteJEzrE+kB3Bx84w4fkZh30CDjB4oNMQ8aU+mzNVGws2g== X-Received: by 2002:a05:6a20:9699:b0:14d:7511:1c2 with SMTP id hp25-20020a056a20969900b0014d751101c2mr2550569pzc.55.1695842417600; Wed, 27 Sep 2023 12:20:17 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c1:6eb0:7f09:2e60:f05d:65ef]) by smtp.gmail.com with ESMTPSA id h16-20020aa786d0000000b0068fb8080939sm1600888pfo.65.2023.09.27.12.20.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 12:20:17 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org, Siddhesh Poyarekar Subject: [PATCH] test-container: Use nftw instead of rm -rf Date: Wed, 27 Sep 2023 16:20:13 -0300 Message-Id: <20230927192013.2071605-1-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: If the binary to run is 'env', test-containers skips it and adds any required environment variable on the process envs variables. This simplifies the required code to spawn new process (no need to build an env-like program). However, this is an issue for recursive_remove if there is any LD_PRELOAD, since test-container will not prepend the loader command along with required paths. If the required preloaded library can not be loaded by the system glibc, the 'post-clean rsync' will eventually fail. One example is if system glibc does not support DT_RELR and the built glibc does, the nss/tst-nss-gai-hv2-canonname test fails with: ../scripts/evaluate-test.sh nss/tst-nss-gai-hv2-canonname $? false false 86_64-linux-gnu/nss/tst-nss-gai-hv2-canonname.test-result rm: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_ABI_DT_RELR' not found (required by x86_64-linux-gnu/malloc/libc_malloc_debug.so) Instead trying to figure out the required loader arguments on how to spawn the 'rm -rf', replace the command with a nftw call. Checked on x86_64-linux-gnu. --- support/test-container.c | 34 +++++++++++----------------------- 1 file changed, 11 insertions(+), 23 deletions(-) diff --git a/support/test-container.c b/support/test-container.c index 788b091ea0..95dfef1a99 100644 --- a/support/test-container.c +++ b/support/test-container.c @@ -37,6 +37,7 @@ #include #include #include +#include #ifdef __linux__ #include @@ -405,32 +406,19 @@ file_exists (char *path) return 0; } +static int +unlink_cb (const char *fpath, const struct stat *sb, int typeflag, + struct FTW *ftwbuf) +{ + return remove (fpath); +} + static void recursive_remove (char *path) { - pid_t child; - int status; - - child = fork (); - - switch (child) { - case -1: - perror("fork"); - FAIL_EXIT1 ("Unable to fork"); - case 0: - /* Child. */ - execlp ("rm", "rm", "-rf", path, NULL); - FAIL_EXIT1 ("exec rm: %m"); - default: - /* Parent. */ - waitpid (child, &status, 0); - /* "rm" would have already printed a suitable error message. */ - if (! WIFEXITED (status) - || WEXITSTATUS (status) != 0) - FAIL_EXIT1 ("exec child returned status: %d", status); - - break; - } + int r = nftw (path, unlink_cb, 1000, FTW_DEPTH | FTW_PHYS); + if (r == -1) + FAIL_EXIT1 ("recursive_remove failed"); } /* Used for both rsync and the mytest.script "cp" command. */ -- 2.34.1