X-Git-Url: http://www.dolda2000.com/gitweb/?a=blobdiff_plain;f=src%2Faccesslog.c;h=35a1e32a6e3d173b498b13a7455d558cca9dd6b1;hb=472abd3cd62e50a4e9d2bfc5368547e6325ed31b;hp=4c06e69fef026f7f913c4246d874a7f83e6c266c;hpb=8ad7573acd834e02bffbd7adc3814d4ca5645677;p=ashd.git diff --git a/src/accesslog.c b/src/accesslog.c index 4c06e69..35a1e32 100644 --- a/src/accesslog.c +++ b/src/accesslog.c @@ -25,6 +25,7 @@ #include #include #include +#include #ifdef HAVE_CONFIG_H #include @@ -194,7 +195,7 @@ static void reopenlog(void) static void usage(FILE *out) { - fprintf(out, "usage: accesslog [-hFa] [-f FORMAT] OUTFILE CHILD [ARGS...]\n"); + fprintf(out, "usage: accesslog [-hFa] [-f FORMAT] [-p PIDFILE] OUTFILE CHILD [ARGS...]\n"); } int main(int argc, char **argv) @@ -203,8 +204,11 @@ int main(int argc, char **argv) struct hthead *req; int fd; struct pollfd pfd[2]; + char *pidfile; + FILE *pidout; - while((c = getopt(argc, argv, "+hFaf:")) >= 0) { + pidfile = NULL; + while((c = getopt(argc, argv, "+hFaf:p:")) >= 0) { switch(c) { case 'h': usage(stdout); @@ -215,6 +219,9 @@ int main(int argc, char **argv) case 'f': format = optarg; break; + case 'p': + pidfile = optarg; + break; case 'a': format = "%A - - [%{%d/%b/%Y:%H:%M:%S %z}t] \"%m %u %v\" - - \"%R\" \"%G\""; break; @@ -242,10 +249,25 @@ int main(int argc, char **argv) } } if((ch = stdmkchild(argv + optind + 1, NULL, NULL)) < 0) { - flog(LOG_ERR, "accesslog: could fork child: %s", strerror(errno)); + flog(LOG_ERR, "accesslog: could not fork child: %s", strerror(errno)); exit(1); } signal(SIGHUP, sighandler); + if(pidfile) { + if(!strcmp(pidfile, "-")) { + if(!outname) { + flog(LOG_ERR, "accesslog: cannot derive PID file name without an output file"); + exit(1); + } + pidfile = sprintf2("%s.pid", outname); + } + if((pidout = fopen(pidfile, "w")) == NULL) { + flog(LOG_ERR, "accesslog: could not open PID file %s for writing: %s", pidfile); + exit(1); + } + fprintf(pidout, "%i\n", (int)getpid()); + fclose(pidout); + } while(1) { if(reopen) { reopenlog(); @@ -276,5 +298,7 @@ int main(int argc, char **argv) if(pfd[1].revents & POLLHUP) break; } + if(pidfile != NULL) + unlink(pidfile); return(0); }