public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] gdb/inflow.c: Move SIGTTOU temporary ignoring to a RAII class
@ 2017-11-10  0:04 Pedro Alves
  2017-11-10 16:24 ` Simon Marchi
  0 siblings, 1 reply; 3+ messages in thread
From: Pedro Alves @ 2017-11-10  0:04 UTC (permalink / raw)
  To: gdb-patches

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  <palves@redhat.com>

	* 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
 
-- 
2.5.5

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] gdb/inflow.c: Move SIGTTOU temporary ignoring to a RAII class
  2017-11-10  0:04 [PATCH] gdb/inflow.c: Move SIGTTOU temporary ignoring to a RAII class Pedro Alves
@ 2017-11-10 16:24 ` Simon Marchi
  2017-11-16 18:46   ` Pedro Alves
  0 siblings, 1 reply; 3+ messages in thread
From: Simon Marchi @ 2017-11-10 16:24 UTC (permalink / raw)
  To: gdb-patches, Pedro Alves

On 9 November 2017 19:04:04 GMT-05:00, Pedro Alves <palves@redhat.com> wrote:
>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  <palves@redhat.com>
>
>	* 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
> 

LGTM (at least on my phone :))

Simon 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] gdb/inflow.c: Move SIGTTOU temporary ignoring to a RAII class
  2017-11-10 16:24 ` Simon Marchi
@ 2017-11-16 18:46   ` Pedro Alves
  0 siblings, 0 replies; 3+ messages in thread
From: Pedro Alves @ 2017-11-16 18:46 UTC (permalink / raw)
  To: Simon Marchi, gdb-patches


On 11/10/2017 04:24 PM, Simon Marchi wrote:
> On 9 November 2017 19:04:04 GMT-05:00, Pedro Alves <palves@redhat.com> wrote:
>> I expect to use this more places (in inflow.c) in follow up patches,
>> but I think this is still good on its own.


> LGTM (at least on my phone :))

:-)

Now pushed.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-11-16 18:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-10  0:04 [PATCH] gdb/inflow.c: Move SIGTTOU temporary ignoring to a RAII class Pedro Alves
2017-11-10 16:24 ` Simon Marchi
2017-11-16 18:46   ` Pedro Alves

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).