From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-x64a.google.com (mail-pl1-x64a.google.com [IPv6:2607:f8b0:4864:20::64a]) by sourceware.org (Postfix) with ESMTPS id 747A23858D33 for ; Mon, 13 Feb 2023 06:01:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 747A23858D33 Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=flex--vitalybuka.bounces.google.com Received: by mail-pl1-x64a.google.com with SMTP id j12-20020a170902da8c00b0019a8df175b2so2674945plx.23 for ; Sun, 12 Feb 2023 22:01:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=S5Fne35wzQ4z+HMf5styz7EG4IA/GQsHaYVw4wC14oQ=; b=Ldz/BFurHCmls2XCKI0WJKn4dYZspqFLCnKXIrETpvNWfyJjUKqtMlVHWQM9WZxvEU oi0MnLkr0cG9w5Uj+5H8V7jKsKXRPPR6s6SC8tGyMmZ+Z49t+DW2wrAXICd3/VnnY1qh gtUraUOX4+mVw3uRfGr4uyiPIKO3Qs/miOP2Cis59eEp2AMUWSs+hVPCDIEKsXbNo5e0 FErYQy4NTa9NKrzW3TySNdizk4jZHeC0IrhrRqNKPmy+/CIR8Nba1/WP8uv+lUc0kiQN JPzXQHDCxSK7t2a9sdgwR/pqQ8H6rCZh5vNGZWRjQ8JNsWgfJ80dgIRPv/j97oIbV7L1 SfrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=S5Fne35wzQ4z+HMf5styz7EG4IA/GQsHaYVw4wC14oQ=; b=Ggzifdw+QGKnK5TF23D4uJwrrtPuOiHuTUXd3QxoYGGOcTa9fXkUnHilWaPe7A1kv4 AWscFfTG5P+qqFWVwRC5TU3caTTlvJttn5v1zZuo03F7r0IN7M/sulNdbwkGLiym4a/+ 4qhNYYTnlCMepnYy5G+U3zht5WiRzO+rQyI/3ksiolsmhnquOnXFYE2WGMWFEmNskkiy qa00yKuXGmF0OSZ1sivyZqhRj7xGjO+aTQDN9rlvkOGFIuBtxc5EPb1t17O7n2THoqVr VQBwskNPKzBe2jtyKlgpASS0qpzFkZs0CwF9pK54IxX8geukjEOhTQTiqMCr13fz6zZJ B0mg== X-Gm-Message-State: AO0yUKWRIwS9HgJmOooUuwk3nllxyHR3DXUB/xUH7dhjxG9Af+CzmRC/ Pxp9N44zxIRewrT383qMeMErWJTtrd7iLwi6o6o2iAN7v5XV2hrxkR8D9Kbnkzg9fQ0YPebIdCT ggmYevTrRyaJJ/TROaQbOq/oJauoC4MDVKMXJCZRROmclDmt5Ukg/DzARg5DUd4036upIbOxMmn rd X-Google-Smtp-Source: AK7set8fGe2zFrOzZmWzAmp1bJ+JDUUu2gJQ6S5L91JVyx/oxSLAFIyfSKGmCTVGHfwm9AhRCsJDP1Jvn/uqgq09 X-Received: from vvv.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:56c]) (user=vitalybuka job=sendgmr) by 2002:a17:90b:2342:b0:233:cb22:9790 with SMTP id ms2-20020a17090b234200b00233cb229790mr1226450pjb.29.1676268080416; Sun, 12 Feb 2023 22:01:20 -0800 (PST) Date: Sun, 12 Feb 2023 22:01:17 -0800 In-Reply-To: <0a4a8828-ed9a-66d4-f65c-f2f386768bdb@prevas.dk> Mime-Version: 1.0 References: <0a4a8828-ed9a-66d4-f65c-f2f386768bdb@prevas.dk> X-Mailer: git-send-email 2.39.1.581.gbfd45094c4-goog Message-ID: <20230213060117.3193783-1-vitalybuka@google.com> Subject: [PATCH] stdlib: Undo post review change to 16adc58e73f3 [BZ #27749] From: Vitaly Buka To: libc-alpha@sourceware.org Cc: Rasmus Villemoes , Adhemerval Zanella , Vitaly Buka Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-20.3 required=5.0 tests=BAYES_00,DKIMWL_WL_MED,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,USER_IN_DEF_DKIM_WL 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: Post review removal of "goto restart" from https://sourceware.org/pipermail/libc-alpha/2021-April/125470.html introduced a bug when some atexit handers skipped. Signed-off-by: Vitaly Buka --- stdlib/Makefile | 1 + stdlib/exit.c | 7 +++- stdlib/test-atexit-recursive.c | 72 ++++++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 stdlib/test-atexit-recursive.c diff --git a/stdlib/Makefile b/stdlib/Makefile index 83391d00c1..8f80571d76 100644 --- a/stdlib/Makefile +++ b/stdlib/Makefile @@ -171,6 +171,7 @@ tests := \ test-a64l \ test-at_quick_exit-race \ test-atexit-race \ + test-atexit-recursive \ test-bz22786 \ test-canon \ test-canon2 \ diff --git a/stdlib/exit.c b/stdlib/exit.c index 6b1eed6445..1cd0bdfe94 100644 --- a/stdlib/exit.c +++ b/stdlib/exit.c @@ -51,7 +51,10 @@ __run_exit_handlers (int status, struct exit_function_list **listp, exit (). */ while (true) { - struct exit_function_list *cur = *listp; + struct exit_function_list *cur; + + restart: + cur = *listp; if (cur == NULL) { @@ -113,7 +116,7 @@ __run_exit_handlers (int status, struct exit_function_list **listp, if (__glibc_unlikely (new_exitfn_called != __new_exitfn_called)) /* The last exit function, or another thread, has registered more exit functions. Start the loop over. */ - continue; + goto restart; } *listp = cur->next; diff --git a/stdlib/test-atexit-recursive.c b/stdlib/test-atexit-recursive.c new file mode 100644 index 0000000000..ca832941fe --- /dev/null +++ b/stdlib/test-atexit-recursive.c @@ -0,0 +1,72 @@ +/* Support file for atexit/exit, etc. race tests (BZ #27749). + Copyright (C) 2021-2023 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +/* Check that atexit handler registed from another handler still called. */ + +#include +#include +#include +#include +#include +#include + +static void +atexit_cb (void) { +} + +static void +atexit_last (void) { + _exit (1); +} + +static void +atexit_recursive (void) { + atexit(&atexit_cb); + atexit(&atexit_last); +} + +_Noreturn static void +test_and_exit (int count) +{ + for (int i = 0; i < count; ++i) + atexit(&atexit_cb); + atexit(&atexit_recursive); + exit (0); +} + +static int +do_test (void) +{ + for (int i = 0; i < 100; ++i) + if (xfork () == 0) + test_and_exit (i); + + for (int i = 0; i < 100; ++i) + { + int status; + xwaitpid (0, &status, 0); + if (!WIFEXITED (status)) + FAIL_EXIT1 ("Failed iterations %d", i); + TEST_COMPARE (WEXITSTATUS (status), 1); + } + + return 0; +} + +#define TEST_FUNCTION do_test +#include -- 2.39.1.581.gbfd45094c4-goog