From c97c26558670b2bcd835ea868a33538df4be1cfe Mon Sep 17 00:00:00 2001 From: Anis Ellouze Date: Thu, 5 Feb 2015 17:40:22 +0100 Subject: [PATCH] Related to #6030 (3): Avoid the inherit of file descriptor of /var/run/cwmp.pid to the fork() child Signed-off-by: Anis Ellouze --- config.c | 1 + ubus.c | 1 + 2 files changed, 2 insertions(+) diff --git a/config.c b/config.c index 19b570e..8886366 100644 --- a/config.c +++ b/config.c @@ -729,6 +729,7 @@ int cwmp_init(int argc, char** argv,struct cwmp *cwmp) } /* Only One instance should run*/ cwmp->pid_file = open("/var/run/cwmpd.pid", O_CREAT | O_RDWR, 0666); + fcntl(cwmp->pid_file, F_SETFD, fcntl(cwmp->pid_file, F_GETFD) | FD_CLOEXEC); int rc = flock(cwmp->pid_file, LOCK_EX | LOCK_NB); if(rc) { if(EWOULDBLOCK != errno) diff --git a/ubus.c b/ubus.c index c5170a4..c201736 100644 --- a/ubus.c +++ b/ubus.c @@ -128,6 +128,7 @@ cwmp_handle_command(struct ubus_context *ctx, struct ubus_object *obj, int error; CWMP_LOG(INFO, "triggered ubus exit"); int rc = flock(cwmp_main.pid_file, LOCK_UN | LOCK_NB); + close(cwmp_main.pid_file); if(rc) { char *piderr = "PID file unlock failed!"; fprintf(stderr, "%s\n", piderr);