From 957b6a7efb9498c0af0ea7535628610fda66ef24 Mon Sep 17 00:00:00 2001 From: Christian Ruppert Date: Mon, 26 Apr 2010 22:54:12 +0200 Subject: Search cronolog in PATH --- squid-cronolog.c | 35 ++++++++++++++++++++++++++++++++--- 1 file 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 #include #include +#include #include #include -#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; } -- cgit v1.2.3-65-gdbad