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) {
int main(int argc, char **argv) {
int exitcode = -1;
int pfd;
char pidbuf[10];
static SLOTHD_OPTS mopts;
static SLOTHD_PACKET mpkt;
......@@ -75,16 +73,6 @@ int main(int argc, char **argv) {
opts = &mopts;
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) {
fprintf(stderr, "Error processing arguments.\n");
}
......@@ -177,6 +165,8 @@ int parse_args(int argc, char **argv) {
int init_slothd(void) {
DIR *devs;
int pfd;
char pidbuf[10];
char bufstr[MAXDEVLEN];
struct dirent *dptr;
struct hostent *hent;
......@@ -257,6 +247,16 @@ int init_slothd(void) {
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;
}
......
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