int run_digests(struct mlmmj_list *list, const char *mlmmjsend)
{
char *lasttimestr, *lastindexstr, *lastissuestr;
- char *digestname, *indexname;
char *digestintervalstr, *digestmaxmailsstr;
char *s1, *s2;
time_t digestinterval, t, lasttime;
long digestmaxmails, lastindex, index, lastissue;
- int fd, indexfd, lock;
+ int fd, indexfd;
if (statctrl(list, "noarchive")) {
return 0;
digestmaxmails = DIGESTMAXMAILS;
}
- digestname = concatstr(2, list->dir, "/lastdigest");
- fd = open(digestname, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
+ fd = openat(list->fd, "latestdigest", O_RDWR | O_CREAT | O_EXLOCK, S_IRUSR | S_IWUSR);
if (fd < 0) {
- log_error(LOG_ARGS, "Could not open '%s'", digestname);
- myfree(digestname);
+ log_error(LOG_ARGS, "Could not open '%s/latestdigest'", list->dir);
return 1;
}
-
- lock = myexcllock(fd);
- if(lock) {
- log_error(LOG_ARGS, "Error locking lastdigest");
- myfree(digestname);
- close(fd);
- return 1;
- }
-
s1 = mygetline(fd);
/* Syntax is lastindex:lasttime or lastindex:lasttime:lastissue */
lastindex = atol(lastindexstr);
} else {
if (s1 && (strlen(s1) > 0)) {
- log_error(LOG_ARGS, "'%s' contains malformed data",
- digestname);
- myfree(digestname);
+ log_error(LOG_ARGS, "'%s/latestdigest' contains malformed data",
+ list->dir);
myfree(s1);
close(fd);
return 1;
lastindex = 0;
lastissue = 0;
}
-
- indexname = concatstr(2, list->dir, "/index");
- indexfd = open(indexname, O_RDONLY);
+
+ indexfd = openat(list->fd, "index", O_RDONLY);
if (indexfd < 0) {
- log_error(LOG_ARGS, "Could not open '%s'", indexname);
- myfree(digestname);
- myfree(indexname);
+ log_error(LOG_ARGS, "Could not open '%s/index'", list->dir);
myfree(s1);
close(fd);
return 1;
if (!s2) {
/* If we don't have an index, no mails have been sent to the
* list, and therefore we don't need to send a digest */
- myfree(digestname);
- myfree(indexname);
myfree(s1);
close(fd);
return 1;
}
if (lseek(fd, 0, SEEK_SET) < 0) {
- log_error(LOG_ARGS, "Could not seek '%s'", digestname);
+ log_error(LOG_ARGS, "Could not seek '%s/latestdigest'", list->dir);
} else {
/* index + ':' + time + ':' + issue + '\n' + '\0' */
if (dprintf(fd, "%ld:%ld:%ld\n", index, (long)t, lastissue) == -1) {
- log_error(LOG_ARGS, "Could not write new '%s'",
- digestname);
+ log_error(LOG_ARGS, "Could not write new '%s/latestdigest'",
+ list->dir);
}
}
}
- myfree(digestname);
- myfree(indexname);
myfree(s1);
myfree(s2);
close(fd);