diff options
| author | Karoly Lorentey | 2006-03-26 16:05:17 +0000 |
|---|---|---|
| committer | Karoly Lorentey | 2006-03-26 16:05:17 +0000 |
| commit | 59b3194ca9708b904c87d52bb9e074e32b7d9089 (patch) | |
| tree | dcc26d7abc0f9ea7871a43254a10cf0cbf777800 /src | |
| parent | 6a5af08f8d3bb831a78edf17e9c38813bbfbb6f8 (diff) | |
| download | emacs-59b3194ca9708b904c87d52bb9e074e32b7d9089.tar.gz emacs-59b3194ca9708b904c87d52bb9e074e32b7d9089.zip | |
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
Diffstat (limited to 'src')
| -rw-r--r-- | src/term.c | 95 |
1 files changed, 47 insertions, 48 deletions
diff --git a/src/term.c b/src/term.c index b1183ed9e2a..c98c7db2c0d 100644 --- a/src/term.c +++ b/src/term.c | |||
| @@ -25,9 +25,8 @@ Boston, MA 02110-1301, USA. */ | |||
| 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 |
| @@ -2074,7 +2073,7 @@ is not on a tty device. */) | |||
| 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; |
| @@ -2193,9 +2192,11 @@ the currently selected frame. */) | |||
| 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) |
| 2196 | error ("Can not reopen tty device %s: %s", t->display_info.tty->name, strerror (errno)); | ||
| 2197 | 2197 | ||
| 2198 | dissociate_if_controlling_tty (fd); | 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; |
| @@ -2303,14 +2304,15 @@ static void maybe_fatal(); | |||
| 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, |
| @@ -2377,58 +2379,55 @@ init_tty (char *name, char *terminal_type, int must_succeed) | |||
| 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", |
| 2416 | "Not a tty device: %s", | ||
| 2417 | name); | ||
| 2418 | } | ||
| 2410 | 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 | ||