diff options
author | Roy Marples <roy@marples.name> | 2009-04-18 19:54:04 +0000 |
---|---|---|
committer | Roy Marples <roy@marples.name> | 2009-04-18 19:54:04 +0000 |
commit | 3579663173be18becb5f4ddadf859e5984eab660 (patch) | |
tree | 92b3d9b1b63f3fb7a67578b7d50b73ad21eba183 /src/rc | |
parent | 802fe9709ec9e2e5887e87e1047c15d90020472f (diff) |
Don't leak the lock fd.
Diffstat (limited to 'src/rc')
-rw-r--r-- | src/rc/rc-misc.c | 6 | ||||
-rw-r--r-- | src/rc/runscript.c | 13 |
2 files changed, 14 insertions, 5 deletions
diff --git a/src/rc/rc-misc.c b/src/rc/rc-misc.c index 5ebd1ddc..f86f1773 100644 --- a/src/rc/rc-misc.c +++ b/src/rc/rc-misc.c @@ -351,11 +351,13 @@ exec_service(const char *service, const char *arg) _exit(EXIT_FAILURE); } - if (pid == -1) + if (pid == -1) { fprintf(stderr, "fork: %s\n",strerror (errno)); + svc_unlock(basename_c(service), fd); + } else + fcntl(fd, F_SETFD, fcntl(fd, F_GETFD, 0) | FD_CLOEXEC); sigprocmask(SIG_SETMASK, &old, NULL); - free(file); return pid; } diff --git a/src/rc/runscript.c b/src/rc/runscript.c index 20b14ae4..a727ba07 100644 --- a/src/rc/runscript.c +++ b/src/rc/runscript.c @@ -596,7 +596,7 @@ svc_start(bool deps) " next runlevel", applet); } - if (exclusive_fd == -1) + if (exclusive_fd == -1) exclusive_fd = svc_lock(applet); if (exclusive_fd == -1) { if (errno == EACCES) @@ -606,7 +606,9 @@ svc_start(bool deps) else ewarnx("WARNING: %s is already starting", applet); } - + fcntl(exclusive_fd, F_SETFD, + fcntl(exclusive_fd, F_GETFD, 0) | FD_CLOEXEC); + if (state & RC_SERVICE_STARTED) { ewarn("WARNING: %s has already been started", applet); return; @@ -824,8 +826,11 @@ svc_stop(bool deps) eerrorx("%s: superuser access required", applet); if (state & RC_SERVICE_STOPPING) ewarnx("WARNING: %s is already stopping", applet); - eerrorx("ERROR: %d %s has been stopped by something else", exclusive_fd, applet); + eerrorx("ERROR: %s has been stopped by something else", applet); } + fcntl(exclusive_fd, F_SETFD, + fcntl(exclusive_fd, F_GETFD, 0) | FD_CLOEXEC); + if (state & RC_SERVICE_STOPPED) { ewarn("WARNING: %s is already stopped", applet); return; @@ -1160,6 +1165,8 @@ runscript(int argc, char **argv) break; case 'l': exclusive_fd = atoi(optarg); + fcntl(exclusive_fd, F_SETFD, + fcntl(exclusive_fd, F_GETFD, 0) | FD_CLOEXEC); break; case 's': if (!(rc_service_state(service) & RC_SERVICE_STARTED)) |