diff --git a/GNUmakefile b/GNUmakefile index 18b92976..d40aeaff 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -1,4 +1,4 @@ -# $Id: GNUmakefile,v 1.77 2009-03-31 21:24:33 nicm Exp $ +# $Id: GNUmakefile,v 1.78 2009-03-31 22:08:45 nicm Exp $ .PHONY: clean @@ -76,7 +76,7 @@ SRCS+= compat/vis.c compat/strlcpy.c compat/strlcat.c compat/strtonum.c \ CFLAGS+= -DNO_TREE_H -DNO_ASPRINTF -DNO_QUEUE_H -DNO_VSYSLOG \ -DNO_PROGNAME -DNO_STRLCPY -DNO_STRLCAT -DNO_STRTONUM \ -DNO_SETPROCTITLE -DNO_QUEUE_H -DNO_TREE_H -DNO_FORKPTY -DNO_FGETLN \ - -DBROKEN_GETOPT -DBROKEN_POLL + -DBROKEN_GETOPT -DBROKEN_POLL -DNO_PATHS_H LDFLAGS+= -L/usr/local/lib endif diff --git a/compat/forkpty-aix.c b/compat/forkpty-aix.c index 6d4f5327..c1f59f92 100644 --- a/compat/forkpty-aix.c +++ b/compat/forkpty-aix.c @@ -1,4 +1,4 @@ -/* $Id: forkpty-aix.c,v 1.1 2009-03-31 21:23:18 nicm Exp $ */ +/* $Id: forkpty-aix.c,v 1.2 2009-03-31 22:08:45 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net> @@ -30,18 +30,14 @@ pid_t forkpty(int *master, unused char *name, unused struct termios *tio, struct winsize *ws) { - int slave; + int slave, fd; char *path; pid_t pid; if ((*master = open("/dev/ptc", O_RDWR|O_NOCTTY)) == -1) return (-1); - if (grantpt(*master) != 0) - goto out; - if (unlockpt(*master) != 0) - goto out; - if ((path = ptsname(*master)) == NULL) + if ((path = ttyname(*master)) == NULL) goto out; if ((slave = open(path, O_RDWR|O_NOCTTY)) == -1) goto out; @@ -52,11 +48,28 @@ forkpty(int *master, case 0: close(*master); - setsid(); -#ifdef TIOCSCTTY - if (ioctl(slave, TIOCSCTTY, NULL) == -1) - fatal("ioctl failed"); -#endif + fd = open(_PATH_TTY, O_RDWR|O_NOCTTY); + if (fd >= 0) { + ioctl(fd, TIOCNOTTY, NULL); + close(fd); + } + + if (setsid() < 0) + fatal("setsid"); + + fd = open(_PATH_TTY, O_RDWR|O_NOCTTY); + if (fd >= 0) + fatalx("open succeeded (failed to disconnect)"); + + fd = open(path, O_RDWR); + if (fd < 0) + fatal("open failed"); + close(fd); + + fd = open("/dev/tty", O_WRONLY); + if (fd < 0) + fatal("open failed"); + close(fd); if (ioctl(slave, TIOCSWINSZ, ws) == -1) fatal("ioctl failed"); diff --git a/tmux.h b/tmux.h index 94cb06cb..2a0745c1 100644 --- a/tmux.h +++ b/tmux.h @@ -1,4 +1,4 @@ -/* $Id: tmux.h,v 1.292 2009-03-29 11:18:28 nicm Exp $ */ +/* $Id: tmux.h,v 1.293 2009-03-31 22:08:45 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -109,6 +109,7 @@ extern const char *__progname; #define _PATH_BSHELL "/bin/sh" #define _PATH_TMP "/tmp/" #define _PATH_DEVNULL "/dev/null" +#define _PATH_TTY "/dev/tty" #endif /* Default configuration file. */