summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed T. Crigler <crigler@users.sourceforge.net>2005-04-10 19:38:43 +0000
committerNed T. Crigler <crigler@users.sourceforge.net>2005-04-10 19:38:43 +0000
commit3b070abf7ad3f8e9787dc5c30b81e42b1d6121bc (patch)
tree3427ebd41199b80d0a691e5ee9c9e64cf9f3d5aa
parent76b04f84f0b681b9d9d93fd83f392ef0651b8832 (diff)
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.
-rw-r--r--dtach.h1
-rw-r--r--main.c20
-rw-r--r--master.c5
3 files changed, 23 insertions, 3 deletions
diff --git a/dtach.h b/dtach.h
index f28099a..2ffd778 100644
--- a/dtach.h
+++ b/dtach.h
@@ -76,6 +76,7 @@
extern char *progname, *sockname;
extern int detach_char, no_suspend, redraw_method;
extern struct termios orig_term;
+extern int dont_have_tty;
enum
{
diff --git a/main.c b/main.c
index 2f7eb2c..f7bc13d 100644
--- a/main.c
+++ b/main.c
@@ -44,6 +44,7 @@ int redraw_method = REDRAW_UNSPEC;
** it to restore the original settings.
*/
struct termios orig_term;
+int dont_have_tty;
static void
usage()
@@ -210,10 +211,25 @@ main(int argc, char **argv)
/* Save the original terminal settings. */
if (tcgetattr(0, &orig_term) < 0)
{
- printf("%s: tcgetattr: %s\n", progname, strerror(errno));
- return 1;
+ if (errno == ENOTTY)
+ {
+ 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 (argc > 0)
diff --git a/master.c b/master.c
index 1f08a6b..4b03fab 100644
--- a/master.c
+++ b/master.c
@@ -114,7 +114,10 @@ init_pty(char **argv)
memset(&the_pty.ws, 0, sizeof(struct winsize));
/* 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)
return -1;
else if (the_pty.pid == 0)