]> git.ipfire.org Git - people/ms/dma.git/blobdiff - spool.c
implement queue flushing prod
[people/ms/dma.git] / spool.c
diff --git a/spool.c b/spool.c
index 7c7c08d5c53503ac56c8e43aa4f1741b0f9854b6..873352d4be2fc7742bb27f9f60be5a406174651c 100644 (file)
--- a/spool.c
+++ b/spool.c
@@ -395,3 +395,52 @@ dropspool(struct queue *queue, struct qitem *keep)
                        fclose(it->mailf);
        }
 }
+
+int
+flushqueue_since(unsigned int period)
+{
+        struct stat st;
+       struct timeval now;
+        char *flushfn = NULL;
+
+       if (asprintf(&flushfn, "%s/%s", config.spooldir, SPOOL_FLUSHFILE) < 0)
+               return (0);
+       if (stat(flushfn, &st) < 0) {
+               free(flushfn);
+               return (0);
+       }
+       free(flushfn);
+       flushfn = NULL;
+       if (gettimeofday(&now, 0) != 0)
+               return (0);
+
+       /* Did the flush file get touched within the last period seconds? */
+       if (st.st_mtim.tv_sec + period >= now.tv_sec)
+               return (1);
+       else
+               return (0);
+}
+
+int
+flushqueue_signal(void)
+{
+        char *flushfn = NULL;
+       int fd;
+
+        if (asprintf(&flushfn, "%s/%s", config.spooldir, SPOOL_FLUSHFILE) < 0)
+               return (-1);
+       fd = open(flushfn, O_CREAT|O_RDONLY, 0440);
+       if (fd < 0) {
+               syslog(LOG_ERR, "could not open flush file: %m");
+               free(flushfn);
+               return (-1);
+       }
+        close(fd);
+        if (utimes(flushfn, NULL) < 0) {
+               syslog(LOG_ERR, "could not touch flush file: %m");
+               free(flushfn);
+               return (-1);
+       }
+       free (flushfn);
+       return (0);
+}