From patchwork Tue Jun 6 09:40:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 1790952 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=vChomcya; 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 4Qb57Z4Mtpz20Ty for ; Tue, 6 Jun 2023 19:40:42 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 375B0385771D for ; Tue, 6 Jun 2023 09:40:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 375B0385771D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1686044440; bh=ZP1vwWj1TQxrpNXMEobUqfiHcpY87+yypyJtbMFN6+c=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=vChomcyaJB9lag6gBrh8Dnp7OA5w6S2KvIHHJxS7xbo8Pj2qpjKVFRiLTQIFKR9VX pZnS93yeeFdBPBHU7aNsohc5u1GouUlVsDJFxJIqc+8gVaaDo9W04fIcjsbfkNF9gU uELPAL6JGV8JxChtDw2+vbUUJl13vXldLKnteo3U= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id A01733858D33 for ; Tue, 6 Jun 2023 09:40:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A01733858D33 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-152-FrvcwQDYOIaLZPjxh7DzgQ-1; Tue, 06 Jun 2023 05:40:18 -0400 X-MC-Unique: FrvcwQDYOIaLZPjxh7DzgQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5CA1F299E74A for ; Tue, 6 Jun 2023 09:40:18 +0000 (UTC) Received: from oldenburg3.str.redhat.com (unknown [10.39.193.74]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E11E19E8B for ; Tue, 6 Jun 2023 09:40:17 +0000 (UTC) To: libc-alpha@sourceware.org Subject: [PATCH 1/2] support: Add delayed__exit (with two underscores) X-From-Line: 047703fbb88eb38fbe973f3abedb279382f181d0 Mon Sep 17 00:00:00 2001 Message-Id: <047703fbb88eb38fbe973f3abedb279382f181d0.1686044390.git.fweimer@redhat.com> Date: Tue, 06 Jun 2023 11:40:16 +0200 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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: Florian Weimer via Libc-alpha From: Florian Weimer Reply-To: Florian Weimer Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" It calls _exit instead of exit once the timeout expires. --- support/delayed_exit.c | 41 +++++++++++++++++++++++++++++++++-------- support/xthread.h | 9 ++++++--- 2 files changed, 39 insertions(+), 11 deletions(-) base-commit: e3622a8f391deea3b75a577dce70d023dfa3f1c7 diff --git a/support/delayed_exit.c b/support/delayed_exit.c index 53aa40c275..bc64ff0d3e 100644 --- a/support/delayed_exit.c +++ b/support/delayed_exit.c @@ -23,33 +23,58 @@ #include #include #include +#include #include +#include + +struct delayed_exit_request +{ + void (*exitfunc) (int); + int seconds; +}; static void * -delayed_exit_thread (void *seconds_as_ptr) +delayed_exit_thread (void *closure) { - int seconds = (uintptr_t) seconds_as_ptr; - struct timespec delay = { seconds, 0 }; + struct delayed_exit_request *request = closure; + void (*exitfunc) (int) = request->exitfunc; + struct timespec delay = { request->seconds, 0 }; struct timespec remaining = { 0 }; + free (request); + if (nanosleep (&delay, &remaining) != 0) FAIL_EXIT1 ("nanosleep: %m"); /* Exit the process successfully. */ - exit (0); + exitfunc (0); return NULL; } -void -delayed_exit (int seconds) +static void +delayed_exit_1 (int seconds, void (*exitfunc) (int)) { /* Create the new thread with all signals blocked. */ sigset_t all_blocked; sigfillset (&all_blocked); sigset_t old_set; xpthread_sigmask (SIG_SETMASK, &all_blocked, &old_set); + struct delayed_exit_request *request = xmalloc (sizeof (*request)); + request->seconds = seconds; + request->exitfunc = exitfunc; /* Create a detached thread. */ - pthread_t thr = xpthread_create - (NULL, delayed_exit_thread, (void *) (uintptr_t) seconds); + pthread_t thr = xpthread_create (NULL, delayed_exit_thread, request); xpthread_detach (thr); /* Restore the original signal mask. */ xpthread_sigmask (SIG_SETMASK, &old_set, NULL); } + +void +delayed_exit (int seconds) +{ + delayed_exit_1 (seconds, exit); +} + +void +delayed__exit (int seconds) +{ + delayed_exit_1 (seconds, _exit); +} diff --git a/support/xthread.h b/support/xthread.h index b1e85a9b56..402df561aa 100644 --- a/support/xthread.h +++ b/support/xthread.h @@ -25,11 +25,14 @@ __BEGIN_DECLS -/* Terminate the process (with exit status 0) after SECONDS have - elapsed, from a helper thread. The process is terminated with the - exit function, so atexit handlers are executed. */ +/* Terminate the process (with exit (0)) after SECONDS have elapsed, + from a helper thread. The process is terminated with the exit + function, so atexit handlers are executed. */ void delayed_exit (int seconds); +/* Like delayed_exit, but use _exit (0). */ +void delayed__exit (int seconds); + /* Returns true if Priority Inheritance support CLOCK_MONOTONIC. */ bool support_mutex_pi_monotonic (void);