client->running = false;
+ pthread_mutex_lock(&client->mutex);
+ client->state = STATE_DONE;
+ pthread_cond_signal(&client->cond);
+ pthread_mutex_unlock(&client->mutex);
+
// kill process and free resource
lwsl_notice("sending %s (%d) to process %d\n", server->sig_name, server->sig_code, client->pid);
if (kill(client->pid, server->sig_code) != 0) {
while (client->running) {
FD_ZERO (&des_set);
FD_SET (pty, &des_set);
-
- if (select(pty + 1, &des_set, NULL, NULL, NULL) < 0)
- break;
+ struct timeval tv = { 1, 0 };
+ int ret = select(pty + 1, &des_set, NULL, NULL, &tv);
+ if (ret == 0) continue;
+ if (ret < 0) break;
if (FD_ISSET (pty, &des_set)) {
while (client->running) {
break;
}
if (send_initial_message(wsi, client->initial_cmd_index) < 0) {
- tty_client_remove(client);
lws_close_reason(wsi, LWS_CLOSE_STATUS_UNEXPECTED_CONDITION, NULL, 0);
return -1;
}
// read error or client exited, close connection
if (client->pty_len <= 0) {
- tty_client_remove(client);
lws_close_reason(wsi,
client->pty_len == 0 ? LWS_CLOSE_STATUS_NORMAL
: LWS_CLOSE_STATUS_UNEXPECTED_CONDITION,
return 0;
if (write(client->pty, client->buffer + 1, client->len - 1) == -1) {
lwsl_err("write INPUT to pty: %d (%s)\n", errno, strerror(errno));
- tty_client_remove(client);
lws_close_reason(wsi, LWS_CLOSE_STATUS_UNEXPECTED_CONDITION, NULL, 0);
return -1;
}
lwsl_warn("WS authentication failed with token: %s\n", token);
}
if (!client->authenticated) {
- tty_client_remove(client);
lws_close_reason(wsi, LWS_CLOSE_STATUS_POLICY_VIOLATION, NULL, 0);
return -1;
}