Mercurial > emacs
comparison src/term.c @ 83498:f0987e2f27e2
Clean up tty device handling. Change name of controlling tty from nil to "/dev/tty".
* src/term.c: Include errno.h.
(Fcontrolling_tty_p): Compare name with "/dev/tty", not NULL.
(Fresume_tty): Handle errors on reopening ttys. Don't
dissociate if terminal was explicitly opened on the controlling
terminal.
(init_tty): Initialize local pointers. Always set name (use
"/dev/tty" for controlling tty.) Remove special case for name == NULL.
git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-538
author | Karoly Lorentey <lorentey@elte.hu> |
---|---|
date | Sun, 26 Mar 2006 16:05:17 +0000 |
parents | b98066f4aa10 |
children | c1e013e3dc0e |
comparison
equal
deleted
inserted
replaced
83497:a25bb5ef27bf | 83498:f0987e2f27e2 |
---|---|
23 | 23 |
24 #include <config.h> | 24 #include <config.h> |
25 #include <stdio.h> | 25 #include <stdio.h> |
26 #include <ctype.h> | 26 #include <ctype.h> |
27 #include <string.h> | 27 #include <string.h> |
28 | 28 #include <errno.h> |
29 #include <sys/file.h> | 29 #include <sys/file.h> |
30 | |
31 #include <unistd.h> /* For isatty. */ | 30 #include <unistd.h> /* For isatty. */ |
32 | 31 |
33 #if HAVE_TERMIOS_H | 32 #if HAVE_TERMIOS_H |
34 #include <termios.h> /* For TIOCNOTTY. */ | 33 #include <termios.h> /* For TIOCNOTTY. */ |
35 #endif | 34 #endif |
2072 (terminal) | 2071 (terminal) |
2073 Lisp_Object terminal; | 2072 Lisp_Object terminal; |
2074 { | 2073 { |
2075 struct terminal *t = get_terminal (terminal, 1); | 2074 struct terminal *t = get_terminal (terminal, 1); |
2076 | 2075 |
2077 if (t->type != output_termcap || t->display_info.tty->name) | 2076 if (t->type != output_termcap || strcmp (t->display_info.tty->name, "/dev/tty")) |
2078 return Qnil; | 2077 return Qnil; |
2079 else | 2078 else |
2080 return Qt; | 2079 return Qt; |
2081 } | 2080 } |
2082 | 2081 |
2191 if (get_named_tty (t->display_info.tty->name)) | 2190 if (get_named_tty (t->display_info.tty->name)) |
2192 error ("Cannot resume display while another display is active on the same device"); | 2191 error ("Cannot resume display while another display is active on the same device"); |
2193 | 2192 |
2194 fd = emacs_open (t->display_info.tty->name, O_RDWR | O_NOCTTY, 0); | 2193 fd = emacs_open (t->display_info.tty->name, O_RDWR | O_NOCTTY, 0); |
2195 | 2194 |
2196 /* XXX What if open fails? */ | 2195 if (fd == -1) |
2197 | 2196 error ("Can not reopen tty device %s: %s", t->display_info.tty->name, strerror (errno)); |
2198 dissociate_if_controlling_tty (fd); | 2197 |
2198 if (strcmp (t->display_info.tty->name, "/dev/tty")) | |
2199 dissociate_if_controlling_tty (fd); | |
2199 | 2200 |
2200 t->display_info.tty->output = fdopen (fd, "w+"); | 2201 t->display_info.tty->output = fdopen (fd, "w+"); |
2201 t->display_info.tty->input = t->display_info.tty->output; | 2202 t->display_info.tty->input = t->display_info.tty->output; |
2202 | 2203 |
2203 add_keyboard_wait_descriptor (fd); | 2204 add_keyboard_wait_descriptor (fd); |
2301 If MUST_SUCCEED is true, then all errors are fatal. */ | 2302 If MUST_SUCCEED is true, then all errors are fatal. */ |
2302 | 2303 |
2303 struct terminal * | 2304 struct terminal * |
2304 init_tty (char *name, char *terminal_type, int must_succeed) | 2305 init_tty (char *name, char *terminal_type, int must_succeed) |
2305 { | 2306 { |
2306 char *area; | 2307 char *area = NULL; |
2307 char **address = &area; | 2308 char **address = &area; |
2308 char *buffer = NULL; | 2309 char *buffer = NULL; |
2309 int buffer_size = 4096; | 2310 int buffer_size = 4096; |
2310 register char *p; | 2311 register char *p = NULL; |
2311 int status; | 2312 int status; |
2312 struct tty_display_info *tty; | 2313 struct tty_display_info *tty = NULL; |
2313 struct terminal *terminal; | 2314 struct terminal *terminal = NULL; |
2315 int ctty = 0; /* 1 if asked to open controlling tty. */ | |
2314 | 2316 |
2315 if (!terminal_type) | 2317 if (!terminal_type) |
2316 maybe_fatal (must_succeed, 0, 0, | 2318 maybe_fatal (must_succeed, 0, 0, |
2317 "Unknown terminal type", | 2319 "Unknown terminal type", |
2318 "Unknown terminal type"); | 2320 "Unknown terminal type"); |
2375 terminal->frame_up_to_date_hook = 0; /* Not needed. */ | 2377 terminal->frame_up_to_date_hook = 0; /* Not needed. */ |
2376 | 2378 |
2377 terminal->delete_frame_hook = &delete_tty_output; | 2379 terminal->delete_frame_hook = &delete_tty_output; |
2378 terminal->delete_terminal_hook = &delete_tty; | 2380 terminal->delete_terminal_hook = &delete_tty; |
2379 | 2381 |
2380 if (name) | 2382 if (name == NULL) |
2381 { | 2383 name = "/dev/tty"; |
2382 int fd; | 2384 if (!strcmp (name, "/dev/tty")) |
2383 FILE *file; | 2385 ctty = 1; |
2386 | |
2387 { | |
2388 int fd; | |
2389 FILE *file; | |
2384 | 2390 |
2385 #ifdef O_IGNORE_CTTY | 2391 #ifdef O_IGNORE_CTTY |
2392 if (!ctty) | |
2386 /* Open the terminal device. Don't recognize it as our | 2393 /* Open the terminal device. Don't recognize it as our |
2387 controlling terminal, and don't make it the controlling tty | 2394 controlling terminal, and don't make it the controlling tty |
2388 if we don't have one at the moment. */ | 2395 if we don't have one at the moment. */ |
2389 fd = emacs_open (name, O_RDWR | O_IGNORE_CTTY | O_NOCTTY, 0); | 2396 fd = emacs_open (name, O_RDWR | O_IGNORE_CTTY | O_NOCTTY, 0); |
2397 else | |
2390 #else | 2398 #else |
2391 /* Alas, O_IGNORE_CTTY is a GNU extension that seems to be only | 2399 /* Alas, O_IGNORE_CTTY is a GNU extension that seems to be only |
2392 defined on Hurd. On other systems, we need to dissociate | 2400 defined on Hurd. On other systems, we need to explicitly |
2393 ourselves from the controlling tty when we want to open a | 2401 dissociate ourselves from the controlling tty when we want to |
2394 frame on the same terminal. */ | 2402 open a frame on the same terminal. */ |
2395 | |
2396 fd = emacs_open (name, O_RDWR | O_NOCTTY, 0); | 2403 fd = emacs_open (name, O_RDWR | O_NOCTTY, 0); |
2397 | |
2398 #endif /* O_IGNORE_CTTY */ | 2404 #endif /* O_IGNORE_CTTY */ |
2399 | 2405 |
2400 if (fd < 0) | 2406 if (fd < 0) |
2401 { | 2407 maybe_fatal (must_succeed, buffer, terminal, |
2402 delete_tty (terminal); | 2408 "Could not open file: %s", |
2403 error ("Could not open file: %s", name); | 2409 "Could not open file: %s", |
2404 } | 2410 name); |
2405 if (!isatty (fd)) | 2411 if (!isatty (fd)) |
2406 { | 2412 { |
2407 close (fd); | 2413 close (fd); |
2408 error ("Not a tty device: %s", name); | 2414 maybe_fatal (must_succeed, buffer, terminal, |
2409 } | 2415 "Not a tty device: %s", |
2410 | 2416 "Not a tty device: %s", |
2417 name); | |
2418 } | |
2419 | |
2420 #ifndef O_IGNORE_CTTY | |
2421 if (!ctty) | |
2411 dissociate_if_controlling_tty (fd); | 2422 dissociate_if_controlling_tty (fd); |
2412 | 2423 #endif |
2413 file = fdopen (fd, "w+"); | 2424 |
2414 tty->name = xstrdup (name); | 2425 file = fdopen (fd, "w+"); |
2415 terminal->name = xstrdup (name); | 2426 tty->name = xstrdup (name); |
2416 tty->input = file; | 2427 terminal->name = xstrdup (name); |
2417 tty->output = file; | 2428 tty->input = file; |
2418 } | 2429 tty->output = file; |
2419 else | 2430 } |
2420 { | |
2421 if (no_controlling_tty) | |
2422 { | |
2423 /* Opening a frame on stdout is unsafe if we have | |
2424 disconnected our controlling terminal. */ | |
2425 error ("There is no controlling terminal any more"); | |
2426 } | |
2427 tty->name = 0; | |
2428 terminal->name = xstrdup (ttyname (0)); | |
2429 tty->input = stdin; | |
2430 tty->output = stdout; | |
2431 } | |
2432 | 2431 |
2433 tty->type = xstrdup (terminal_type); | 2432 tty->type = xstrdup (terminal_type); |
2434 | 2433 |
2435 add_keyboard_wait_descriptor (fileno (tty->input)); | 2434 add_keyboard_wait_descriptor (fileno (tty->input)); |
2436 | 2435 |