diff options
-rw-r--r-- | README.multi-tty | 27 | ||||
-rw-r--r-- | src/term.c | 54 |
2 files changed, 71 insertions, 10 deletions
diff --git a/README.multi-tty b/README.multi-tty index 06e069f8019..c86d69ac0dd 100644 --- a/README.multi-tty +++ b/README.multi-tty @@ -60,22 +60,23 @@ architectures, though.) Both multiple tty device support and simultaneous X and tty frame support works fine. Emacsclient has been extended to support opening a new terminal frame. - Please let me know if you find any bugs in this branch. +HOW TO COMPILE AND TEST +----------------------- + To try it out, compile and run the multi-tty branch with the following commands: mkdir +build cd +build - ../configure + ../configure <your favourite options> make bootstrap src/emacs -nw # You can also try without -nw M-x server-start and then (from a shell prompt on another terminal) start emacsclient with - lib-src/emacsclient -t /optional/file/names... You'll hopefully have two fully working, independent frames on @@ -160,9 +161,12 @@ THANKS The following is an (incomplete) list of people who have contributed to the project by testing, bug reports, and suggestions. Thanks! -Robert J. Chassel <bob@rattlesnake.com> -Romain Francoise <romain@orekobech.com> -Ami Fischman <ami@fischman.org> +Robert J. Chassel <bob at rattlesnake dot com> +Romain Francoise <romain at orekobech dot com> +Ami Fischman <ami at fischman dot org> +Dan Nicolaescu <dann at ics dot uci dot edu> + +Richard Stallman was kind enough to review my patches. CHANGELOG @@ -172,6 +176,10 @@ See arch logs. THINGS TO DO ------------ +** Dan Nicolaescu (dann at ics dot uci dot edu) suggests that -nw + should be added as an alias for -t in emacsclient. Good idea. + (Alas, implementing this is not trivial, getopt_long does not seem + to support two-letter ``short'' options.) ** Robert J. Chassell reports: @@ -634,4 +642,11 @@ DIARY OF CHANGES (Fixed.) + +-- Dan Nicolaescu noticed that starting emacsclient on the same + terminal device that is the controlling tty of the Emacs process + gives unexpected results. + + (Fixed.) + ;;; arch-tag: 8da1619e-2e79-41a8-9ac9-a0485daad17d diff --git a/src/term.c b/src/term.c index f5e0256e0f1..ddca41f3173 100644 --- a/src/term.c +++ b/src/term.c @@ -28,6 +28,9 @@ Boston, MA 02111-1307, USA. */ #include <sys/file.h> +#include <unistd.h> /* For isatty. */ +#include <sys/ioctl.h> /* For TIOCNOTTY. */ + #include "lisp.h" #include "termchar.h" #include "termopts.h" @@ -66,6 +69,10 @@ extern int tgetnum P_ ((char *id)); #define O_RDWR 2 #endif +#ifndef O_NOCTTY +#define O_NOCTTY 0 +#endif + static void turn_on_face P_ ((struct frame *, int face_id)); static void turn_off_face P_ ((struct frame *, int face_id)); static void tty_show_cursor P_ ((struct tty_display_info *)); @@ -153,6 +160,10 @@ int max_frame_lines; FRAME_PTR updating_frame; +/* Non-zero if we have dropped our controlling tty and therefore + should not open a frame on stdout. */ +static int no_controlling_tty; + /* Provided for lisp packages. */ static int system_uses_terminfo; @@ -2169,8 +2180,6 @@ DEFUN ("frame-tty-type", Fframe_tty_type, Sframe_tty_type, 0, 1, 0, struct display * init_initial_display (void) { - struct tty_display_info *tty; - if (initialized || display_list || tty_list) abort (); @@ -2285,12 +2294,41 @@ term_init (char *name, char *terminal_type, int must_succeed) { int fd; FILE *file; - fd = emacs_open (name, O_RDWR, 0); + +#ifdef O_IGNORE_CTTY + /* Open the terminal device. Don't recognize it as our + controlling terminal, and don't make it the controlling tty + if we don't have one at the moment. */ + fd = emacs_open (name, O_RDWR | O_IGNORE_CTTY | O_NOCTTY, 0); +#else + /* Alas, O_IGNORE_CTTY is a GNU extension that is only defined + on Hurd. On other systems, we need to dissociate ourselves + from the controlling tty when we want to open a frame on the + same terminal. The function setsid should be used for this, + but it didn't work for me. */ + + fd = emacs_open (name, O_RDWR | O_NOCTTY, 0); + +#ifdef TIOCNOTTY + /* Drop our controlling tty if it is the same device. */ + if (ioctl (fd, TIOCNOTTY, 0) != -1) + { + no_controlling_tty = 1; + } +#endif +#endif /* O_IGNORE_CTTY */ + if (fd < 0) { delete_tty (display); error ("Could not open file: %s", name); } + if (! isatty (fd)) + { + close (fd); + error ("Not a tty device: %s", name); + } + file = fdopen (fd, "w+"); tty->name = xstrdup (name); tty->input = file; @@ -2298,6 +2336,12 @@ term_init (char *name, char *terminal_type, int must_succeed) } else { + if (no_controlling_tty) + { + /* Opening a frame on stdout is unsafe if we have + disconnected our controlling terminal. */ + error ("There is no controlling terminal any more"); + } tty->name = 0; tty->input = stdin; tty->output = stdout; @@ -2805,6 +2849,8 @@ tty. The functions are run with one arg, the frame to be deleted. */) error ("No such terminal device: %s", name); delete_tty (d); + + return Qnil; } static int deleting_tty = 0; @@ -2952,7 +2998,7 @@ void mark_ttys () { struct tty_display_info *tty; - Lisp_Object *p; + for (tty = tty_list; tty; tty = tty->next) { if (tty->top_frame) |