1 --- ../mosh/src/frontend/pty.cc 2016-04-29 00:42:37.207832463 +1000
2 +++ ./src/frontend/pty.cc 2016-04-29 00:40:31.306486322 +1000
5 + Mosh: the mobile shell
6 + Copyright 2012 Keith Winstein
8 + This program is free software: you can redistribute it and/or modify
9 + it under the terms of the GNU General Public License as published by
10 + the Free Software Foundation, either version 3 of the License, or
11 + (at your option) any later version.
13 + This program is distributed in the hope that it will be useful,
14 + but WITHOUT ANY WARRANTY; without even the implied warranty of
15 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 + GNU General Public License for more details.
18 + You should have received a copy of the GNU General Public License
19 + along with this program. If not, see <http://www.gnu.org/licenses/>.
24 +#include <sys/types.h>
25 +#include <sys/stat.h>
26 +#include <sys/ioctl.h>
36 +/* from dropbear 0.53.1 sshpty.c, original license: "can be used freely for any purpose." */
37 +int my_openpty (int *amaster, int *aslave, char *name, const struct termios *termp,
38 + const struct winsize *winp)
43 + master = open("/dev/ptmx", O_RDWR);
45 +// TRACE(("Fail to open master"))
49 + if (grantpt(master))
52 + if (unlockpt(master))
55 + name_slave = ptsname(master);
56 +// TRACE(("openpty: slave name %s", name_slave))
57 + slave = open(name_slave, O_RDWR | O_NOCTTY);
64 + tcsetattr(slave, TCSAFLUSH, termp);
66 + ioctl (slave, TIOCSWINSZ, winp);
71 + strcpy(name, name_slave);
81 +#ifndef HAVE_LOGIN_TTY
82 +/* from glibc 2.14, login/login_tty.c, under the BSD license */
83 +int login_tty(int fd)
87 + if (ioctl(fd, TIOCSCTTY, (char *)NULL) == -1)
91 + /* This might work. */
92 + char *fdname = ttyname (fd);
102 + newfd = open (fdname, O_RDWR);
103 + (void) close (newfd);
107 + while (dup2(fd, 0) == -1 && errno == EBUSY)
109 + while (dup2(fd, 1) == -1 && errno == EBUSY)
111 + while (dup2(fd, 2) == -1 && errno == EBUSY)
119 +int my_forkpty (int *amaster, char *name, const struct termios *termp, const struct winsize *winp) {
121 +//return forkpty(amaster, name, termp, winp);
123 +/* from glibc 2.14, login/forkpty.c, under the LGPL 2.1 (or later) license */
124 + int master, slave, pid;
126 + if (openpty (&master, &slave, name, termp, winp) == -1)
129 + switch (pid = fork ())
138 + if (login_tty (slave))