From patchwork Fri Nov 10 00:04:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 24188 Received: (qmail 129486 invoked by alias); 10 Nov 2017 00:04:09 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 129475 invoked by uid 89); 10 Nov 2017 00:04:08 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 10 Nov 2017 00:04:07 +0000 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DD26B8008B for ; Fri, 10 Nov 2017 00:04:05 +0000 (UTC) Received: from cascais.lan (ovpn04.gateway.prod.ext.ams2.redhat.com [10.39.146.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 63FFA5D9C8 for ; Fri, 10 Nov 2017 00:04:05 +0000 (UTC) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH] gdb/inflow.c: Move SIGTTOU temporary ignoring to a RAII class Date: Fri, 10 Nov 2017 00:04:04 +0000 Message-Id: <1510272244-4980-1-git-send-email-palves@redhat.com> I expect to use this more places (in inflow.c) in follow up patches, but I think this is still good on its own. gdb/ChangeLog: yyyy-mm-dd Pedro Alves * inflow.c (scoped_ignore_sigttou): New class. (child_terminal_ours_1, new_tty): Use it. --- gdb/inflow.c | 50 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 17 deletions(-) diff --git a/gdb/inflow.c b/gdb/inflow.c index 2fba0fa..52be5af 100644 --- a/gdb/inflow.c +++ b/gdb/inflow.c @@ -91,6 +91,35 @@ static serial_ttystate initial_gdb_ttystate; static struct terminal_info *get_inflow_inferior_data (struct inferior *); +/* RAII class used to ignore SIGTTOU in a scope. */ + +class scoped_ignore_sigttou +{ +public: + scoped_ignore_sigttou () + { +#ifdef SIGTTOU + if (job_control) + m_osigttou = signal (SIGTTOU, SIG_IGN); +#endif + } + + ~scoped_ignore_sigttou () + { +#ifdef SIGTTOU + if (job_control) + signal (SIGTTOU, m_osigttou); +#endif + } + + DISABLE_COPY_AND_ASSIGN (scoped_ignore_sigttou); + +private: +#ifdef SIGTTOU + sighandler_t m_osigttou = NULL; +#endif +}; + #ifdef HAVE_TERMIOS_H /* Return the process group of the current inferior. */ @@ -329,17 +358,11 @@ child_terminal_ours_1 (int output_only) return; else { -#ifdef SIGTTOU - /* Ignore this signal since it will happen when we try to set the - pgrp. */ - sighandler_t osigttou = NULL; -#endif int result ATTRIBUTE_UNUSED; -#ifdef SIGTTOU - if (job_control) - osigttou = signal (SIGTTOU, SIG_IGN); -#endif + /* Ignore SIGTTOU since it will happen when we try to set the + terminal's pgrp. */ + scoped_ignore_sigttou ignore_sigttou; xfree (tinfo->ttystate); tinfo->ttystate = serial_get_tty_state (stdin_serial); @@ -372,11 +395,6 @@ child_terminal_ours_1 (int output_only) #endif /* termios */ } -#ifdef SIGTTOU - if (job_control) - signal (SIGTTOU, osigttou); -#endif - if (!job_control) { signal (SIGINT, sigint_ours); @@ -603,12 +621,10 @@ new_tty (void) tty = open ("/dev/tty", O_RDWR); if (tty > 0) { - sighandler_t osigttou; + scoped_ignore_sigttou ignore_sigttou; - osigttou = signal (SIGTTOU, SIG_IGN); ioctl (tty, TIOCNOTTY, 0); close (tty); - signal (SIGTTOU, osigttou); } #endif