#include "inflow.h"
#include "gdbcmd.h"
-#include "gdb_termios.h"
+#ifdef HAVE_TERMIOS_H
+#include <termios.h>
+#endif
#include "job-control.h"
#ifdef HAVE_SYS_IOCTL_H
it when it resumes. */
serial_ttystate ttystate;
-#ifdef PROCESS_GROUP_TYPE
+#ifdef HAVE_TERMIOS_H
/* Process group. Saved and restored just like ttystate. */
- PROCESS_GROUP_TYPE process_group;
+ pid_t process_group;
#endif
/* fcntl flags. Saved and restored just like ttystate. */
static struct terminal_info *get_inflow_inferior_data (struct inferior *);
-#ifdef PROCESS_GROUP_TYPE
+/* 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. */
-PROCESS_GROUP_TYPE
+pid_t
inferior_process_group (void)
{
return get_inflow_inferior_data (current_inferior ())->process_group;
int terminal_is_ours;
-#ifdef PROCESS_GROUP_TYPE
-static PROCESS_GROUP_TYPE
-gdb_getpgrp (void)
-{
- int process_group = -1;
-
-#ifdef HAVE_TERMIOS
- process_group = tcgetpgrp (0);
-#endif
-#ifdef HAVE_TERMIO
- process_group = getpgrp ();
-#endif
-#ifdef HAVE_SGTTY
- ioctl (0, TIOCGPGRP, &process_group);
-#endif
- return process_group;
-}
-#endif
-
/* See terminal.h. */
void
#ifdef F_GETFL
our_terminal_info.tflags = fcntl (0, F_GETFL, 0);
#endif
-#ifdef PROCESS_GROUP_TYPE
- our_terminal_info.process_group = gdb_getpgrp ();
+#ifdef HAVE_TERMIOS_H
+ our_terminal_info.process_group = tcgetpgrp (0);
#endif
}
}
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 PROCESS_GROUP_TYPE
+#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 PROCESS_GROUP_TYPE
- /* 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 /* PROCESS_GROUP_TYPE */
-}
-
/* Put the inferior's terminal settings into effect.
This is preparation for starting or resuming the inferior.
int result;
#ifdef F_GETFL
- /* Is there a reason this is being done twice? It happens both
- places we use F_SETFL, so I'm inclined to think perhaps there
- is some reason, however perverse. Perhaps not though... */
- result = fcntl (0, F_SETFL, tinfo->tflags);
result = fcntl (0, F_SETFL, tinfo->tflags);
OOPSY ("fcntl F_SETFL");
#endif
- /* Because we were careful to not change in or out of raw mode in
- terminal_ours, we will not change in our out of raw mode with
- this call, so we don't flush any input. */
- result = serial_set_tty_state (stdin_serial,
- tinfo->ttystate);
+ result = serial_set_tty_state (stdin_serial, tinfo->ttystate);
OOPSY ("setting tty state");
if (!job_control)
if (job_control)
{
-#ifdef HAVE_TERMIOS
+#ifdef HAVE_TERMIOS_H
result = tcsetpgrp (0, tinfo->process_group);
if (!inf->attach_flag)
OOPSY ("tcsetpgrp");
#endif
-
-#ifdef HAVE_SGTTY
- result = ioctl (0, TIOCSPGRP, &tinfo->process_group);
- if (!inf->attach_flag)
- OOPSY ("TIOCSPGRP");
-#endif
}
-
}
terminal_is_ours = 0;
}
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);
-#ifdef PROCESS_GROUP_TYPE
+#ifdef HAVE_TERMIOS_H
if (!inf->attach_flag)
- /* If setpgrp failed in terminal_inferior, this would give us
+ /* If tcsetpgrp failed in terminal_inferior, this would give us
our process group instead of the inferior's. See
terminal_inferior for details. */
- tinfo->process_group = gdb_getpgrp ();
+ tinfo->process_group = tcgetpgrp (0);
#endif
- /* Here we used to set ICANON in our ttystate, but I believe this
- was an artifact from before when we used readline. Readline sets
- the tty state when it needs to.
- FIXME-maybe: However, query() expects non-raw mode and doesn't
- use readline. Maybe query should use readline (on the other hand,
- this only matters for HAVE_SGTTY, not termio or termios, I think). */
-
- /* Set tty state to our_ttystate. We don't change in our out of raw
- mode, to avoid flushing input. We need to do the same thing
- regardless of output_only, because we don't have separate
- terminal_is_ours and terminal_is_ours_for_output flags. It's OK,
- though, since readline will deal with raw mode when/if it needs
- to. */
-
- serial_noflush_set_tty_state (stdin_serial, our_terminal_info.ttystate,
- tinfo->ttystate);
+ /* Set tty state to our_ttystate. */
+ serial_set_tty_state (stdin_serial, our_terminal_info.ttystate);
if (job_control)
{
-#ifdef HAVE_TERMIOS
+#ifdef HAVE_TERMIOS_H
result = tcsetpgrp (0, our_terminal_info.process_group);
#if 0
/* This fails on Ultrix with EINVAL if you run the testsuite
safe_strerror (errno));
#endif
#endif /* termios */
-
-#ifdef HAVE_SGTTY
- result = ioctl (0, TIOCSPGRP, &our_terminal_info.process_group);
-#endif
}
-#ifdef SIGTTOU
- if (job_control)
- signal (SIGTTOU, osigttou);
-#endif
-
if (!job_control)
{
signal (SIGINT, sigint_ours);
#ifdef F_GETFL
tinfo->tflags = fcntl (0, F_GETFL, 0);
-
- /* Is there a reason this is being done twice? It happens both
- places we use F_SETFL, so I'm inclined to think perhaps there
- is some reason, however perverse. Perhaps not though... */
- result = fcntl (0, F_SETFL, our_terminal_info.tflags);
result = fcntl (0, F_SETFL, our_terminal_info.tflags);
#endif
}
}
void
-info_terminal_command (char *arg, int from_tty)
+info_terminal_command (const char *arg, int from_tty)
{
target_terminal::info (arg, from_tty);
}
printf_filtered ("\n");
}
-#ifdef PROCESS_GROUP_TYPE
+#ifdef HAVE_TERMIOS_H
printf_filtered ("Process group = %d\n", (int) tinfo->process_group);
#endif
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