Revision: 14754
Author: adrian.chadd
Date: Tue Aug 10 06:09:05 2010
Log: * include periodic rechecking; currently 5 seconds
* change the response to be OK/ERR

This is still not correct for live use.

http://code.google.com/p/lusca-cache/source/detail?r=14754

Modified:
 /branches/LUSCA_HEAD/helpers/external_acl/regex/regex.c

=======================================
--- /branches/LUSCA_HEAD/helpers/external_acl/regex/regex.c Mon Aug 9 23:24:11 2010 +++ /branches/LUSCA_HEAD/helpers/external_acl/regex/regex.c Tue Aug 10 06:09:05 2010
@@ -12,6 +12,7 @@
 #include <stdlib.h>
 #include <sys/types.h>
 #include <sys/time.h>
+#include <sys/stat.h>
 #include <strings.h>
 #include <string.h>
 #include <regex.h>
@@ -62,7 +63,6 @@
 {
        int i;
        for (i = 0; i < re_list.count; i++) {
-               fprintf(stderr, "[%d]: free\n", i);
                regfree(&re_list.r[i].re);
                bzero(&re_list.r[i], sizeof(regex_entry_t));
        }
@@ -153,9 +153,6 @@
                /* Trim trailing \r\n's */
                trim_trailing_crlf(buf);
                n = regex_parse_line(buf, linenum);
-               if (n > 0) {
-                       printf("[%d]: %s\n", linenum, buf);
-               }
        }

        fclose(fp);
@@ -191,6 +188,8 @@
        char buf[HELPERBUFSZ];
        time_t ts;
        int r;
+       struct stat sb;
+       time_t last_mtime = 0;

        if (argc < 2) {
                printf("%s: <config file>\n", argv[0]);
@@ -203,13 +202,26 @@
        (void) setvbuf(stderr, NULL, _IONBF, 0);

        /* initial load */
+       if (stat(fn, &sb) < 0) {
+               perror("stat");
+               exit(127);
+       }
+       last_mtime = sb.st_mtimespec.tv_sec;
+
        load_regex_file(fn);
        ts = time(NULL);

        while (!feof(stdin)) {
                if (time(NULL) - ts > RELOAD_TIME) {
+                       fprintf(stderr, "re-check\n");
                        ts = time(NULL);
-                       check_file_update(fn, NULL);
+                       /* re-stat the file */
+                       if (stat(fn, &sb) < 0) {
+                               perror("stat");
+                       } else if (sb.st_mtimespec.tv_sec > last_mtime) {
+                               last_mtime = sb.st_mtimespec.tv_sec;
+                               check_file_update(fn, NULL);
+                       }
                }

                if (! fgets(buf, HELPERBUFSZ, stdin))
@@ -221,9 +233,9 @@
                if (r > 0) {
                        fprintf(stderr, "HIT: line %d; rule %s\n",
                            re_list.r[r].linenum, re_list.r[r].entry);
-                       printf("YES\n");
+                       printf("OK\n");
                } else {
-                       printf("NO\n");
+                       printf("ERR\n");
                }
        }
        re_list_free();

--
You received this message because you are subscribed to the Google Groups 
"lusca-commit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/lusca-commit?hl=en.

Reply via email to