summaryrefslogtreecommitdiff
path: root/usr.sbin/smtpd/runner.c
diff options
context:
space:
mode:
authorGilles Chehade <gilles@cvs.openbsd.org>2010-01-10 16:42:36 +0000
committerGilles Chehade <gilles@cvs.openbsd.org>2010-01-10 16:42:36 +0000
commit6da0bc7f38345d7dd3b9755ca396488764f8a274 (patch)
tree224f5d8e066b53562cac30eb68f414a99b1d2ee8 /usr.sbin/smtpd/runner.c
parentb39b103c9261484e58be3bd3bc32f86fca82d39d (diff)
- teach runner how to remove a message from queue given a message id/uid
and assuming message is not in processing/scheduled state - teach smtpctl how to request message removal from runner discussed with todd@, idea ok jacekm@
Diffstat (limited to 'usr.sbin/smtpd/runner.c')
-rw-r--r--usr.sbin/smtpd/runner.c61
1 files changed, 60 insertions, 1 deletions
diff --git a/usr.sbin/smtpd/runner.c b/usr.sbin/smtpd/runner.c
index 4f541e5978e..a2f9b1ac808 100644
--- a/usr.sbin/smtpd/runner.c
+++ b/usr.sbin/smtpd/runner.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: runner.c,v 1.77 2010/01/03 14:37:37 chl Exp $ */
+/* $OpenBSD: runner.c,v 1.78 2010/01/10 16:42:35 gilles Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -83,6 +83,9 @@ struct batch *batch_lookup(struct smtpd *, struct message *);
int runner_force_envelope_schedule(char *);
int runner_force_message_schedule(char *);
+int runner_force_envelope_remove(char *);
+int runner_force_message_remove(char *);
+
void
runner_sig_handler(int sig, short event, void *p)
{
@@ -214,6 +217,20 @@ runner_dispatch_control(int sig, short event, void *p)
imsg_compose_event(iev, IMSG_RUNNER_SCHEDULE, 0, 0, -1, s, sizeof(*s));
break;
}
+ case IMSG_RUNNER_REMOVE: {
+ struct remove *s = imsg.data;
+
+ IMSG_SIZE_CHECK(s);
+
+ s->ret = 0;
+ if (valid_message_uid(s->mid))
+ s->ret = runner_force_envelope_remove(s->mid);
+ else if (valid_message_id(s->mid))
+ s->ret = runner_force_message_remove(s->mid);
+
+ imsg_compose_event(iev, IMSG_RUNNER_REMOVE, 0, 0, -1, s, sizeof(*s));
+ break;
+ }
default:
log_warnx("runner_dispatch_control: got imsg %d",
imsg.hdr.type);
@@ -930,6 +947,48 @@ runner_force_message_schedule(char *mid)
return 1;
}
+
+int
+runner_force_envelope_remove(char *mid)
+{
+ struct message message;
+
+ if (! queue_load_envelope(&message, mid))
+ return 0;
+
+ if (! message.flags & (F_MESSAGE_PROCESSING|F_MESSAGE_SCHEDULED))
+ return 0;
+
+ if (! queue_remove_envelope(&message))
+ return 0;
+
+ return 1;
+}
+
+int
+runner_force_message_remove(char *mid)
+{
+ char path[MAXPATHLEN];
+ DIR *dirp;
+ struct dirent *dp;
+
+ if (! bsnprintf(path, MAXPATHLEN, "%s/%d/%s/envelopes",
+ PATH_QUEUE, queue_hash(mid), mid))
+ return 0;
+
+ dirp = opendir(path);
+ if (dirp == NULL)
+ return 0;
+
+ while ((dp = readdir(dirp)) != NULL) {
+ if (valid_message_uid(dp->d_name))
+ runner_force_envelope_remove(dp->d_name);
+ }
+ closedir(dirp);
+
+ return 1;
+}
+
void
runner_purge_run(void)
{