forked from github/abduco
Fix AIX support
This commit is contained in:
parent
d23c9982c7
commit
6df4421e6c
|
|
@ -17,23 +17,13 @@
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stropts.h>
|
#include <stropts.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <paths.h>
|
#include <paths.h>
|
||||||
|
|
||||||
/* Fatal errors. */
|
pid_t forkpty(int *master, char *name, struct termios *tio, struct winsize *ws)
|
||||||
#ifdef NDEBUG
|
|
||||||
#define debug(format, args...)
|
|
||||||
#else
|
|
||||||
#define debug eprint
|
|
||||||
#endif
|
|
||||||
#define fatal(msg) debug("%s: %s", __func__, msg);
|
|
||||||
|
|
||||||
pid_t
|
|
||||||
forkpty(int *master, char *name, struct termios *tio, struct winsize *ws)
|
|
||||||
{
|
{
|
||||||
int slave, fd;
|
int slave, fd;
|
||||||
char *path;
|
char *path;
|
||||||
|
|
@ -41,7 +31,7 @@ forkpty(int *master, char *name, struct termios *tio, struct winsize *ws)
|
||||||
struct termios tio2;
|
struct termios tio2;
|
||||||
|
|
||||||
if ((*master = open("/dev/ptc", O_RDWR|O_NOCTTY)) == -1)
|
if ((*master = open("/dev/ptc", O_RDWR|O_NOCTTY)) == -1)
|
||||||
return (-1);
|
return -1;
|
||||||
|
|
||||||
if ((path = ttyname(*master)) == NULL)
|
if ((path = ttyname(*master)) == NULL)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
@ -61,47 +51,47 @@ forkpty(int *master, char *name, struct termios *tio, struct winsize *ws)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (setsid() < 0)
|
if (setsid() < 0)
|
||||||
fatal("setsid");
|
return -1;
|
||||||
|
|
||||||
fd = open(_PATH_TTY, O_RDWR|O_NOCTTY);
|
fd = open(_PATH_TTY, O_RDWR|O_NOCTTY);
|
||||||
if (fd >= 0)
|
if (fd >= 0)
|
||||||
fatal("open succeeded (failed to disconnect)");
|
return -1;
|
||||||
|
|
||||||
fd = open(path, O_RDWR);
|
fd = open(path, O_RDWR);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
fatal("open failed");
|
return -1;
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
fd = open("/dev/tty", O_WRONLY);
|
fd = open("/dev/tty", O_WRONLY);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
fatal("open failed");
|
return -1;
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
if (tcgetattr(slave, &tio2) != 0)
|
if (tcgetattr(slave, &tio2) != 0)
|
||||||
fatal("tcgetattr failed");
|
return -1;
|
||||||
if (tio != NULL)
|
if (tio != NULL)
|
||||||
memcpy(tio2.c_cc, tio->c_cc, sizeof tio2.c_cc);
|
memcpy(tio2.c_cc, tio->c_cc, sizeof tio2.c_cc);
|
||||||
tio2.c_cc[VERASE] = '\177';
|
tio2.c_cc[VERASE] = '\177';
|
||||||
if (tcsetattr(slave, TCSAFLUSH, &tio2) == -1)
|
if (tcsetattr(slave, TCSAFLUSH, &tio2) == -1)
|
||||||
fatal("tcsetattr failed");
|
return -1;
|
||||||
if (ioctl(slave, TIOCSWINSZ, ws) == -1)
|
if (ioctl(slave, TIOCSWINSZ, ws) == -1)
|
||||||
fatal("ioctl failed");
|
return -1;
|
||||||
|
|
||||||
dup2(slave, 0);
|
dup2(slave, 0);
|
||||||
dup2(slave, 1);
|
dup2(slave, 1);
|
||||||
dup2(slave, 2);
|
dup2(slave, 2);
|
||||||
if (slave > 2)
|
if (slave > 2)
|
||||||
close(slave);
|
close(slave);
|
||||||
return (0);
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
close(slave);
|
close(slave);
|
||||||
return (pid);
|
return pid;
|
||||||
|
|
||||||
out:
|
out:
|
||||||
if (*master != -1)
|
if (*master != -1)
|
||||||
close(*master);
|
close(*master);
|
||||||
if (slave != -1)
|
if (slave != -1)
|
||||||
close(slave);
|
close(slave);
|
||||||
return (-1);
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue