From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pj1-x1049.google.com (mail-pj1-x1049.google.com [IPv6:2607:f8b0:4864:20::1049]) by sourceware.org (Postfix) with ESMTPS id A40153858D33 for ; Mon, 13 Feb 2023 05:57:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A40153858D33 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-pj1-x1049.google.com with SMTP id d16-20020a17090ad3d000b00233f132b99dso1238066pjw.0 for ; Sun, 12 Feb 2023 21:57:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1676267878; 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=Braeyo4VF2yITvDmrXU9VZxxm/gbctjkgk7tdns239WtlGjktcakM0KOHaDOxPIRoH 8cdNjsvcedEi2MrDzp46APpEekfJlRXadmEXJuUudYm427zr/kqZl+VH2mu/GTjm51eq BHyxqPYqALvztsp5kg9As8NLs7+bxg2X0BO/5bRGjslsYAMGZnF3mfkRsezzK6Xd9Btk 7jpG3zYuCkbOBzqf1hakt49u+JSpuigN6QZDxF0tXFhYJvvGKmnDLN9fBAfNzkxloIFa 8WHVO8PtxjHREFoQKrkjyeLGyUF8UmyhPU80PLnJPm1Ht142Oya4Q/8XS7P3vGr1wJ3i H60w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1676267878; 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=N/bYLoCnQHdE+iZ7O8Aq/MQQjDDD/C6x0QOBgRrUWiGrNC1HYdnsh9j7nxPOFq9JT+ hjqeXAbEo0ADOpunJWSJwBHunamobDm0w3uwfX10MIPdVEQs8Bnwtxa/Ik6pAlusWyHz lFztPvmZ4bKiWbZLesE5Q3CfOAfCKo0NwVjv0OY3sItM2JRe7uzjoYxfTudRiu9hkGBM KX1THX9DILOe3gVzhgXw2u7Qey2IQySwzhBVRP5zYtr/7CGbzHU5w7jYrhiJ/0MEf7P/ hQDMORRkSuq8U4Oc8rtEj2nKsvpNzw4c8zJF1OqMPSsEZPPCjiBQLQh2nQhxB1yzHsGJ 6X8A== X-Gm-Message-State: AO0yUKUhi39x7HyELBozeTpIX90c/VgwZfstheFCMgzYWXXX1jvTBeWH T1IsFDwtKUmzbGmaBzYuxS0ngML9Vq6np7iJPnLcJ5PCgQrfTpYx1s1NYmEM0yKjjWFPwA8nsjY mA9djG1NmFW/m6iwiO8nSIfHlASp7ECbJKRUswrM8N261xAq6ie10vnMZnbXewwAqlRtedniUYi /2 X-Google-Smtp-Source: AK7set+WFfTobNUxFrTEjJCCWe998TBeM8SrQ0Wo1gEbK7gTtl+K/Q8GqGUORpm7kAC1RMwb+XLKHo+20AKk8wUs X-Received: from vvv.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:56c]) (user=vitalybuka job=sendgmr) by 2002:a62:8489:0:b0:5a8:4dea:7015 with SMTP id k131-20020a628489000000b005a84dea7015mr3079409pfd.36.1676267878370; Sun, 12 Feb 2023 21:57:58 -0800 (PST) Date: Sun, 12 Feb 2023 21:57:50 -0800 In-Reply-To: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.39.1.581.gbfd45094c4-goog Message-ID: <20230213055750.3192155-1-vitalybuka@google.com> Subject: [PATCH] stdlib: Undo post review change to 16adc58e73f3 [BZ #27749] From: Vitaly Buka To: libc-alpha@sourceware.org Cc: Vitaly Buka Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-20.6 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