OLD | NEW |
(Empty) | |
| 1 *** Python-2.2.1.orig/Modules/posixmodule.c Tue Mar 12 16:38:31 2002 |
| 2 --- Python-2.2.1/Modules/posixmodule.c Tue May 21 01:16:29 2002 |
| 3 *************** |
| 4 *** 1904,1910 **** |
| 5 } |
| 6 #endif |
| 7 |
| 8 ! #if defined(HAVE_OPENPTY) || defined(HAVE_FORKPTY) |
| 9 #ifdef HAVE_PTY_H |
| 10 #include <pty.h> |
| 11 #else |
| 12 --- 1904,1913 ---- |
| 13 } |
| 14 #endif |
| 15 |
| 16 ! #if defined(HAVE_OPENPTY) || defined(HAVE_FORKPTY) || defined(sun) |
| 17 ! #ifdef sun |
| 18 ! #include <sys/stropts.h> |
| 19 ! #endif |
| 20 #ifdef HAVE_PTY_H |
| 21 #include <pty.h> |
| 22 #else |
| 23 *************** |
| 24 *** 1914,1920 **** |
| 25 #endif /* HAVE_PTY_H */ |
| 26 #endif /* defined(HAVE_OPENPTY) || defined(HAVE_FORKPTY) */ |
| 27 |
| 28 ! #if defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) |
| 29 static char posix_openpty__doc__[] = |
| 30 "openpty() -> (master_fd, slave_fd)\n\ |
| 31 Open a pseudo-terminal, returning open fd's for both master and slave end.\n"; |
| 32 --- 1917,1923 ---- |
| 33 #endif /* HAVE_PTY_H */ |
| 34 #endif /* defined(HAVE_OPENPTY) || defined(HAVE_FORKPTY) */ |
| 35 |
| 36 ! #if defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(sun) |
| 37 static char posix_openpty__doc__[] = |
| 38 "openpty() -> (master_fd, slave_fd)\n\ |
| 39 Open a pseudo-terminal, returning open fd's for both master and slave end.\n"; |
| 40 *************** |
| 41 *** 1925,1932 **** |
| 42 int master_fd, slave_fd; |
| 43 #ifndef HAVE_OPENPTY |
| 44 char * slave_name; |
| 45 #endif |
| 46 ! |
| 47 if (!PyArg_ParseTuple(args, ":openpty")) |
| 48 return NULL; |
| 49 |
| 50 --- 1928,1941 ---- |
| 51 int master_fd, slave_fd; |
| 52 #ifndef HAVE_OPENPTY |
| 53 char * slave_name; |
| 54 + #ifdef sun |
| 55 + void *sig_saved; |
| 56 #endif |
| 57 ! #endif |
| 58 ! #if !defined(HAVE_OPENPTY) && !defined(HAVE__GETPTY) && defined(sun) |
| 59 ! extern char *ptsname(); |
| 60 ! #endif |
| 61 ! |
| 62 if (!PyArg_ParseTuple(args, ":openpty")) |
| 63 return NULL; |
| 64 |
| 65 *************** |
| 66 *** 1933,1939 **** |
| 67 #ifdef HAVE_OPENPTY |
| 68 if (openpty(&master_fd, &slave_fd, NULL, NULL, NULL) != 0) |
| 69 return posix_error(); |
| 70 ! #else |
| 71 slave_name = _getpty(&master_fd, O_RDWR, 0666, 0); |
| 72 if (slave_name == NULL) |
| 73 return posix_error(); |
| 74 --- 1942,1948 ---- |
| 75 #ifdef HAVE_OPENPTY |
| 76 if (openpty(&master_fd, &slave_fd, NULL, NULL, NULL) != 0) |
| 77 return posix_error(); |
| 78 ! #elif HAVE__GETPTY |
| 79 slave_name = _getpty(&master_fd, O_RDWR, 0666, 0); |
| 80 if (slave_name == NULL) |
| 81 return posix_error(); |
| 82 *************** |
| 83 *** 1941,1946 **** |
| 84 --- 1950,1966 ---- |
| 85 slave_fd = open(slave_name, O_RDWR); |
| 86 if (slave_fd < 0) |
| 87 return posix_error(); |
| 88 + #else |
| 89 + master_fd = open("/dev/ptmx", O_RDWR|O_NOCTTY); /* open master */ |
| 90 + sig_saved = signal(SIGCHLD, SIG_DFL); |
| 91 + grantpt(master_fd); /* change permission of slav
e */ |
| 92 + unlockpt(master_fd); /* unlock slave */ |
| 93 + signal(SIGCHLD,sig_saved); |
| 94 + slave_name = ptsname(master_fd); /* get name of slave */ |
| 95 + slave_fd = open(slave_name, O_RDWR); /* open slave */ |
| 96 + ioctl(slave_fd, I_PUSH, "ptem"); /* push ptem */ |
| 97 + ioctl(slave_fd, I_PUSH, "ldterm"); /* push ldterm*/ |
| 98 + ioctl(slave_fd, I_PUSH, "ttcompat"); /* push ttcompat*/ |
| 99 #endif /* HAVE_OPENPTY */ |
| 100 |
| 101 return Py_BuildValue("(ii)", master_fd, slave_fd); |
| 102 *************** |
| 103 *** 1948,1954 **** |
| 104 } |
| 105 #endif /* defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) */ |
| 106 |
| 107 ! #ifdef HAVE_FORKPTY |
| 108 static char posix_forkpty__doc__[] = |
| 109 "forkpty() -> (pid, master_fd)\n\ |
| 110 Fork a new process with a new pseudo-terminal as controlling tty.\n\n\ |
| 111 --- 1968,1974 ---- |
| 112 } |
| 113 #endif /* defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) */ |
| 114 |
| 115 ! #if defined(HAVE_FORKPTY) || defined(sun) |
| 116 static char posix_forkpty__doc__[] = |
| 117 "forkpty() -> (pid, master_fd)\n\ |
| 118 Fork a new process with a new pseudo-terminal as controlling tty.\n\n\ |
| 119 *************** |
| 120 *** 1959,1968 **** |
| 121 --- 1979,2067 ---- |
| 122 posix_forkpty(PyObject *self, PyObject *args) |
| 123 { |
| 124 int master_fd, pid; |
| 125 + #if defined(sun) |
| 126 + int slave; |
| 127 + char * slave_name; |
| 128 + void *sig_saved; |
| 129 + int fd; |
| 130 + #endif |
| 131 |
| 132 if (!PyArg_ParseTuple(args, ":forkpty")) |
| 133 return NULL; |
| 134 + #if defined(sun) |
| 135 + master_fd = open("/dev/ptmx", O_RDWR|O_NOCTTY); /* open master */ |
| 136 + sig_saved = signal(SIGCHLD, SIG_DFL); |
| 137 + grantpt(master_fd); /* change permission of slav
e */ |
| 138 + unlockpt(master_fd); /* unlock slave */ |
| 139 + signal(SIGCHLD,sig_saved); |
| 140 + slave_name = ptsname(master_fd); /* get name of slave */ |
| 141 + slave = open(slave_name, O_RDWR); /* open slave */ |
| 142 + ioctl(slave, I_PUSH, "ptem"); /* push ptem */ |
| 143 + ioctl(slave, I_PUSH, "ldterm"); /* push ldterm*/ |
| 144 + ioctl(slave, I_PUSH, "ttcompat"); /* push ttcompat*/ |
| 145 + if (master_fd < 0 || slave < 0) |
| 146 + { |
| 147 + return posix_error(); |
| 148 + } |
| 149 + switch (pid = fork()) { |
| 150 + case -1: |
| 151 + return posix_error(); |
| 152 + case 0: |
| 153 + /* First disconnect from the old controlling tty. */ |
| 154 + #ifdef TIOCNOTTY |
| 155 + fd = open("/dev/tty", O_RDWR | O_NOCTTY); |
| 156 + if (fd >= 0) { |
| 157 + (void) ioctl(fd, TIOCNOTTY, NULL); |
| 158 + close(fd); |
| 159 + } |
| 160 + #endif /* TIOCNOTTY */ |
| 161 + if (setsid() < 0) |
| 162 + return posix_error(); |
| 163 + |
| 164 + /* |
| 165 + * Verify that we are successfully disconnected from the controlli
ng |
| 166 + * tty. |
| 167 + */ |
| 168 + fd = open("/dev/tty", O_RDWR | O_NOCTTY); |
| 169 + if (fd >= 0) { |
| 170 + return posix_error(); |
| 171 + close(fd); |
| 172 + } |
| 173 + /* Make it our controlling tty. */ |
| 174 + #ifdef TIOCSCTTY |
| 175 + if (ioctl(slave, TIOCSCTTY, NULL) < 0) |
| 176 + return posix_error(); |
| 177 + #endif /* TIOCSCTTY */ |
| 178 + fd = open(slave_name, O_RDWR); |
| 179 + if (fd < 0) { |
| 180 + return posix_error(); |
| 181 + } else { |
| 182 + close(fd); |
| 183 + } |
| 184 + /* Verify that we now have a controlling tty. */ |
| 185 + fd = open("/dev/tty", O_WRONLY); |
| 186 + if (fd < 0) |
| 187 + return posix_error(); |
| 188 + else { |
| 189 + close(fd); |
| 190 + } |
| 191 + (void) close(master_fd); |
| 192 + (void) dup2(slave, 0); |
| 193 + (void) dup2(slave, 1); |
| 194 + (void) dup2(slave, 2); |
| 195 + if (slave > 2) |
| 196 + (void) close(slave); |
| 197 + pid = 0; |
| 198 + break; |
| 199 + defautlt: |
| 200 + /* |
| 201 + * parent |
| 202 + */ |
| 203 + (void) close(slave); |
| 204 + } |
| 205 + #else |
| 206 pid = forkpty(&master_fd, NULL, NULL, NULL); |
| 207 + #endif |
| 208 if (pid == -1) |
| 209 return posix_error(); |
| 210 if (pid == 0) |
| 211 *************** |
| 212 *** 5607,5616 **** |
| 213 #ifdef HAVE_FORK |
| 214 {"fork", posix_fork, METH_VARARGS, posix_fork__doc__}, |
| 215 #endif /* HAVE_FORK */ |
| 216 ! #if defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) |
| 217 {"openpty", posix_openpty, METH_VARARGS, posix_openpty__doc__}, |
| 218 #endif /* HAVE_OPENPTY || HAVE__GETPTY */ |
| 219 ! #ifdef HAVE_FORKPTY |
| 220 {"forkpty", posix_forkpty, METH_VARARGS, posix_forkpty__doc__}, |
| 221 #endif /* HAVE_FORKPTY */ |
| 222 #ifdef HAVE_GETEGID |
| 223 --- 5706,5715 ---- |
| 224 #ifdef HAVE_FORK |
| 225 {"fork", posix_fork, METH_VARARGS, posix_fork__doc__}, |
| 226 #endif /* HAVE_FORK */ |
| 227 ! #if defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(sun) |
| 228 {"openpty", posix_openpty, METH_VARARGS, posix_openpty__doc__}, |
| 229 #endif /* HAVE_OPENPTY || HAVE__GETPTY */ |
| 230 ! #if defined(HAVE_FORKPTY) || defined(sun) |
| 231 {"forkpty", posix_forkpty, METH_VARARGS, posix_forkpty__doc__}, |
| 232 #endif /* HAVE_FORKPTY */ |
| 233 #ifdef HAVE_GETEGID |
OLD | NEW |