Lines 78-85
Link Here
|
78 |
#definePTYCHAR1 "pqrstuvwxyz" |
78 |
#definePTYCHAR1 "pqrstuvwxyz" |
79 |
#definePTYCHAR2 "0123456789abcdef" |
79 |
#definePTYCHAR2 "0123456789abcdef" |
80 |
|
80 |
|
81 |
/* allocate one pty/tty pair */ |
81 |
/* allocate one pty/tty pair, the old way */ |
82 |
static int get_pty(char *tty_str) |
82 |
static int old_get_pty(char *tty_str) |
83 |
{ |
83 |
{ |
84 |
int fd; |
84 |
int fd; |
85 |
char ptydev[] = "/dev/pty??"; |
85 |
char ptydev[] = "/dev/pty??"; |
Lines 103-108
Link Here
|
103 |
return -1; |
103 |
return -1; |
104 |
} |
104 |
} |
105 |
|
105 |
|
|
|
106 |
/* ...and the devpts way */ |
107 |
static int get_pty(char *tty_str) |
108 |
{ |
109 |
int fd; |
110 |
fd = getpt(); |
111 |
if(!fd) return -1; |
112 |
grantpt(fd); |
113 |
unlockpt(fd); |
114 |
char *ttyname = ptsname(); |
115 |
strcpy(tty_str, ttyname); |
116 |
return fd; |
117 |
} |
118 |
|
106 |
static int run_process(const char *path, char **argv, |
119 |
static int run_process(const char *path, char **argv, |
107 |
int *fd_ptr, int *pid_ptr) |
120 |
int *fd_ptr, int *pid_ptr) |
108 |
{ |
121 |
{ |
Lines 111-116
Link Here
|
111 |
struct winsize ws; |
124 |
struct winsize ws; |
112 |
|
125 |
|
113 |
pty_fd = get_pty(tty_name); |
126 |
pty_fd = get_pty(tty_name); |
|
|
127 |
|
128 |
/* Try using legacy PTYs if the above doesn't work. */ |
129 |
if(pty_fd < 0) { |
130 |
pty_fd = old_get_pty(tty_name); |
131 |
} |
132 |
|
114 |
fcntl(pty_fd, F_SETFL, O_NONBLOCK); |
133 |
fcntl(pty_fd, F_SETFL, O_NONBLOCK); |
115 |
if (pty_fd < 0) |
134 |
if (pty_fd < 0) |
116 |
return -1; |
135 |
return -1; |