-#ifdef TIOCGPGRP
- result = ioctl (0, TIOCSPGRP, &pgrp_inferior);
- /* If we attached to the process, we might or might not be sharing
- a terminal. Avoid printing error msg if we are unable to set our
- terminal's process group to his process group ID. */
- if (!attach_flag) {
- OOPSY ("ioctl TIOCSPGRP");
- }
-#else
- sigint_ours = (void (*) ()) signal (SIGINT, SIG_IGN);
- sigquit_ours = (void (*) ()) signal (SIGQUIT, SIG_IGN);
-#endif /* TIOCGPGRP */
+ /* 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, inferior_ttystate);
+
+ /* If attach_flag is set, we don't 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, I think (but perhaps this is not
+ `sharing' in the sense that we need to save and restore tty
+ state)). I don't know if there is any way to tell whether we
+ are sharing a terminal. So what we do is to go through all
+ the saving and restoring of terminal state, but ignore errors
+ (which will occur, in tcsetpgrp, if we are not sharing a
+ terminal). */
+
+ if (!attach_flag)
+ OOPSY ("setting tty state");
+
+ if (!job_control)
+ {
+ sigint_ours = (void (*) ()) signal (SIGINT, SIG_IGN);
+ sigquit_ours = (void (*) ()) signal (SIGQUIT, SIG_IGN);
+ }