From patchwork Mon Feb 13 06:01:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vitaly Buka X-Patchwork-Id: 64849 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 100043858C66 for ; Mon, 13 Feb 2023 06:01:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 100043858C66 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1676268104; bh=S5Fne35wzQ4z+HMf5styz7EG4IA/GQsHaYVw4wC14oQ=; h=Date:In-Reply-To:References:Subject:To:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=Tb8w8ynfxY8COaSjLzVFMoX4vchNIRtk6TAjuwfuM71/9jbRSAtDbUnzlDVVdBMgR LLy9HvY8y8dQE6E54cGPdHTLOM9j3nGMm4sOp31lSlPCNBg6EFmZJooJdk+qbcpXrq ACdHYQGeKr3+MyUJCgHYsUL/dnY8+aWy7VNHyFAc= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org 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 Received: by mail-pl1-x64a.google.com with SMTP id j12-20020a170902da8c00b0019a8df175b2so2674945plx.23 for ; Sun, 12 Feb 2023 22:01:21 -0800 (PST) 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] To: libc-alpha@sourceware.org Cc: Rasmus Villemoes , Adhemerval Zanella , Vitaly Buka 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 X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Vitaly Buka via Libc-alpha From: Vitaly Buka Reply-To: Vitaly Buka Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" 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