9 int forkpty(int *pm, char *name, const struct termios *tio, const struct winsize *ws)
11 int m, s, ec=0, p[2], cs;
15 if (openpty(&m, &s, name, tio, ws) < 0) return -1;
18 pthread_sigmask(SIG_BLOCK, &set, &oldset);
19 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
21 if (pipe2(p, O_CLOEXEC)) {
31 write(p[1], &errno, sizeof errno);
35 pthread_setcancelstate(cs, 0);
36 pthread_sigmask(SIG_SETMASK, &oldset, 0);
41 if (read(p[0], &ec, sizeof ec) > 0) {
43 waitpid(pid, &status, 0);
53 pthread_setcancelstate(cs, 0);
54 pthread_sigmask(SIG_SETMASK, &oldset, 0);