+2013-01-11 Paul Eggert <eggert@cs.ucla.edu>
+
+ emacsclient -t should not suspend Emacs server (Bug#13387)
+ * lisp.h, sysdep.c (block_tty_out_signal, unblock_tty_out_signal):
+ New functions.
+ * term.c (init_tty): Use them instead of rolling our own code.
+ * sysdep.c (tcsetpgrp_without_stopping): Likewise. Here, this
+ switches from 'signal' to 'pthread_sigmask', which is safer in
+ multithreaded applications.
+ * term.c (Fresume_tty): Don't bother dissociating if O_IGNORE_CTTY,
+ which has already arranged for that.
+ (dissociate_if_controlling_tty): If setsid fails, fall back on TIOCNOTTY.
+ This is the main part of the bug fix.
+
2013-01-10 Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE> (tiny change)
* gtkutil.c (xg_initialize): Add ifdef HAVE_FREETYPE around
extern void sys_subshell (void);
extern void sys_suspend (void);
extern void discard_tty_input (void);
+extern void block_tty_out_signal (void);
+extern void unblock_tty_out_signal (void);
extern void init_sys_modes (struct tty_display_info *);
extern void reset_sys_modes (struct tty_display_info *);
extern void init_all_sys_modes (void);
inherited_pgroup = getpid () == pgrp ? 0 : pgrp;
}
+/* Block and unblock SIGTTOU. */
+
+void
+block_tty_out_signal (void)
+{
+#ifdef SIGTTOU
+ sigset_t blocked;
+ sigemptyset (&blocked);
+ sigaddset (&blocked, SIGTTOU);
+ pthread_sigmask (SIG_BLOCK, &blocked, 0);
+#endif
+}
+
+void
+unblock_tty_out_signal (void)
+{
+#ifdef SIGTTOU
+ pthread_sigmask (SIG_SETMASK, &empty_mask, 0);
+#endif
+}
+
/* Safely set a controlling terminal FD's process group to PGID.
If we are not in the foreground already, POSIX requires tcsetpgrp
to deliver a SIGTTOU signal, which would stop us. This is an
tcsetpgrp_without_stopping (int fd, pid_t pgid)
{
#ifdef SIGTTOU
- signal_handler_t handler;
block_input ();
- handler = signal (SIGTTOU, SIG_IGN);
+ block_tty_out_signal ();
tcsetpgrp (fd, pgid);
- signal (SIGTTOU, handler);
+ unblock_tty_out_signal ();
unblock_input ();
#endif
}
if (fd == -1)
error ("Can not reopen tty device %s: %s", t->display_info.tty->name, strerror (errno));
- if (strcmp (t->display_info.tty->name, DEV_TTY))
+ if (!O_IGNORE_CTTY && strcmp (t->display_info.tty->name, DEV_TTY) != 0)
dissociate_if_controlling_tty (fd);
t->display_info.tty->output = fdopen (fd, "w+");
terminal->delete_terminal_hook = &delete_tty;
}
-/* Drop the controlling terminal if fd is the same device. */
+/* If FD is the controlling terminal, drop it. */
static void
dissociate_if_controlling_tty (int fd)
{
- pid_t pgid = tcgetpgrp (fd); /* If tcgetpgrp succeeds, fd is the ctty. */
- if (0 <= pgid)
- setsid ();
+ /* If tcgetpgrp succeeds, fd is the controlling terminal,
+ so dissociate it by invoking setsid. */
+ if (0 <= tcgetpgrp (fd) && setsid () < 0)
+ {
+#ifdef TIOCNOTTY
+ /* setsid failed, presumably because Emacs is already a process
+ group leader. Fall back on the obsolescent way to dissociate
+ a controlling tty. */
+ block_tty_out_signal ();
+ ioctl (fd, TIOCNOTTY, 0);
+ unblock_tty_out_signal ();
+#endif
+ }
}
/* Create a termcap display on the tty device with the given name and
/* On some systems, tgetent tries to access the controlling
terminal. */
- {
- sigset_t blocked;
- sigemptyset (&blocked);
- sigaddset (&blocked, SIGTTOU);
- pthread_sigmask (SIG_BLOCK, &blocked, 0);
- status = tgetent (tty->termcap_term_buffer, terminal_type);
- pthread_sigmask (SIG_UNBLOCK, &blocked, 0);
- }
+ block_tty_out_signal ();
+ status = tgetent (tty->termcap_term_buffer, terminal_type);
+ unblock_tty_out_signal ();
if (status < 0)
{