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);
61 slavefd
= open(name
, O_RDWR
);
63 perror("slave pty: open");
68 * Fork and execute the command.
85 fcntl(slavefd
, F_SETFD
, 0); /* don't close on exec */
91 tcsetpgrp(slavefd
, getpgrp());
92 /* Close everything _else_, for tidiness. */
93 for (i
= 3; i
< 1024; i
++)
96 char term_env_var
[10 + sizeof(cfg
.termtype
)];
97 sprintf(term_env_var
, "TERM=%s", cfg
.termtype
);
101 execvp(pty_argv
[0], pty_argv
);
103 execl(getenv("SHELL"), getenv("SHELL"), NULL
);
105 * If we're here, exec has gone badly foom.
117 * Called to send data down the pty.
119 static int pty_send(char *buf
, int len
)
122 int ret
= write(pty_master_fd
, buf
, len
);
124 perror("write pty master");
134 * Called to query the current socket sendability status.
136 static int pty_sendbuffer(void)
142 * Called to set the size of the window
144 static void pty_size(void)
148 size
.ws_row
= (unsigned short)rows
;
149 size
.ws_col
= (unsigned short)cols
;
150 ioctl(pty_master_fd
, TIOCSWINSZ
, (void *)&size
);
155 * Send special codes.
157 static void pty_special(Telnet_Special code
)
163 static Socket
pty_socket(void)
165 return NULL
; /* shouldn't ever be needed */
168 static int pty_sendok(void)
173 static void pty_unthrottle(int backlog
)
178 static int pty_ldisc(int option
)
180 return 0; /* neither editing nor echoing */
183 static int pty_exitcode(void)
185 /* Shouldn't ever be required */
189 Backend pty_backend
= {