From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id HNU6HUJ7y2DiLgAAWB0awg (envelope-from ) for ; Thu, 17 Jun 2021 12:41:38 -0400 Received: by simark.ca (Postfix, from userid 112) id 6644E1F163; Thu, 17 Jun 2021 12:41:38 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-0.6 required=5.0 tests=MAILING_LIST_MULTI, RDNS_DYNAMIC,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 502C91E54D for ; Thu, 17 Jun 2021 12:41:37 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 92EBB398A860 for ; Thu, 17 Jun 2021 16:41:36 +0000 (GMT) Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.42]) by sourceware.org (Postfix) with ESMTPS id 035F7396EC42 for ; Thu, 17 Jun 2021 15:37:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 035F7396EC42 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=palves.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wr1-f42.google.com with SMTP id v9so7299770wrx.6 for ; Thu, 17 Jun 2021 08:37:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:references:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=5HxU9MnvxcUagIpCd95XkqJzkWHxyg2NWhvyV7iRkwE=; b=TveaVb5hwFSuxVuf7mT9DRpZQCXyuIyaWir2DX6PVSnu0zzm+vRpypLkbECNF4p3hd i8pYx6Q9F0iGqCakqO1ah6A5FhCS3nkT/Ek8GunKoE0Onx1O716kRUU0q7LIJhCaZACs jFdGWyBP4gDMONpyfpD5zr1NofXuLJdNA3UBlWiZV0NC42turgbQUsL1zAMZmEPgir0J fnLQX7DMpsulnFz/qzHlkDbeI0hQWpQmacXEGZM4LvPaQHkqP/unyLbCse9+yCO49elh Xm+4+InaIZgBRR+n4yrYWjcBtu5phCt/zkSD4k9p/cHvVedK/yvzf0vWlN0KZ747V74x apqw== X-Gm-Message-State: AOAM531/jm3ehw7PJxU+LkoCiuwlg/QVZtL9WnxF/HAs/xdmntwZr+Bl gMACB5cyDeKfwHOLlJAkoUX71jWibx2Cyevw X-Google-Smtp-Source: ABdhPJxYngPdvI7N5l1/1MlIZsBr02CIP1h+F6tF20ppSi6YKC8P7iJXPB2DNca3U9GJyYNm0s3KVA== X-Received: by 2002:adf:df09:: with SMTP id y9mr6625820wrl.108.1623944219866; Thu, 17 Jun 2021 08:36:59 -0700 (PDT) Received: from ?IPv6:2001:8a0:f932:6a00:6b6e:c7b6:c5a7:aac3? ([2001:8a0:f932:6a00:6b6e:c7b6:c5a7:aac3]) by smtp.gmail.com with ESMTPSA id p11sm5729961wrx.85.2021.06.17.08.36.58 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 17 Jun 2021 08:36:58 -0700 (PDT) Subject: Re: [PATCH 0/4] Introduce scoped_ignore_signal & make it thread safe From: Pedro Alves To: John Baldwin , gdb-patches@sourceware.org References: <20210615111429.1879286-1-pedro@palves.net> <7f678d4a-b015-655f-f79a-36daccab5062@palves.net> Message-ID: <18c7433b-464d-b274-88a2-5495aab407ba@palves.net> Date: Thu, 17 Jun 2021 16:36:57 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <7f678d4a-b015-655f-f79a-36daccab5062@palves.net> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" On 2021-06-17 3:38 p.m., Pedro Alves wrote: > On 2021-06-15 6:04 p.m., John Baldwin wrote: > If SIGTTOU ends up raised by some other thread while the main thread has it blocked > in scoped_ignore_sigttou, and if it is sent to the whole process, there's a small time window > where the sigtimedwait in the main thread can eat the signal. That still seems better than > the current status where the end result can be that we can end up with the signal enabled > instead of ignored and then gdb backgrounds itself. This is of course highly theoretical since I > expect that gdb threads run with signals blocked from the get go. But you never know what > Python code does. > Hmm, I just thought of an easy fix for that. Just don't consume the pending signal in SIGTTOU's case. I wonder how portable is this? WDYT? I'll see if I can try this on Solaris. >From 7f9288f1c3c4f184ebc08dd56406de0c13f5246a Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Thu, 17 Jun 2021 16:23:03 +0100 Subject: [PATCH] No sigtimedwait for SIGTTOU Change-Id: I92f754dbc45c45819dce2ce68b8c067d8d5c61b1 --- gdbsupport/scoped_ignore_signal.h | 18 +++++++++++++----- gdbsupport/scoped_ignore_sigttou.h | 2 +- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/gdbsupport/scoped_ignore_signal.h b/gdbsupport/scoped_ignore_signal.h index 55a921cb332..a14c96779bf 100644 --- a/gdbsupport/scoped_ignore_signal.h +++ b/gdbsupport/scoped_ignore_signal.h @@ -25,9 +25,16 @@ /* RAII class used to ignore a signal in a scope. If sigprocmask is supported, then the signal is only ignored by the calling thread. Otherwise, the signal disposition is set to SIG_IGN, which affects - the whole process. */ - -template + the whole process. If ConsumePending is true, the destructor + consumes a pending Sig. SIGPIPE for example is queued on the + thread even if blocked at the time the pipe is written to. SIGTTOU + OTOH is not raised at all if the thread writing to the terminal has + it blocked. Because SIGTTOU is sent to the whole process instead + of to a specific thread, consuming a pending SIGTTOU in the + destructor could consume a signal raised due to actions done by + some other thread. */ + +template class scoped_ignore_signal { public: @@ -58,7 +65,8 @@ class scoped_ignore_signal /* If we got a pending Sig signal, consume it before unblocking. */ - sigtimedwait (&set, nullptr, &zero_timeout); + if (ConsumePending) + sigtimedwait (&set, nullptr, &zero_timeout); sigprocmask (SIG_UNBLOCK, &set, nullptr); } @@ -89,7 +97,7 @@ struct scoped_ignore_signal_nop }; #ifdef SIGPIPE -using scoped_ignore_sigpipe = scoped_ignore_signal; +using scoped_ignore_sigpipe = scoped_ignore_signal; #else using scoped_ignore_sigpipe = scoped_ignore_signal_nop; #endif diff --git a/gdbsupport/scoped_ignore_sigttou.h b/gdbsupport/scoped_ignore_sigttou.h index 1fc8f80d7fd..5695c5db905 100644 --- a/gdbsupport/scoped_ignore_sigttou.h +++ b/gdbsupport/scoped_ignore_sigttou.h @@ -75,7 +75,7 @@ class scoped_ignore_sigttou DISABLE_COPY_AND_ASSIGN (scoped_ignore_sigttou); private: - lazy_init> m_ignore_signal; + lazy_init> m_ignore_signal; }; #else base-commit: 2af6d46fd331b8e632bb9245614bad0c974392a4 -- 2.26.2