Fix descriptor leaks: when child exits, we have to close control and event
socket pairs. We did that only in one case out of three. MFC after: 3 days
This commit is contained in:
parent
6d7fe90938
commit
0c24d8e2a1
@ -39,6 +39,7 @@ __FBSDID("$FreeBSD$");
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "hast.h"
|
||||
#include "hastd.h"
|
||||
@ -51,6 +52,17 @@ __FBSDID("$FreeBSD$");
|
||||
|
||||
#include "control.h"
|
||||
|
||||
void
|
||||
child_cleanup(struct hast_resource *res)
|
||||
{
|
||||
|
||||
proto_close(res->hr_ctrl);
|
||||
res->hr_ctrl = NULL;
|
||||
proto_close(res->hr_event);
|
||||
res->hr_event = NULL;
|
||||
res->hr_workerpid = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
control_set_role_common(struct hastd_config *cfg, struct nv *nvout,
|
||||
uint8_t role, struct hast_resource *res, const char *name, unsigned int no)
|
||||
@ -109,7 +121,7 @@ control_set_role_common(struct hastd_config *cfg, struct nv *nvout,
|
||||
pjdlog_debug(1, "Worker process %u stopped.",
|
||||
(unsigned int)res->hr_workerpid);
|
||||
}
|
||||
res->hr_workerpid = 0;
|
||||
child_cleanup(res);
|
||||
}
|
||||
|
||||
/* Start worker process if we are changing to primary. */
|
||||
|
@ -38,6 +38,8 @@
|
||||
struct hastd_config;
|
||||
struct hast_resource;
|
||||
|
||||
void child_cleanup(struct hast_resource *res);
|
||||
|
||||
void control_set_role(struct hast_resource *res, uint8_t role);
|
||||
|
||||
void control_handle(struct hastd_config *cfg);
|
||||
|
@ -158,13 +158,7 @@ child_exit(void)
|
||||
pjdlog_prefix_set("[%s] (%s) ", res->hr_name,
|
||||
role2str(res->hr_role));
|
||||
child_exit_log(pid, status);
|
||||
proto_close(res->hr_ctrl);
|
||||
res->hr_ctrl = NULL;
|
||||
if (res->hr_event != NULL) {
|
||||
proto_close(res->hr_event);
|
||||
res->hr_event = NULL;
|
||||
}
|
||||
res->hr_workerpid = 0;
|
||||
child_cleanup(res);
|
||||
if (res->hr_role == HAST_ROLE_PRIMARY) {
|
||||
/*
|
||||
* Restart child process if it was killed by signal
|
||||
@ -553,7 +547,7 @@ listen_accept(void)
|
||||
} else {
|
||||
child_exit_log(res->hr_workerpid, status);
|
||||
}
|
||||
res->hr_workerpid = 0;
|
||||
child_cleanup(res);
|
||||
} else if (res->hr_remotein != NULL) {
|
||||
char oaddr[256];
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user