aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKaroly Lorentey2004-02-02 22:09:56 +0000
committerKaroly Lorentey2004-02-02 22:09:56 +0000
commit0c72d684c4b3e25bdb3a6a869d9f1b8bd21b80c7 (patch)
treeff652240fcff0425e0398736c2b44b690bb8ebe7 /src
parentd3a6748c5b378a86fc8408222c7dd26e47218af9 (diff)
downloademacs-0c72d684c4b3e25bdb3a6a869d9f1b8bd21b80c7.tar.gz
emacs-0c72d684c4b3e25bdb3a6a869d9f1b8bd21b80c7.zip
Fix the case when emacsclient is run on Emacs's controlling tty.
src/term.c (O_NOCTTY): Make sure it's defined. (no_controlling_tty): New variable. (init_initial_display, mark_ttys): Remove unused variable. (term_init): Check that the given filename is a terminal device. Dissociate the controlling terminal if we reopen it for other purposes. (Reported by Dan Nicolaescu <dann at ics dot uci dot edu>. (Fdelete_tty): Return nil. git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-72
Diffstat (limited to 'src')
-rw-r--r--src/term.c54
1 files changed, 50 insertions, 4 deletions
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. */
28 28
29#include <sys/file.h> 29#include <sys/file.h>
30 30
31#include <unistd.h> /* For isatty. */
32#include <sys/ioctl.h> /* For TIOCNOTTY. */
33
31#include "lisp.h" 34#include "lisp.h"
32#include "termchar.h" 35#include "termchar.h"
33#include "termopts.h" 36#include "termopts.h"
@@ -66,6 +69,10 @@ extern int tgetnum P_ ((char *id));
66#define O_RDWR 2 69#define O_RDWR 2
67#endif 70#endif
68 71
72#ifndef O_NOCTTY
73#define O_NOCTTY 0
74#endif
75
69static void turn_on_face P_ ((struct frame *, int face_id)); 76static void turn_on_face P_ ((struct frame *, int face_id));
70static void turn_off_face P_ ((struct frame *, int face_id)); 77static void turn_off_face P_ ((struct frame *, int face_id));
71static void tty_show_cursor P_ ((struct tty_display_info *)); 78static void tty_show_cursor P_ ((struct tty_display_info *));
@@ -153,6 +160,10 @@ int max_frame_lines;
153 160
154FRAME_PTR updating_frame; 161FRAME_PTR updating_frame;
155 162
163/* Non-zero if we have dropped our controlling tty and therefore
164 should not open a frame on stdout. */
165static int no_controlling_tty;
166
156/* Provided for lisp packages. */ 167/* Provided for lisp packages. */
157 168
158static int system_uses_terminfo; 169static int system_uses_terminfo;
@@ -2169,8 +2180,6 @@ DEFUN ("frame-tty-type", Fframe_tty_type, Sframe_tty_type, 0, 1, 0,
2169struct display * 2180struct display *
2170init_initial_display (void) 2181init_initial_display (void)
2171{ 2182{
2172 struct tty_display_info *tty;
2173
2174 if (initialized || display_list || tty_list) 2183 if (initialized || display_list || tty_list)
2175 abort (); 2184 abort ();
2176 2185
@@ -2285,12 +2294,41 @@ term_init (char *name, char *terminal_type, int must_succeed)
2285 { 2294 {
2286 int fd; 2295 int fd;
2287 FILE *file; 2296 FILE *file;
2288 fd = emacs_open (name, O_RDWR, 0); 2297
2298#ifdef O_IGNORE_CTTY
2299 /* Open the terminal device. Don't recognize it as our
2300 controlling terminal, and don't make it the controlling tty
2301 if we don't have one at the moment. */
2302 fd = emacs_open (name, O_RDWR | O_IGNORE_CTTY | O_NOCTTY, 0);
2303#else
2304 /* Alas, O_IGNORE_CTTY is a GNU extension that is only defined
2305 on Hurd. On other systems, we need to dissociate ourselves
2306 from the controlling tty when we want to open a frame on the
2307 same terminal. The function setsid should be used for this,
2308 but it didn't work for me. */
2309
2310 fd = emacs_open (name, O_RDWR | O_NOCTTY, 0);
2311
2312#ifdef TIOCNOTTY
2313 /* Drop our controlling tty if it is the same device. */
2314 if (ioctl (fd, TIOCNOTTY, 0) != -1)
2315 {
2316 no_controlling_tty = 1;
2317 }
2318#endif
2319#endif /* O_IGNORE_CTTY */
2320
2289 if (fd < 0) 2321 if (fd < 0)
2290 { 2322 {
2291 delete_tty (display); 2323 delete_tty (display);
2292 error ("Could not open file: %s", name); 2324 error ("Could not open file: %s", name);
2293 } 2325 }
2326 if (! isatty (fd))
2327 {
2328 close (fd);
2329 error ("Not a tty device: %s", name);
2330 }
2331
2294 file = fdopen (fd, "w+"); 2332 file = fdopen (fd, "w+");
2295 tty->name = xstrdup (name); 2333 tty->name = xstrdup (name);
2296 tty->input = file; 2334 tty->input = file;
@@ -2298,6 +2336,12 @@ term_init (char *name, char *terminal_type, int must_succeed)
2298 } 2336 }
2299 else 2337 else
2300 { 2338 {
2339 if (no_controlling_tty)
2340 {
2341 /* Opening a frame on stdout is unsafe if we have
2342 disconnected our controlling terminal. */
2343 error ("There is no controlling terminal any more");
2344 }
2301 tty->name = 0; 2345 tty->name = 0;
2302 tty->input = stdin; 2346 tty->input = stdin;
2303 tty->output = stdout; 2347 tty->output = stdout;
@@ -2805,6 +2849,8 @@ tty. The functions are run with one arg, the frame to be deleted. */)
2805 error ("No such terminal device: %s", name); 2849 error ("No such terminal device: %s", name);
2806 2850
2807 delete_tty (d); 2851 delete_tty (d);
2852
2853 return Qnil;
2808} 2854}
2809 2855
2810static int deleting_tty = 0; 2856static int deleting_tty = 0;
@@ -2952,7 +2998,7 @@ void
2952mark_ttys () 2998mark_ttys ()
2953{ 2999{
2954 struct tty_display_info *tty; 3000 struct tty_display_info *tty;
2955 Lisp_Object *p; 3001
2956 for (tty = tty_list; tty; tty = tty->next) 3002 for (tty = tty_list; tty; tty = tty->next)
2957 { 3003 {
2958 if (tty->top_frame) 3004 if (tty->top_frame)