summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Ruppert <idl0r@gentoo.org>2010-04-26 22:54:12 +0200
committerChristian Ruppert <idl0r@gentoo.org>2010-04-26 22:54:12 +0200
commit957b6a7efb9498c0af0ea7535628610fda66ef24 (patch)
treee396b553aab927b2fad1682f7bc5967df628282f
parentClean up (diff)
downloadfifo-cronolog-957b6a7efb9498c0af0ea7535628610fda66ef24.tar.gz
fifo-cronolog-957b6a7efb9498c0af0ea7535628610fda66ef24.tar.bz2
fifo-cronolog-957b6a7efb9498c0af0ea7535628610fda66ef24.zip
Search cronolog in PATH
-rw-r--r--squid-cronolog.c35
1 files changed, 32 insertions, 3 deletions
diff --git a/squid-cronolog.c b/squid-cronolog.c
index 58bd6a9..c1cfc5d 100644
--- a/squid-cronolog.c
+++ b/squid-cronolog.c
@@ -5,13 +5,34 @@
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
+#include <sys/stat.h>
#include <errno.h>
#include <string.h>
-#define CRONOLOG "/usr/sbin/cronolog"
-
char *pidfile;
+char *get_cronolog(void) {
+ int len = 0;
+ char *path, *tmp;
+ struct stat st;
+
+ path = strtok(getenv("PATH"), ":");
+ while(path != NULL) {
+ len = (strlen(path) + strlen("/cronolog") + 1);
+ tmp = (char *)malloc(len);
+ snprintf(tmp, len, "%s%s", path, "/cronolog");
+
+ stat(tmp, &st);
+ if(st.st_mode & S_IFREG)
+ return tmp;
+ else
+ free(tmp);
+
+ path = strtok(NULL, ":");
+ }
+ return NULL;
+}
+
void die(int sig) {
/* kill off children */
kill(0, SIGTERM);
@@ -38,6 +59,12 @@ int main(int argc, char *argv[]) {
fifo = argv[2];
log = argv[3];
+ cronolog = get_cronolog();
+ if(cronolog == NULL) {
+ fprintf(stderr, "cronolog not found in PATH\n");
+ exit(1);
+ }
+
/* Test for fifo access, leave open for use */
/* O_NONBLOCK allows us to fork into the background */
fd = open(fifo, O_RDONLY|O_NONBLOCK);
@@ -84,7 +111,7 @@ int main(int argc, char *argv[]) {
/* unset O_NONBLOCK */
fcntl(0, F_SETFL, 0);
/* exec cronolog */
- execl(CRONOLOG, CRONOLOG, log, (char *) 0);
+ execl(cronolog, cronolog, log, (char *) 0);
/* filure! give up on life */
exit(1);
} else {
@@ -102,6 +129,8 @@ int main(int argc, char *argv[]) {
/* PARENT 0 exits */
close(fd);
+ free(cronolog);
+
return 0;
}