mirror of
https://github.com/tmate-io/tmate-ssh-server.git
synced 2020-11-18 19:53:51 -08:00
Avoid killing sessions when restarting server
This commit is contained in:
parent
5a8a116351
commit
b8a65c20be
@ -152,6 +152,9 @@ static void client_bootstrap(struct tmate_ssh_client *client)
|
|||||||
ssh_channel channel = NULL;
|
ssh_channel channel = NULL;
|
||||||
ssh_message msg;
|
ssh_message msg;
|
||||||
|
|
||||||
|
/* new process group, we don't want to die with our parent (upstart) */
|
||||||
|
setpgid(0, 0);
|
||||||
|
|
||||||
int flag = 1;
|
int flag = 1;
|
||||||
setsockopt(ssh_get_fd(session), IPPROTO_TCP, TCP_NODELAY,
|
setsockopt(ssh_get_fd(session), IPPROTO_TCP, TCP_NODELAY,
|
||||||
&flag, sizeof(flag));
|
&flag, sizeof(flag));
|
||||||
@ -178,27 +181,14 @@ static void client_bootstrap(struct tmate_ssh_client *client)
|
|||||||
|
|
||||||
static void handle_sigchld(void)
|
static void handle_sigchld(void)
|
||||||
{
|
{
|
||||||
int status, child_dead, child_exit_status;
|
siginfo_t si;
|
||||||
pid_t pid;
|
|
||||||
|
|
||||||
/* TODO cleanup the socket when the client dies */
|
/* TODO cleanup the socket when the client dies */
|
||||||
|
while (waitid(P_ALL, 0, &si, WEXITED | WNOHANG) >= 0 && si.si_pid) {
|
||||||
while ((pid = waitpid(0, &status, WNOHANG)) > 0) {
|
tmate_info("Child %d %s (%d)",
|
||||||
child_dead = 0;
|
si.si_pid,
|
||||||
|
si.si_code == CLD_EXITED ? "exited" : "killed",
|
||||||
if (WIFEXITED(status)) {
|
si.si_status);
|
||||||
child_dead = 1;
|
|
||||||
child_exit_status = WEXITSTATUS(status);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (WIFSIGNALED(status)) {
|
|
||||||
child_dead = 1;
|
|
||||||
child_exit_status = EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (child_dead)
|
|
||||||
tmate_info("Child reaped pid=%d exit=%d",
|
|
||||||
pid, child_exit_status);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user