lwsl_err("kill: %d, errno: %d (%s)\n", pid, errno, strerror(errno));
}
pid_t pid_out;
- int status = wait_proc(client->pid, &pid_out);
+ client->exit_status = wait_proc(client->pid, &pid_out);
if (pid_out > 0) {
- lwsl_notice("process exited with code %d, pid: %d\n", status, pid_out);
+ lwsl_notice("process exited with code %d, pid: %d\n", client->exit_status, pid_out);
}
close(client->pty);
void
tty_client_poll(struct tty_client *client) {
- if (!client->running || client->state == STATE_READY) return;
+ if (client->pid <= 0 || client->state == STATE_READY) return;
+
+ if (!client->running) {
+ memset(client->pty_buffer, 0, sizeof(client->pty_buffer));
+ client->pty_len = client->exit_status;
+ client->state = STATE_READY;
+ return;
+ }
fd_set des_set;
FD_ZERO (&des_set);
return -1;
}
}
- if (spawn_process(client) != 0) {
- return 1;
- }
+ if (spawn_process(client) != 0) return 1;
break;
default:
lwsl_warn("ignored unknown message type: %c\n", command);
int status = wait_proc(-1, &pid);
if (pid > 0) {
lwsl_notice("process exited with code %d, pid: %d\n", status, pid);
+ struct tty_client *iterator;
+ LIST_FOREACH(iterator, &server->clients, list) {
+ if (iterator->pid == pid) {
+ iterator->running = false;
+ iterator->exit_status = status;
+ break;
+ }
+ }
}
}