diff options
author | Jacek Masiulaniec <jacekm@cvs.openbsd.org> | 2008-12-17 18:47:38 +0000 |
---|---|---|
committer | Jacek Masiulaniec <jacekm@cvs.openbsd.org> | 2008-12-17 18:47:38 +0000 |
commit | bed623e2a09e48efefacc10ac99e11f03b5b538a (patch) | |
tree | e8e87dc5b7fc5dbe9abafd9f420102fed1ca5eb9 /usr.sbin | |
parent | 7e2e3174519967e54e6c5f28c163263924424176 (diff) |
Introduce /purge, where all msgs scheduled for deletion are put by
queue, and removed from disk by runner.
On startup, clean /incoming by moving msgs within it to /purge.
ok gilles@
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/smtpd/queue.c | 82 | ||||
-rw-r--r-- | usr.sbin/smtpd/runner.c | 80 | ||||
-rw-r--r-- | usr.sbin/smtpd/smtpd.c | 4 | ||||
-rw-r--r-- | usr.sbin/smtpd/smtpd.h | 4 |
4 files changed, 117 insertions, 53 deletions
diff --git a/usr.sbin/smtpd/queue.c b/usr.sbin/smtpd/queue.c index f993eb3c01a..0db5423a6ea 100644 --- a/usr.sbin/smtpd/queue.c +++ b/usr.sbin/smtpd/queue.c @@ -1,4 +1,4 @@ -/* $OpenBSD: queue.c,v 1.29 2008/12/14 19:27:47 jacekm Exp $ */ +/* $OpenBSD: queue.c,v 1.30 2008/12/17 18:47:37 jacekm Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -54,6 +54,7 @@ void queue_dispatch_runner(int, short, void *); void queue_setup_events(struct smtpd *); void queue_disable_events(struct smtpd *); void queue_timeout(int, short, void *); +void queue_purge_incoming(void); int queue_create_incoming_layout(char *); int queue_record_envelope(struct message *); int queue_remove_envelope(struct message *); @@ -676,6 +677,7 @@ queue(struct smtpd *env) config_peers(env, peers, 6); queue_setup_events(env); + queue_purge_incoming(); event_dispatch(); queue_shutdown(); @@ -748,6 +750,27 @@ message_by_id(struct smtpd *env, struct batch *batchp, u_int64_t id) return NULL; } +void +queue_purge_incoming(void) +{ + DIR *dirp; + struct dirent *dp; + + dirp = opendir(PATH_INCOMING); + if (dirp == NULL) + fatal("queue_purge_incoming: opendir"); + + while ((dp = readdir(dirp)) != NULL) { + if (strcmp(dp->d_name, ".") == 0 || + strcmp(dp->d_name, "..") == 0) { + continue; + } + queue_delete_incoming_message(dp->d_name); + } + + closedir(dirp); +} + int queue_create_incoming_layout(char *message_id) { @@ -782,61 +805,22 @@ badroot: } void -queue_delete_incoming_message(char *message_id) +queue_delete_incoming_message(char *msgid) { char rootdir[MAXPATHLEN]; - char evpdir[MAXPATHLEN]; - char evppath[MAXPATHLEN]; - char msgpath[MAXPATHLEN]; - DIR *dirp; - struct dirent *dp; - - if (! bsnprintf(rootdir, MAXPATHLEN, "%s/%s", PATH_INCOMING, - message_id)) - fatal("queue_delete_incoming_message: snprintf"); + char purgedir[MAXPATHLEN]; - if (! bsnprintf(evpdir, MAXPATHLEN, "%s%s", - rootdir, PATH_ENVELOPES)) - fatal("queue_delete_incoming_message: snprintf"); - - if (! bsnprintf(msgpath, MAXPATHLEN, "%s/message", rootdir)) - fatal("queue_delete_incoming_message: snprintf"); + if (! bsnprintf(rootdir, MAXPATHLEN, "%s/%s", PATH_INCOMING, msgid)) + fatalx("snprintf"); - if (unlink(msgpath) == -1) { - if (errno != ENOENT) - fatal("queue_delete_incoming_message: unlink"); - } + if (! bsnprintf(purgedir, MAXPATHLEN, "%s/%s", PATH_PURGE, msgid)) + fatalx("snprintf"); - dirp = opendir(evpdir); - if (dirp == NULL) { + if (rename(rootdir, purgedir) == -1) { if (errno == ENOENT) - goto delroot; - fatal("queue_delete_incoming_message: opendir"); - } - while ((dp = readdir(dirp)) != NULL) { - if (strcmp(dp->d_name, ".") == 0 || - strcmp(dp->d_name, "..") == 0) - continue; - if (! bsnprintf(evppath, MAXPATHLEN, "%s/%s", evpdir, dp->d_name)) - fatal("queue_delete_incoming_message: snprintf"); - - if (unlink(evppath) == -1) { - if (errno != ENOENT) - fatal("queue_delete_incoming_message: unlink"); - } + return; + fatal("queue_delete_incoming_message: rename"); } - closedir(dirp); - - if (rmdir(evpdir) == -1) - if (errno != ENOENT) - fatal("queue_delete_incoming_message: rmdir"); - -delroot: - if (rmdir(rootdir) == -1) - if (errno != ENOENT) - fatal("queue_delete_incoming_message: rmdir"); - - return; } int diff --git a/usr.sbin/smtpd/runner.c b/usr.sbin/smtpd/runner.c index 372f0ffcbdc..204ff58bafc 100644 --- a/usr.sbin/smtpd/runner.c +++ b/usr.sbin/smtpd/runner.c @@ -1,4 +1,4 @@ -/* $OpenBSD: runner.c,v 1.7 2008/12/13 23:19:34 jacekm Exp $ */ +/* $OpenBSD: runner.c,v 1.8 2008/12/17 18:47:37 jacekm Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -66,6 +66,9 @@ void runner_batch_dispatch(struct smtpd *, struct batch *, time_t); int runner_message_schedule(struct message *, time_t); +void runner_purge_run(void); +void runner_purge_message(char *); + struct batch *batch_record(struct smtpd *, struct message *); struct batch *batch_lookup(struct smtpd *, struct message *); @@ -423,6 +426,7 @@ runner_timeout(int fd, short event, void *p) struct smtpd *env = p; struct timeval tv; + runner_purge_run(); runner_process_queue(env); runner_process_runqueue(env); runner_process_batchqueue(env); @@ -784,6 +788,80 @@ runner_message_schedule(struct message *messagep, time_t tm) return 0; } +void +runner_purge_run(void) +{ + DIR *dirp; + struct dirent *dp; + + dirp = opendir(PATH_PURGE); + if (dirp == NULL) + fatal("runner_purge_run: opendir"); + + while ((dp = readdir(dirp)) != NULL) { + if (strcmp(dp->d_name, ".") == 0 || + strcmp(dp->d_name, "..") == 0) { + continue; + } + runner_purge_message(dp->d_name); + } + + closedir(dirp); +} + +void +runner_purge_message(char *msgid) +{ + char rootdir[MAXPATHLEN]; + char evpdir[MAXPATHLEN]; + char evppath[MAXPATHLEN]; + char msgpath[MAXPATHLEN]; + DIR *dirp; + struct dirent *dp; + + if (! bsnprintf(rootdir, MAXPATHLEN, "%s/%s", PATH_PURGE, msgid)) + fatal("queue_delete_incoming_message: snprintf"); + + if (! bsnprintf(evpdir, MAXPATHLEN, "%s%s", rootdir, PATH_ENVELOPES)) + fatal("queue_delete_incoming_message: snprintf"); + + if (! bsnprintf(msgpath, MAXPATHLEN, "%s/message", rootdir)) + fatal("queue_delete_incoming_message: snprintf"); + + if (unlink(msgpath) == -1) + if (errno != ENOENT) + fatal("queue_delete_incoming_message: unlink"); + + dirp = opendir(evpdir); + if (dirp == NULL) { + if (errno == ENOENT) + goto delroot; + fatal("queue_delete_incoming_message: opendir"); + } + while ((dp = readdir(dirp)) != NULL) { + if (strcmp(dp->d_name, ".") == 0 || + strcmp(dp->d_name, "..") == 0) + continue; + if (! bsnprintf(evppath, MAXPATHLEN, "%s/%s", evpdir, + dp->d_name)) + fatal("queue_delete_incoming_message: snprintf"); + + if (unlink(evppath) == -1) + if (errno != ENOENT) + fatal("queue_delete_incoming_message: unlink"); + } + closedir(dirp); + + if (rmdir(evpdir) == -1) + if (errno != ENOENT) + fatal("queue_delete_incoming_message: rmdir"); + +delroot: + if (rmdir(rootdir) == -1) + if (errno != ENOENT) + fatal("queue_delete_incoming_message: rmdir"); +} + struct batch * batch_record(struct smtpd *env, struct message *messagep) { diff --git a/usr.sbin/smtpd/smtpd.c b/usr.sbin/smtpd/smtpd.c index 60d97b76269..4d9643d57a6 100644 --- a/usr.sbin/smtpd/smtpd.c +++ b/usr.sbin/smtpd/smtpd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: smtpd.c,v 1.14 2008/12/11 23:10:28 gilles Exp $ */ +/* $OpenBSD: smtpd.c,v 1.15 2008/12/17 18:47:37 jacekm Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -627,7 +627,7 @@ int setup_spool(uid_t uid, gid_t gid) { unsigned int n; - char *paths[] = { PATH_INCOMING, PATH_QUEUE, + char *paths[] = { PATH_INCOMING, PATH_QUEUE, PATH_PURGE, PATH_RUNQUEUE, PATH_RUNQUEUELOW, PATH_RUNQUEUEHIGH }; char pathname[MAXPATHLEN]; diff --git a/usr.sbin/smtpd/smtpd.h b/usr.sbin/smtpd/smtpd.h index 67376c5ca23..106b894dde5 100644 --- a/usr.sbin/smtpd/smtpd.h +++ b/usr.sbin/smtpd/smtpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: smtpd.h,v 1.27 2008/12/13 23:19:34 jacekm Exp $ */ +/* $OpenBSD: smtpd.h,v 1.28 2008/12/17 18:47:37 jacekm Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -49,6 +49,8 @@ #define PATH_INCOMING "/incoming" #define PATH_QUEUE "/queue" +#define PATH_PURGE "/purge" + #define PATH_MESSAGE "/message" #define PATH_ENVELOPES "/envelopes" |