From patchwork Sat Feb 18 20:53:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vitaly Buka X-Patchwork-Id: 65226 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 62C61385840E for ; Sat, 18 Feb 2023 20:54:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 62C61385840E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1676753651; bh=fEVu608hxcvcrOln7d8aXMqeq29gDi93mzax8dLzs+E=; 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=Fkrd0f445ILoaVfBZjkMaSvy/5VjaM4ppXhBR1YmHyTJ0PjSHSenlrnuUIKKtNyOt lk9C/mqkmcYLBn8IWcZtKg70/vBtkv08X4TWRBN3ZHAWCSBoSDvM04aJK3burJRIbP VBfyEazlZnbvc4aJI77r4pHlfpAe1fedediS3ukI= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by sourceware.org (Postfix) with ESMTPS id 01EBC3858D32 for ; Sat, 18 Feb 2023 20:53:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 01EBC3858D32 Received: by mail-yb1-xb4a.google.com with SMTP id c140-20020a25c092000000b0096c886848c9so862524ybf.3 for ; Sat, 18 Feb 2023 12:53:48 -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=fEVu608hxcvcrOln7d8aXMqeq29gDi93mzax8dLzs+E=; b=LulMqhvJi+wa6A4YYkKfqvDO6OgO1jHmZyp3L/2okdUqlAEqyh8R2LGQIxxII9qtsj nXOOjcQsED7wzbxkdZapue573iZbpVdIwSJoljZbYlNSBcEV0hStzOgqZYFLSfcxCmFP lB8UCklZ68kanpJjxX1DB+8yKaWAiPaKQgVre5rxEcU5kCqPXW3zpr6e7i27fz4lfnfp a14stZFUGnSsmQvshJZg5Qi879Nx0o3+a7VU7VCGT6DMHARaXvrGQUhwY7eYCesZFAO9 7Sz8skxxGZgUKMq8vTubP3/3C8gLGVJ1EkKVfzVI7as0ODGoMEe96TCqh/hhMj7Mk6Oe i3Hw== X-Gm-Message-State: AO0yUKUkS1UyYk0J6r0WxyH383j2XydWjW2Zw0tm8Hj8NLJBr/dPZHdt HOgj8juzLBiBwuCyzIayUnrS7rW6POzgsC/W9QdB9eRlpSDvmBK+B0sSMRrVIHW96vSDtuGiCdR Org7S77YnXRVbsi+lHk9gH8S62wNsG/zlywAYYLOsrzC2RToDJamv0wWZ20CzF9f23Ua80vsew8 Gj X-Google-Smtp-Source: AK7set9Snj/39UTIThhYSstNY7JjkKeBkmnsx8Y19MZUmQutiq5HB9WO9NWMEiABmE8Nc1MbgCWH++ryVbuwDJYj X-Received: from vvv.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:56c]) (user=vitalybuka job=sendgmr) by 2002:a0d:d985:0:b0:536:44ba:c4c9 with SMTP id b127-20020a0dd985000000b0053644bac4c9mr577025ywe.152.1676753628248; Sat, 18 Feb 2023 12:53:48 -0800 (PST) Date: Sat, 18 Feb 2023 12:53:41 -0800 In-Reply-To: <92772e3f-4809-ed81-5d3a-796a7dce4f45@linaro.org> Mime-Version: 1.0 References: <92772e3f-4809-ed81-5d3a-796a7dce4f45@linaro.org> X-Mailer: git-send-email 2.39.2.637.g21b0678d19-goog Message-ID: <20230218205341.3180300-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.8 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 Reviewed-by: Adhemerval Zanella --- stdlib/Makefile | 1 + stdlib/exit.c | 7 +++- stdlib/test-atexit-recursive.c | 75 ++++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+), 2 deletions(-) create mode 100644 stdlib/test-atexit-recursive.c diff --git a/stdlib/Makefile b/stdlib/Makefile index ff5096ad1b..cd32f53b56 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..0596b9763b --- /dev/null +++ b/stdlib/test-atexit-recursive.c @@ -0,0 +1,75 @@ +/* Support file for atexit/exit, etc. race tests (BZ #27749). + Copyright (C) 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