mirror of
https://github.com/tsl0922/ttyd.git
synced 2025-12-23 12:14:20 +01:00
protocol: set the pty file descriptor non blocking
This commit is contained in:
@@ -187,24 +187,25 @@ thread_run_command(void *args) {
|
|||||||
int pty;
|
int pty;
|
||||||
fd_set des_set;
|
fd_set des_set;
|
||||||
pid_t pid = forkpty(&pty, NULL, NULL, NULL);
|
pid_t pid = forkpty(&pty, NULL, NULL, NULL);
|
||||||
|
if (pid < 0) { /* error */
|
||||||
switch (pid) {
|
lwsl_err("forkpty failed: %d (%s)\n", errno, strerror(errno));
|
||||||
case -1: /* error */
|
|
||||||
lwsl_err("forkpty, error: %d (%s)\n", errno, strerror(errno));
|
|
||||||
break;
|
|
||||||
case 0: /* child */
|
|
||||||
if (setenv("TERM", server->terminal_type, true) < 0) {
|
|
||||||
perror("setenv");
|
|
||||||
pthread_exit((void *) 1);
|
pthread_exit((void *) 1);
|
||||||
}
|
} else if (pid == 0) { /* child */
|
||||||
|
setenv("TERM", server->terminal_type, true);
|
||||||
// Don't pass the web socket onto child processes
|
// Don't pass the web socket onto child processes
|
||||||
close(lws_get_socket_fd(client->wsi));
|
close(lws_get_socket_fd(client->wsi));
|
||||||
if (execvp(argv[0], argv) < 0) {
|
if (execvp(argv[0], argv) < 0) {
|
||||||
perror("execvp");
|
perror("execvp failed\n");
|
||||||
pthread_exit((void *) 1);
|
_exit(-errno);
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
default: /* parent */
|
|
||||||
|
// set the pty file descriptor non blocking
|
||||||
|
int status_flags = fcntl(pty, F_GETFL);
|
||||||
|
if (status_flags != -1) {
|
||||||
|
fcntl(pty, F_SETFL, status_flags | O_NONBLOCK);
|
||||||
|
}
|
||||||
|
|
||||||
lwsl_notice("started process, pid: %d\n", pid);
|
lwsl_notice("started process, pid: %d\n", pid);
|
||||||
client->pid = pid;
|
client->pid = pid;
|
||||||
client->pty = pty;
|
client->pty = pty;
|
||||||
@@ -236,8 +237,6 @@ thread_run_command(void *args) {
|
|||||||
|
|
||||||
if (client->pty_len <= 0) break;
|
if (client->pty_len <= 0) break;
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
pthread_exit((void *) 0);
|
pthread_exit((void *) 0);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user