summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
d58ed97)
...and make strace output look nicer. These things are important. :)
#include <ctype.h>
#include <dirent.h>
#include <fnmatch.h>
#include <ctype.h>
#include <dirent.h>
#include <fnmatch.h>
#ifdef HAVE_CONFIG_H
#include <config.h>
#ifdef HAVE_CONFIG_H
#include <config.h>
struct config {
struct config *next, *prev;
char *path;
struct config {
struct config *next, *prev;
char *path;
struct child *children;
struct pattern *patterns;
};
struct child *children;
struct pattern *patterns;
};
};
struct config *cflist;
};
struct config *cflist;
static void freepattern(struct pattern *pat)
{
static void freepattern(struct pattern *pat)
{
-static struct config *readconfig(char *path)
+static struct config *emptyconfig(void)
+{
+ struct config *cf;
+
+ omalloc(cf);
+ return(cf);
+}
+
+static struct config *readconfig(char *file)
{
struct cfstate *s;
FILE *in;
struct config *cf;
struct child *child;
struct pattern *pat;
{
struct cfstate *s;
FILE *in;
struct config *cf;
struct child *child;
struct pattern *pat;
- struct stat sb;
- char *p;
- p = sprintf3("%s/.htrc", path);
- if(stat(p, &sb))
- return(NULL);
- if((in = fopen(p, "r")) == NULL) {
- flog(LOG_WARNING, "%s: %s", p, strerror(errno));
+ if((in = fopen(file, "r")) == NULL) {
+ flog(LOG_WARNING, "%s: %s", file, strerror(errno));
- s = mkcfparser(in, p);
- omalloc(cf);
- cf->mtime = sb.st_mtime;
- cf->path = sstrdup(path);
+ s = mkcfparser(in, file);
+ cf = emptyconfig();
{
struct config *cf;
struct stat sb;
{
struct config *cf;
struct stat sb;
+ char *fn;
+ time_t mtime;
+ fn = sprintf3("%s/.htrc", path);
for(cf = cflist; cf != NULL; cf = cf->next) {
if(!strcmp(cf->path, path)) {
for(cf = cflist; cf != NULL; cf = cf->next) {
if(!strcmp(cf->path, path)) {
- if(stat(sprintf3("%s/.htrc", path), &sb))
- return(NULL);
- if(sb.st_mtime != cf->mtime) {
- freeconfig(cf);
- break;
+ if(now - cf->lastck > 5) {
+ if(stat(fn, &sb) || (sb.st_mtime != cf->mtime)) {
+ freeconfig(cf);
+ break;
+ }
- if((cf = readconfig(path)) != NULL) {
- cf->next = cflist;
- cflist = cf;
+ if(access(fn, R_OK) || stat(fn, &sb)) {
+ cf = emptyconfig();
+ mtime = 0;
+ } else {
+ if((cf = readconfig(fn)) == NULL)
+ return(NULL);
+ mtime = sb.st_mtime;
+ cf->path = sstrdup(path);
+ cf->mtime = mtime;
+ cf->lastck = now;
+ cf->next = cflist;
+ cflist = cf;
DIR *dir;
struct dirent *dent;
DIR *dir;
struct dirent *dent;
nm = req->rest;
path = sstrdup(".");
p = nm;
nm = req->rest;
path = sstrdup(".");
p = nm;