From patchwork Mon Feb 13 05:57:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vitaly Buka X-Patchwork-Id: 1741359 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=M9GKq4Gx; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PFYYB03vJz23qt for ; Mon, 13 Feb 2023 16:58:21 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0A8373858D3C for ; Mon, 13 Feb 2023 05:58:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0A8373858D3C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1676267897; 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=M9GKq4Gx4r1CmllpAdsb9mz/XP+AguGtKjKACu5c9ZExLK+17jVV5d3rxmIl3Q7dJ T3+YHkrZUrA+sOvF5GaT3e3Hf728Aq6gRZ6hHcmToIAVpCgjG3S51zSgBE/nmQXn4A EkUYLcBOah6kOJo18BLrBSomnAmqscSXWtJCsyVw= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org 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 Received: by mail-pj1-x1049.google.com with SMTP id d16-20020a17090ad3d000b00233f132b99dso1238066pjw.0 for ; Sun, 12 Feb 2023 21:57:59 -0800 (PST) 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] To: libc-alpha@sourceware.org Cc: Vitaly Buka 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 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+incoming=patchwork.ozlabs.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