+ /* Using host-dependent code here is fine, because the
+ child_terminal_foo functions are meant to be used by child/native
+ targets. */
+#if defined (__linux__) || defined (__sun__)
+ char buf[100];
+
+ xsnprintf (buf, sizeof (buf), "/proc/%d/fd/0", inf->pid);
+ return is_gdb_terminal (buf);
+#else
+ return TRIBOOL_UNKNOWN;
+#endif
+}
+
+/* Return true if the inferior is using the same TTY for input as GDB
+ is. If this is true, then we save/restore terminal flags/state.
+
+ This is necessary because if inf->attach_flag is set, we don't
+ offhand know whether we are sharing a terminal with the inferior or
+ not. Attaching a process without a terminal is one case where we
+ do not; attaching a process which we ran from the same shell as GDB
+ via `&' is one case where we do.
+
+ If we can't determine, we assume the TTY is being shared. This
+ works OK if you're only debugging one inferior. However, if you're
+ debugging more than one inferior, and e.g., one is spawned by GDB
+ with "run" (sharing terminal with GDB), and another is attached to
+ (and running on a different terminal, as is most common), then it
+ matters, because we can only restore the terminal settings of one
+ of the inferiors, and in that scenario, we want to restore the
+ settings of the "run"'ed inferior.
+
+ Note, this is not the same as determining whether GDB and the
+ inferior are in the same session / connected to the same
+ controlling tty. An inferior (fork child) may call setsid,
+ disconnecting itself from the ctty, while still leaving
+ stdin/stdout/stderr associated with the original terminal. If
+ we're debugging that process, we should also save/restore terminal
+ settings. */
+
+static bool
+sharing_input_terminal (inferior *inf)
+{
+ terminal_info *tinfo = get_inflow_inferior_data (inf);
+
+ tribool res = sharing_input_terminal_1 (inf);