2 #define _XOPEN_SOURCE_EXTENDED
11 #include <sys/ioctl.h>
25 static void pty_size(void);
28 * Called to set up the pty.
30 * Returns an error message, or NULL on success.
32 * Also places the canonical host name into `realhost'. It must be
33 * freed by the caller.
35 static char *pty_init(char *host
, int port
, char **realhost
, int nodelay
)
38 char name
[FILENAME_MAX
];
41 pty_master_fd
= open("/dev/ptmx", O_RDWR
);
43 if (pty_master_fd
< 0) {
44 perror("/dev/ptmx: open");
48 if (grantpt(pty_master_fd
) < 0) {
53 if (unlockpt(pty_master_fd
) < 0) {
58 name
[FILENAME_MAX
-1] = '\0';
59 strncpy(name
, ptsname(pty_master_fd
), FILENAME_MAX
-1);
62 * Fork and execute the command.
76 slavefd
= open(name
, O_RDWR
);
78 perror("slave pty: open");
86 fcntl(slavefd
, F_SETFD
, 0); /* don't close on exec */
91 ioctl(slavefd
, TIOCSCTTY
, 1);
93 tcsetpgrp(slavefd
, pgrp
);
95 close(open(name
, O_WRONLY
, 0));
97 /* Close everything _else_, for tidiness. */
98 for (i
= 3; i
< 1024; i
++)
101 char term_env_var
[10 + sizeof(cfg
.termtype
)];
102 sprintf(term_env_var
, "TERM=%s", cfg
.termtype
);
103 putenv(term_env_var
);
106 execvp(pty_argv
[0], pty_argv
);
108 execl(getenv("SHELL"), getenv("SHELL"), NULL
);
110 * If we're here, exec has gone badly foom.
122 * Called to send data down the pty.
124 static int pty_send(char *buf
, int len
)
127 int ret
= write(pty_master_fd
, buf
, len
);
129 perror("write pty master");
139 * Called to query the current socket sendability status.
141 static int pty_sendbuffer(void)
147 * Called to set the size of the window
149 static void pty_size(void)
153 size
.ws_row
= (unsigned short)rows
;
154 size
.ws_col
= (unsigned short)cols
;
155 ioctl(pty_master_fd
, TIOCSWINSZ
, (void *)&size
);
160 * Send special codes.
162 static void pty_special(Telnet_Special code
)
168 static Socket
pty_socket(void)
170 return NULL
; /* shouldn't ever be needed */
173 static int pty_sendok(void)
178 static void pty_unthrottle(int backlog
)
183 static int pty_ldisc(int option
)
185 return 0; /* neither editing nor echoing */
188 static int pty_exitcode(void)
190 /* Shouldn't ever be required */
194 Backend pty_backend
= {