Related to #6030 (3): Avoid the inherit of file descriptor of /var/run/cwmp.pid to the fork() child

Signed-off-by: Anis Ellouze <anis.ellouze@pivasoftware.com>
This commit is contained in:
Anis Ellouze 2015-02-05 17:40:22 +01:00 committed by MOHAMED Kallel
parent 72f672e679
commit c97c265586
2 changed files with 2 additions and 0 deletions

View file

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

1
ubus.c
View file

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