X-Git-Url: https://gitweb.dragonflybsd.org/dragonfly.git/blobdiff_plain/097a4fd11fac7bc82d1b152e3259da24a019f7b8..14dfb9912037c6e7f0ddb9ef1cd77d5e14246639:/libexec/dma/spool.c diff --git a/libexec/dma/spool.c b/libexec/dma/spool.c index 25c6a99d2c..416b5fa8f0 100644 --- a/libexec/dma/spool.c +++ b/libexec/dma/spool.c @@ -284,7 +284,7 @@ load_queue(struct queue *queue) char *queuefn; char *mailfn; - bzero(queue, sizeof(queue)); + bzero(queue, sizeof(*queue)); LIST_INIT(&queue->queue); spooldir = opendir(config.spooldir); @@ -374,6 +374,8 @@ acquirespool(struct qitem *it) return (0); fail: + if (errno == EWOULDBLOCK) + return (1); syslog(LOG_INFO, "could not acquire queue file: %m"); return (-1); } @@ -393,3 +395,46 @@ 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_WRONLY|O_TRUNC, 0660); + free(flushfn); + if (fd < 0) { + syslog(LOG_ERR, "could not open flush file: %m"); + return (-1); + } + close(fd); + return (0); +}