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. */
before we actually run the inferior. */
void
-child_terminal_init_with_pgrp (int pgrp)
+child_terminal_init (struct target_ops *self)
{
struct inferior *inf = current_inferior ();
struct terminal_info *tinfo = get_inflow_inferior_data (inf);
#ifdef HAVE_TERMIOS_H
/* Store the process group even without a terminal as it is used not
only to reset the tty foreground process group, but also to
- interrupt the inferior. */
- tinfo->process_group = pgrp;
+ interrupt the inferior. A child we spawn should be a process
+ group leader (PGID==PID) at this point, though that may not be
+ true if we're attaching to an existing process. */
+ tinfo->process_group = inf->pid;
#endif
if (gdb_has_a_terminal ())
}
}
-void
-child_terminal_init (struct target_ops *self)
-{
-#ifdef HAVE_TERMIOS_H
- /* This is for Lynx, and should be cleaned up by having Lynx be a
- separate debugging target with a version of target_terminal::init
- which passes in the process group to a generic routine which does
- all the work (and the non-threaded child_terminal_init can just
- pass in inferior_ptid to the same routine). */
- /* We assume INFERIOR_PID is also the child's process group. */
- child_terminal_init_with_pgrp (ptid_get_pid (inferior_ptid));
-#endif /* HAVE_TERMIOS_H */
-}
-
/* Put the inferior's terminal settings into effect.
This is preparation for starting or resuming the inferior.
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);
#endif /* termios */
}
-#ifdef SIGTTOU
- if (job_control)
- signal (SIGTTOU, osigttou);
-#endif
-
if (!job_control)
{
signal (SIGINT, sigint_ours);
}
void
-info_terminal_command (char *arg, int from_tty)
+info_terminal_command (const char *arg, int from_tty)
{
target_terminal::info (arg, from_tty);
}
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