Don't leak the lock fd.

This commit is contained in:
Roy Marples 2009-04-18 19:54:04 +00:00
parent 802fe9709e
commit 3579663173
2 changed files with 14 additions and 5 deletions

View File

@ -351,11 +351,13 @@ exec_service(const char *service, const char *arg)
_exit(EXIT_FAILURE); _exit(EXIT_FAILURE);
} }
if (pid == -1) if (pid == -1) {
fprintf(stderr, "fork: %s\n",strerror (errno)); 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); sigprocmask(SIG_SETMASK, &old, NULL);
free(file); free(file);
return pid; return pid;
} }

View File

@ -606,6 +606,8 @@ svc_start(bool deps)
else else
ewarnx("WARNING: %s is already starting", applet); 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) { if (state & RC_SERVICE_STARTED) {
ewarn("WARNING: %s has already been started", applet); ewarn("WARNING: %s has already been started", applet);
@ -824,8 +826,11 @@ svc_stop(bool deps)
eerrorx("%s: superuser access required", applet); eerrorx("%s: superuser access required", applet);
if (state & RC_SERVICE_STOPPING) if (state & RC_SERVICE_STOPPING)
ewarnx("WARNING: %s is already stopping", applet); 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) { if (state & RC_SERVICE_STOPPED) {
ewarn("WARNING: %s is already stopped", applet); ewarn("WARNING: %s is already stopped", applet);
return; return;
@ -1160,6 +1165,8 @@ runscript(int argc, char **argv)
break; break;
case 'l': case 'l':
exclusive_fd = atoi(optarg); exclusive_fd = atoi(optarg);
fcntl(exclusive_fd, F_SETFD,
fcntl(exclusive_fd, F_GETFD, 0) | FD_CLOEXEC);
break; break;
case 's': case 's':
if (!(rc_service_state(service) & RC_SERVICE_STARTED)) if (!(rc_service_state(service) & RC_SERVICE_STARTED))