This is the mail archive of the gdb-cvs@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[binutils-gdb] gdb/inflow.c: Move SIGTTOU temporary ignoring to a RAII class


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=e2c33ac745108550dcc2dc61d23378fb2fa9e911

commit e2c33ac745108550dcc2dc61d23378fb2fa9e911
Author: Pedro Alves <palves@redhat.com>
Date:   Thu Nov 16 18:44:42 2017 +0000

    gdb/inflow.c: Move SIGTTOU temporary ignoring to a RAII class
    
    I expect to use this in more places (in inflow.c) in follow up
    patches, but I think this is still good on its own.
    
    gdb/ChangeLog:
    2017-11-16  Pedro Alves  <palves@redhat.com>
    
    	* inflow.c (scoped_ignore_sigttou): New class.
    	(child_terminal_ours_1, new_tty): Use it.

Diff:
---
 gdb/ChangeLog |  5 +++++
 gdb/inflow.c  | 50 +++++++++++++++++++++++++++++++++-----------------
 2 files changed, 38 insertions(+), 17 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index df10fe5..52bd615 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2017-11-16  Pedro Alves  <palves@redhat.com>
+
+	* inflow.c (scoped_ignore_sigttou): New class.
+	(child_terminal_ours_1, new_tty): Use it.
+
 2017-11-16  Ulrich Weigand  <uweigand@de.ibm.com>
 
 	* target-float.c (decimal_from_number): Add byte_order argument and
diff --git a/gdb/inflow.c b/gdb/inflow.c
index 0c279e6..7c49246 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]