Commit a08d6dcc authored by Kirk Webb's avatar Kirk Webb
Browse files

Fixed slothd off-by-one pid issue. Slothd now writes its pid _after_ forking into the background.

parent afd81380
...@@ -62,8 +62,6 @@ void usage(void) { ...@@ -62,8 +62,6 @@ void usage(void) {
int main(int argc, char **argv) { int main(int argc, char **argv) {
int exitcode = -1; int exitcode = -1;
int pfd;
char pidbuf[10];
static SLOTHD_OPTS mopts; static SLOTHD_OPTS mopts;
static SLOTHD_PACKET mpkt; static SLOTHD_PACKET mpkt;
...@@ -75,16 +73,6 @@ int main(int argc, char **argv) { ...@@ -75,16 +73,6 @@ int main(int argc, char **argv) {
opts = &mopts; opts = &mopts;
pkt = &mpkt; pkt = &mpkt;
/* Try to get lock. If can't, then bail out. */
if ((pfd = open(PIDFILE, O_EXCL | O_CREAT | O_RDWR)) < 0) {
lerror("Can't create lock file, quiting.");
exit(1);
}
fchmod(pfd, S_IRUSR | S_IRGRP | S_IROTH);
sprintf(pidbuf, "%d", getpid());
write(pfd, pidbuf, sizeof(pidbuf));
close(pfd);
if (parse_args(argc, argv) < 0) { if (parse_args(argc, argv) < 0) {
fprintf(stderr, "Error processing arguments.\n"); fprintf(stderr, "Error processing arguments.\n");
} }
...@@ -177,6 +165,8 @@ int parse_args(int argc, char **argv) { ...@@ -177,6 +165,8 @@ int parse_args(int argc, char **argv) {
int init_slothd(void) { int init_slothd(void) {
DIR *devs; DIR *devs;
int pfd;
char pidbuf[10];
char bufstr[MAXDEVLEN]; char bufstr[MAXDEVLEN];
struct dirent *dptr; struct dirent *dptr;
struct hostent *hent; struct hostent *hent;
...@@ -257,6 +247,16 @@ int init_slothd(void) { ...@@ -257,6 +247,16 @@ int init_slothd(void) {
return -1; return -1;
} }
/* Try to get lock. If can't, then bail out. */
if ((pfd = open(PIDFILE, O_EXCL | O_CREAT | O_RDWR)) < 0) {
lerror("Can't create lock file, quiting.");
exit(1);
}
fchmod(pfd, S_IRUSR | S_IRGRP | S_IROTH);
sprintf(pidbuf, "%d", getpid());
write(pfd, pidbuf, strlen(pidbuf));
close(pfd);
return 0; return 0;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment