Allow the dtach -n mode to be used without a terminal. If a terminal is not

present when dtach is started, we now rely on whatever default terminal
settings the kernel uses.
This commit is contained in:
Ned T. Crigler 2005-04-10 19:38:43 +00:00
parent 76b04f84f0
commit 3b070abf7a
3 changed files with 23 additions and 3 deletions

View File

@ -76,6 +76,7 @@
extern char *progname, *sockname; extern char *progname, *sockname;
extern int detach_char, no_suspend, redraw_method; extern int detach_char, no_suspend, redraw_method;
extern struct termios orig_term; extern struct termios orig_term;
extern int dont_have_tty;
enum enum
{ {

20
main.c
View File

@ -44,6 +44,7 @@ int redraw_method = REDRAW_UNSPEC;
** it to restore the original settings. ** it to restore the original settings.
*/ */
struct termios orig_term; struct termios orig_term;
int dont_have_tty;
static void static void
usage() usage()
@ -210,10 +211,25 @@ main(int argc, char **argv)
/* Save the original terminal settings. */ /* Save the original terminal settings. */
if (tcgetattr(0, &orig_term) < 0) if (tcgetattr(0, &orig_term) < 0)
{ {
printf("%s: tcgetattr: %s\n", progname, strerror(errno)); if (errno == ENOTTY)
return 1; {
memset(&orig_term, 0, sizeof(struct termios));
dont_have_tty = 1;
}
else
{
printf("%s: tcgetattr: %s\n", progname,
strerror(errno));
return 1;
}
} }
if (dont_have_tty && mode != 'n')
{
printf("%s: Attaching to a session requires a terminal.\n",
progname);
return 1;
}
if (mode == 'a') if (mode == 'a')
{ {
if (argc > 0) if (argc > 0)

View File

@ -114,7 +114,10 @@ init_pty(char **argv)
memset(&the_pty.ws, 0, sizeof(struct winsize)); memset(&the_pty.ws, 0, sizeof(struct winsize));
/* Create the pty process */ /* Create the pty process */
the_pty.pid = forkpty(&the_pty.fd, NULL, &the_pty.term, NULL); if (!dont_have_tty)
the_pty.pid = forkpty(&the_pty.fd, NULL, &the_pty.term, NULL);
else
the_pty.pid = forkpty(&the_pty.fd, NULL, NULL, NULL);
if (the_pty.pid < 0) if (the_pty.pid < 0)
return -1; return -1;
else if (the_pty.pid == 0) else if (the_pty.pid == 0)