/*
+ * Copyright (c) 2008-2014, Simon Schubert <2@0x2c.org>.
* Copyright (c) 2008 The DragonFly Project. All rights reserved.
*
* This code is derived from software contributed to The DragonFly Project
- * by Simon 'corecode' Schubert <corecode@fs.ei.tum.de>.
+ * by Simon Schubert <2@0x2c.org>.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
char *queuefn;
char *mailfn;
- bzero(queue, sizeof(queue));
+ bzero(queue, sizeof(*queue));
LIST_INIT(&queue->queue);
spooldir = opendir(config.spooldir);
if (spooldir == NULL)
- err(1, "reading queue");
+ err(EX_NOINPUT, "reading queue");
while ((de = readdir(spooldir)) != NULL) {
queuefn = NULL;
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);
+}