summaryrefslogtreecommitdiffstats
path: root/compat
diff options
context:
space:
mode:
authorNicholas Marriott <nicholas.marriott@gmail.com>2009-03-31 22:08:45 +0000
committerNicholas Marriott <nicholas.marriott@gmail.com>2009-03-31 22:08:45 +0000
commitd13add828ad7737dea34384e7fc0bf116ffff605 (patch)
tree566c9d6e3833c847cf9fd2018cbc3b1a367a48fe /compat
parent92594c8029db87738aa99262a8275d57ce9e520d (diff)
More AIX tweaks.
Diffstat (limited to 'compat')
-rw-r--r--compat/forkpty-aix.c37
1 files changed, 25 insertions, 12 deletions
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");