mirror of
https://gitlab.com/openconnect/ocserv.git
synced 2026-02-10 08:46:58 +08:00
remove_proc: use flags instead of multiple variables
This commit is contained in:
@@ -16,7 +16,7 @@ inline static void terminate_proc(main_server_st *s, proc_st *proc)
|
|||||||
if (proc->pid != -1 && proc->pid != 0)
|
if (proc->pid != -1 && proc->pid != 0)
|
||||||
kill(proc->pid, SIGTERM);
|
kill(proc->pid, SIGTERM);
|
||||||
else
|
else
|
||||||
remove_proc(s, proc, 1, 0);
|
remove_proc(s, proc, RPROC_KILL);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -167,18 +167,18 @@ struct proc_st *ctmp;
|
|||||||
|
|
||||||
/* k: whether to kill the process
|
/* k: whether to kill the process
|
||||||
*/
|
*/
|
||||||
void remove_proc(main_server_st * s, struct proc_st *proc, unsigned k, unsigned quit)
|
void remove_proc(main_server_st * s, struct proc_st *proc, unsigned flags)
|
||||||
{
|
{
|
||||||
mslog(s, proc, LOG_INFO, "user disconnected");
|
mslog(s, proc, LOG_INFO, "user disconnected");
|
||||||
|
|
||||||
list_del(&proc->list);
|
list_del(&proc->list);
|
||||||
s->active_clients--;
|
s->active_clients--;
|
||||||
|
|
||||||
if (k && proc->pid != -1 && proc->pid != 0)
|
if ((flags&RPROC_KILL) && proc->pid != -1 && proc->pid != 0)
|
||||||
kill(proc->pid, SIGTERM);
|
kill(proc->pid, SIGTERM);
|
||||||
|
|
||||||
/* close any pending sessions */
|
/* close any pending sessions */
|
||||||
if (proc->active_sid && quit == 0) {
|
if (proc->active_sid && !(flags & RPROC_QUIT)) {
|
||||||
session_close(s, proc);
|
session_close(s, proc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -500,7 +500,7 @@ struct script_wait_st *stmp = NULL, *spos;
|
|||||||
list_del(&stmp->list);
|
list_del(&stmp->list);
|
||||||
ret = handle_script_exit(s, stmp->proc, estatus);
|
ret = handle_script_exit(s, stmp->proc, estatus);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
remove_proc(s, stmp->proc, 1, 0);
|
remove_proc(s, stmp->proc, RPROC_KILL);
|
||||||
} else {
|
} else {
|
||||||
talloc_free(stmp);
|
talloc_free(stmp);
|
||||||
}
|
}
|
||||||
@@ -660,7 +660,7 @@ static void kill_children(main_server_st* s)
|
|||||||
kill(s->sec_mod_pid, SIGTERM);
|
kill(s->sec_mod_pid, SIGTERM);
|
||||||
list_for_each_safe(&s->proc_list.head, ctmp, cpos, list) {
|
list_for_each_safe(&s->proc_list.head, ctmp, cpos, list) {
|
||||||
if (ctmp->pid != -1) {
|
if (ctmp->pid != -1) {
|
||||||
remove_proc(s, ctmp, 1, 1);
|
remove_proc(s, ctmp, RPROC_KILL|RPROC_QUIT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1267,7 +1267,7 @@ fork_failed:
|
|||||||
if (ctmp->fd >= 0 && FD_ISSET(ctmp->fd, &rd_set)) {
|
if (ctmp->fd >= 0 && FD_ISSET(ctmp->fd, &rd_set)) {
|
||||||
ret = handle_commands(s, ctmp);
|
ret = handle_commands(s, ctmp);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
remove_proc(s, ctmp, (ret!=ERR_WORKER_TERMINATED)?1:0, 0);
|
remove_proc(s, ctmp, (ret!=ERR_WORKER_TERMINATED)?RPROC_KILL:0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -269,7 +269,13 @@ int run_sec_mod(main_server_st * s, int *sync_fd);
|
|||||||
struct proc_st *new_proc(main_server_st * s, pid_t pid, int cmd_fd,
|
struct proc_st *new_proc(main_server_st * s, pid_t pid, int cmd_fd,
|
||||||
struct sockaddr_storage *remote_addr, socklen_t remote_addr_len,
|
struct sockaddr_storage *remote_addr, socklen_t remote_addr_len,
|
||||||
uint8_t *sid, size_t sid_size);
|
uint8_t *sid, size_t sid_size);
|
||||||
void remove_proc(main_server_st* s, struct proc_st *proc, unsigned k, unsigned quit);
|
|
||||||
|
/* kill the pid */
|
||||||
|
#define RPROC_KILL 1
|
||||||
|
/* we are on shutdown, don't wait for anything */
|
||||||
|
#define RPROC_QUIT (1<<1)
|
||||||
|
|
||||||
|
void remove_proc(main_server_st* s, struct proc_st *proc, unsigned flags);
|
||||||
void proc_to_zombie(main_server_st* s, struct proc_st *proc);
|
void proc_to_zombie(main_server_st* s, struct proc_st *proc);
|
||||||
|
|
||||||
void put_into_cgroup(main_server_st * s, const char* cgroup, pid_t pid);
|
void put_into_cgroup(main_server_st * s, const char* cgroup, pid_t pid);
|
||||||
|
|||||||
Reference in New Issue
Block a user