diff options
author | Charles Longeau <chl@cvs.openbsd.org> | 2012-08-24 13:13:14 +0000 |
---|---|---|
committer | Charles Longeau <chl@cvs.openbsd.org> | 2012-08-24 13:13:14 +0000 |
commit | 4aa47bf1d14daa7ee4fd7ee9247d141efb7d5f44 (patch) | |
tree | 75198df279c5dba6abad7ef7b57586781c5f86f4 /usr.sbin | |
parent | edde4e56780201577a2072e058954d2586c75d4b (diff) |
Don't pass struct envelope pointer in queue backend API, instead use envelope id and
an envelope ascii buffer.
ok eric@ gilles@
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/smtpd/queue_backend.c | 44 | ||||
-rw-r--r-- | usr.sbin/smtpd/queue_fsqueue.c | 68 | ||||
-rw-r--r-- | usr.sbin/smtpd/smtpd.h | 7 |
3 files changed, 70 insertions, 49 deletions
diff --git a/usr.sbin/smtpd/queue_backend.c b/usr.sbin/smtpd/queue_backend.c index a81ef220936..c0a0f68d982 100644 --- a/usr.sbin/smtpd/queue_backend.c +++ b/usr.sbin/smtpd/queue_backend.c @@ -1,4 +1,4 @@ -/* $OpenBSD: queue_backend.c,v 1.29 2012/08/19 14:16:58 chl Exp $ */ +/* $OpenBSD: queue_backend.c,v 1.30 2012/08/24 13:13:13 chl Exp $ */ /* * Copyright (c) 2011 Gilles Chehade <gilles@openbsd.org> @@ -125,13 +125,32 @@ queue_message_fd_rw(uint32_t msgid) return open(msgpath, O_RDWR | O_CREAT | O_EXCL, 0600); } +static int +queue_envelope_dump_buffer(struct envelope *ep, char *evpbuf, size_t evpbufsize) +{ + return (envelope_dump_buffer(ep, evpbuf, evpbufsize)); +} + +static int +queue_envelope_load_buffer(struct envelope *ep, char *evpbuf, size_t evpbufsize) +{ + return (envelope_load_buffer(ep, evpbuf, evpbufsize)); +} + + int queue_envelope_create(struct envelope *ep) { - int r; + int r; + char evpbuf[sizeof(struct envelope)]; + size_t evplen; ep->creation = time(NULL); - r = env->sc_queue->envelope(QOP_CREATE, ep); + evplen = queue_envelope_dump_buffer(ep, evpbuf, sizeof evpbuf); + if (evplen == 0) + return (0); + + r = env->sc_queue->envelope(QOP_CREATE, &ep->id, evpbuf, evplen); if (!r) { ep->creation = 0; ep->id = 0; @@ -142,16 +161,22 @@ queue_envelope_create(struct envelope *ep) int queue_envelope_delete(struct envelope *ep) { - return env->sc_queue->envelope(QOP_DELETE, ep); + return env->sc_queue->envelope(QOP_DELETE, &ep->id, NULL, 0); } int queue_envelope_load(uint64_t evpid, struct envelope *ep) { const char *e; + char evpbuf[sizeof(struct envelope)]; + size_t evplen; ep->id = evpid; - if (env->sc_queue->envelope(QOP_LOAD, ep)) { + evplen = env->sc_queue->envelope(QOP_LOAD, &ep->id, evpbuf, sizeof evpbuf); + if (evplen == 0) + return (0); + + if (queue_envelope_load_buffer(ep, evpbuf, evplen)) { if ((e = envelope_validate(ep, evpid)) == NULL) { ep->id = evpid; return (1); @@ -164,7 +189,14 @@ queue_envelope_load(uint64_t evpid, struct envelope *ep) int queue_envelope_update(struct envelope *ep) { - return env->sc_queue->envelope(QOP_UPDATE, ep); + char evpbuf[sizeof(struct envelope)]; + size_t evplen; + + evplen = queue_envelope_dump_buffer(ep, evpbuf, sizeof evpbuf); + if (evplen == 0) + return (0); + + return env->sc_queue->envelope(QOP_UPDATE, &ep->id, evpbuf, evplen); } void * diff --git a/usr.sbin/smtpd/queue_fsqueue.c b/usr.sbin/smtpd/queue_fsqueue.c index 23093dfebc9..1b5503b0da0 100644 --- a/usr.sbin/smtpd/queue_fsqueue.c +++ b/usr.sbin/smtpd/queue_fsqueue.c @@ -1,4 +1,4 @@ -/* $OpenBSD: queue_fsqueue.c,v 1.50 2012/08/24 10:07:28 eric Exp $ */ +/* $OpenBSD: queue_fsqueue.c,v 1.51 2012/08/24 13:13:13 chl Exp $ */ /* * Copyright (c) 2011 Gilles Chehade <gilles@openbsd.org> @@ -42,9 +42,10 @@ #include "smtpd.h" #include "log.h" -static int fsqueue_envelope_load(struct envelope *); -static int fsqueue_envelope_update(struct envelope *); -static int fsqueue_envelope_delete(struct envelope *); +static int fsqueue_envelope_create(uint64_t *, char *, size_t); +static int fsqueue_envelope_load(uint64_t, char *, size_t); +static int fsqueue_envelope_update(uint64_t, char *, size_t); +static int fsqueue_envelope_delete(uint64_t); static int fsqueue_message_create(uint32_t *); static int fsqueue_message_commit(uint32_t); @@ -54,11 +55,11 @@ static int fsqueue_message_corrupt(uint32_t); static int fsqueue_message_path(uint32_t, char *, size_t); static int fsqueue_envelope_path(uint64_t, char *, size_t); -static int fsqueue_envelope_dump_atomic(char *, struct envelope *); +static int fsqueue_envelope_dump_atomic(char *, char *, size_t); static int fsqueue_init(int); static int fsqueue_message(enum queue_op, uint32_t *); -static int fsqueue_envelope(enum queue_op , struct envelope *); +static int fsqueue_envelope(enum queue_op , uint64_t *, char *, size_t); static void *fsqueue_qwalk_new(uint32_t); static int fsqueue_qwalk(void *, uint64_t *); @@ -106,18 +107,12 @@ fsqueue_envelope_path(uint64_t evpid, char *buf, size_t len) } static int -fsqueue_envelope_dump_atomic(char *dest, struct envelope *ep) +fsqueue_envelope_dump_atomic(char *dest, char *evpbuf, size_t evplen) { int fd; char evpname[MAXPATHLEN]; - char evpbuf[sizeof(struct envelope)]; - size_t evplen; ssize_t w; - evplen = envelope_dump_buffer(ep, evpbuf, sizeof evpbuf); - if (evplen == 0) - return (0); - /* temporary fix for multi-process access to the queue, * should be fixed by rerouting ALL queue access through * the queue process. @@ -165,45 +160,42 @@ tempfail: } static int -fsqueue_envelope_create(struct envelope *ep) +fsqueue_envelope_create(uint64_t *evpid, char *buf, size_t len) { char path[MAXPATHLEN]; - uint64_t evpid; uint32_t msgid; int queued = 0, i; struct stat sb; - msgid = evpid_to_msgid(ep->id); + msgid = evpid_to_msgid(*evpid); queue_message_incoming_path(msgid, path, sizeof(path)); if (stat(path, &sb) == -1) queued = 1; for (i = 0; i < 20; i ++) { - evpid = queue_generate_evpid(msgid); + *evpid = queue_generate_evpid(msgid); if (queued) - fsqueue_envelope_path(evpid, path, sizeof(path)); + fsqueue_envelope_path(*evpid, path, sizeof(path)); else - queue_envelope_incoming_path(evpid, path, sizeof(path)); + queue_envelope_incoming_path(*evpid, path, sizeof(path)); if (stat(path, &sb) == -1 && errno == ENOENT) goto found; } fatal("couldn't figure out a new envelope id"); - found: - ep->id = evpid; - return (fsqueue_envelope_dump_atomic(path, ep)); +found: + return (fsqueue_envelope_dump_atomic(path, buf, len)); } static int -fsqueue_envelope_load(struct envelope *ep) +fsqueue_envelope_load(uint64_t evpid, char *buf, size_t len) { char pathname[MAXPATHLEN]; - char evpbuf[sizeof(struct envelope)]; int fd; ssize_t r; - fsqueue_envelope_path(ep->id, pathname, sizeof(pathname)); + fsqueue_envelope_path(evpid, pathname, sizeof(pathname)); fd = open(pathname, O_RDONLY); if (fd == -1) { @@ -212,30 +204,30 @@ fsqueue_envelope_load(struct envelope *ep) fatal("fsqueue_envelope_load: open"); } - if ((r = read(fd, evpbuf, sizeof evpbuf)) == -1) + if ((r = read(fd, buf, len)) == -1) return (0); close(fd); - return (envelope_load_buffer(ep, evpbuf, r)); + return (r); } static int -fsqueue_envelope_update(struct envelope *ep) +fsqueue_envelope_update(uint64_t evpid, char *buf, size_t len) { char dest[MAXPATHLEN]; - fsqueue_envelope_path(ep->id, dest, sizeof(dest)); + fsqueue_envelope_path(evpid, dest, sizeof(dest)); - return (fsqueue_envelope_dump_atomic(dest, ep)); + return (fsqueue_envelope_dump_atomic(dest, buf, len)); } static int -fsqueue_envelope_delete(struct envelope *ep) +fsqueue_envelope_delete(uint64_t evpid) { char pathname[MAXPATHLEN]; - fsqueue_envelope_path(ep->id, pathname, sizeof(pathname)); + fsqueue_envelope_path(evpid, pathname, sizeof(pathname)); if (unlink(pathname) == -1) fatal("fsqueue_envelope_delete: unlink"); @@ -243,7 +235,7 @@ fsqueue_envelope_delete(struct envelope *ep) *strrchr(pathname, '/') = '\0'; if (rmdir(pathname) != -1) - fsqueue_message_delete(evpid_to_msgid(ep->id)); + fsqueue_message_delete(evpid_to_msgid(evpid)); return 1; } @@ -424,20 +416,20 @@ fsqueue_message(enum queue_op qop, uint32_t *msgid) } static int -fsqueue_envelope(enum queue_op qop, struct envelope *m) +fsqueue_envelope(enum queue_op qop, uint64_t *evpid, char *buf, size_t len) { switch (qop) { case QOP_CREATE: - return fsqueue_envelope_create(m); + return fsqueue_envelope_create(evpid, buf, len); case QOP_DELETE: - return fsqueue_envelope_delete(m); + return fsqueue_envelope_delete(*evpid); case QOP_LOAD: - return fsqueue_envelope_load(m); + return fsqueue_envelope_load(*evpid, buf, len); case QOP_UPDATE: - return fsqueue_envelope_update(m); + return fsqueue_envelope_update(*evpid, buf, len); default: fatalx("queue_fsqueue_envelope: unsupported operation."); diff --git a/usr.sbin/smtpd/smtpd.h b/usr.sbin/smtpd/smtpd.h index b7318f96a1d..ea4e844936d 100644 --- a/usr.sbin/smtpd/smtpd.h +++ b/usr.sbin/smtpd/smtpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: smtpd.h,v 1.330 2012/08/24 12:29:50 eric Exp $ */ +/* $OpenBSD: smtpd.h,v 1.331 2012/08/24 13:13:13 chl Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -801,7 +801,7 @@ enum queue_op { struct queue_backend { int (*init)(int); int (*message)(enum queue_op, uint32_t *); - int (*envelope)(enum queue_op, struct envelope *); + int (*envelope)(enum queue_op, uint64_t *, char *, size_t); void *(*qwalk_new)(uint32_t); int (*qwalk)(void *, uint64_t *); @@ -1033,11 +1033,9 @@ void mta_session_imsg(struct imsgev *, struct imsg *); int parse_config(struct smtpd *, const char *, int); int cmdline_symset(char *); - /* queue.c */ pid_t queue(void); - /* queue_backend.c */ uint32_t queue_generate_msgid(void); uint64_t queue_generate_evpid(uint32_t msgid); @@ -1059,7 +1057,6 @@ void *qwalk_new(uint32_t); int qwalk(void *, uint64_t *); void qwalk_close(void *); - /* scheduler.c */ pid_t scheduler(void); |