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