remove_proc() calls remove_from_script_list().

This will prevent a race in the case where a proc is deleted (i.e.,
user is disconnected) but a running script terminates afterwards and
tries to reference the deleted proc.
This commit is contained in:
Nikos Mavrogiannopoulos
2014-01-08 20:20:25 +01:00
parent 7b4c98680e
commit 80e5d84c6d
2 changed files with 3 additions and 2 deletions

View File

@@ -42,6 +42,7 @@
#include <route-add.h>
#include <ip-lease.h>
#include <ipc.pb-c.h>
#include <script-list.h>
#include <vpn.h>
#include <cookies.h>
@@ -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 */

View File

@@ -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);
}
}