#include #include #include #include #include #include #include #include static int myforkpty(int *fd, const char *fn, struct winsize *ws) { #if 1 char Buf[4096]; int ptf = open(fn, O_RDWR); int ptnum = 0; if(ptf < 0)return ptf; ptnum=0;ioctl(ptf, TIOCGPTN, &ptnum); ptnum=0;ioctl(ptf, TIOCSPTLCK, &ptnum); ptnum=0;ioctl(ptf, TIOCGPTN, &ptnum); sprintf(Buf, "/dev/pts/%d", ptnum); *fd = open(Buf, O_RDWR | O_NOCTTY); if(*fd < 0) return -1; ioctl(*fd, TIOCSWINSZ, ws); ptnum = fork(); if(ptnum < 0) { close(*fd); return -1; } else if(ptnum > 0) { close(*fd); *fd = ptf; } else if(!ptnum) { close(ptf); setsid(); ioctl(*fd, TIOCSCTTY, 1); dup2(*fd, 0); dup2(*fd, 1); dup2(*fd, 2); close(*fd); } return ptnum; #else return forkpty(fd, NULL, NULL, ws); #endif } int main(void) { struct winsize ws; int p, fd; memset(&ws, 0, sizeof(ws)); ws.ws_col=80; ws.ws_row=50; p = myforkpty(&fd, "/etc/oktober/dev/ptmx", &ws); //p = myforkpty(&fd, "/dev/ptmx", &ws); fprintf(stderr, "myforkpty returned %d\n", p); fflush(stderr); if(p < 0) { perror("forkpty"); } if(!p) { execl(getenv("SHELL"), getenv("SHELL"), NULL); } if(!fork()) { dup2(fd, 1); dup2(fd, 2); execl("/bin/cat", "cat", NULL); } if(!fork()) { dup2(fd, 0); execl("/bin/cat", "cat", NULL); } while(wait(NULL) >= 0); return 0; }