diff --git a/src/main-misc.c b/src/main-misc.c index e8f995cd..d3ba212f 100644 --- a/src/main-misc.c +++ b/src/main-misc.c @@ -42,6 +42,7 @@ #include #include #include +#include #include #include @@ -270,6 +271,7 @@ void remove_proc(main_server_st* s, struct proc_st *proc, unsigned k) if (k) kill(proc->pid, SIGTERM); + remove_from_script_list(s, proc); user_disconnected(s, proc); /* close the intercomm fd */ diff --git a/src/main.c b/src/main.c index 70e0e1e0..ee92a8f9 100644 --- a/src/main.c +++ b/src/main.c @@ -422,10 +422,10 @@ struct script_wait_st *stmp = NULL, *spos; list_for_each_safe(&s->script_list.head, stmp, spos, list) { if (stmp->pid == pid) { mslog(s, stmp->proc, LOG_DEBUG, "%s-script exit status: %u", stmp->up?"connect":"disconnect", estatus); + list_del(&stmp->list); ret = handle_script_exit(s, stmp->proc, estatus); if (ret < 0) remove_proc(s, stmp->proc, 1); - list_del(&stmp->list); free(stmp); break; } @@ -1021,7 +1021,6 @@ fork_failed: if (FD_ISSET(ctmp->fd, &rd_set)) { ret = handle_commands(&s, ctmp); if (ret < 0) { - remove_from_script_list(&s, ctmp); remove_proc(&s, ctmp, (ret!=ERR_WORKER_TERMINATED)?1:0); } }