summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorEric Faurot <eric@cvs.openbsd.org>2011-12-14 18:42:28 +0000
committerEric Faurot <eric@cvs.openbsd.org>2011-12-14 18:42:28 +0000
commitb00cec847eeeb27d4c754e38b649c07d9972d3d7 (patch)
tree3a5a4eeb7e6f1cdbe7ebf3410ca6bbac69219914 /usr.sbin
parent871e20bfd34576992dd909d6156f03c266fa6cc2 (diff)
move show_queue() and related functions from queue_shared.c
to smtpctl.c ok gilles@
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/smtpd/queue_shared.c101
-rw-r--r--usr.sbin/smtpd/smtpctl.c100
-rw-r--r--usr.sbin/smtpd/smtpctl/Makefile4
-rw-r--r--usr.sbin/smtpd/smtpd.h3
4 files changed, 103 insertions, 105 deletions
diff --git a/usr.sbin/smtpd/queue_shared.c b/usr.sbin/smtpd/queue_shared.c
index 515a6f521e5..41c5883644b 100644
--- a/usr.sbin/smtpd/queue_shared.c
+++ b/usr.sbin/smtpd/queue_shared.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: queue_shared.c,v 1.54 2011/11/15 23:06:39 gilles Exp $ */
+/* $OpenBSD: queue_shared.c,v 1.55 2011/12/14 18:42:27 eric Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -40,11 +40,6 @@
#include "smtpd.h"
#include "log.h"
-int fsqueue_load_envelope_ascii(FILE *, struct envelope *);
-
-void display_envelope(struct envelope *, int);
-void getflag(u_int *, int, char *, char *, size_t);
-
int
bounce_record_message(struct envelope *e, struct envelope *bounce)
{
@@ -100,97 +95,3 @@ queue_message_update(struct envelope *e)
/* no error, remove envelope */
queue_envelope_delete(Q_QUEUE, e);
}
-
-void
-show_queue(enum queue_kind kind, int flags)
-{
- struct qwalk *q;
- struct envelope envelope;
- u_int64_t evpid;
-
- log_init(1);
-
- if (chroot(PATH_SPOOL) == -1 || chdir(".") == -1)
- err(1, "%s", PATH_SPOOL);
-
- q = qwalk_new(kind, 0);
-
- while (qwalk(q, &evpid)) {
- if (! queue_envelope_load(kind, evpid, &envelope))
- continue;
- display_envelope(&envelope, flags);
- }
-
- qwalk_close(q);
-}
-
-void
-display_envelope(struct envelope *e, int flags)
-{
- char status[128];
-
- status[0] = '\0';
-
- getflag(&e->status, DS_TEMPFAILURE, "TEMPFAIL",
- status, sizeof(status));
-
- if (e->status)
- errx(1, "%016" PRIx64 ": unexpected status 0x%04x", e->id,
- e->status);
-
- getflag(&e->flags, DF_BOUNCE, "BOUNCE",
- status, sizeof(status));
- getflag(&e->flags, DF_AUTHENTICATED, "AUTH",
- status, sizeof(status));
- getflag(&e->flags, DF_ENQUEUED, "ENQUEUED",
- status, sizeof(status));
- getflag(&e->flags, DF_INTERNAL, "INTERNAL",
- status, sizeof(status));
-
- if (e->flags)
- errx(1, "%016" PRIx64 ": unexpected flags 0x%04x", e->id,
- e->flags);
-
- if (status[0])
- status[strlen(status) - 1] = '\0';
- else
- strlcpy(status, "-", sizeof(status));
-
- switch (e->type) {
- case D_MDA:
- printf("MDA");
- break;
- case D_MTA:
- printf("MTA");
- break;
- case D_BOUNCE:
- printf("BOUNCE");
- break;
- default:
- printf("UNKNOWN");
- }
-
- printf("|%016" PRIx64 "|%s|%s@%s|%s@%s|%" PRId64 "|%" PRId64 "|%u",
- e->id,
- status,
- e->sender.user, e->sender.domain,
- e->dest.user, e->dest.domain,
- (int64_t) e->lasttry,
- (int64_t) e->expire,
- e->retry);
-
- if (e->errorline[0] != '\0')
- printf("|%s", e->errorline);
-
- printf("\n");
-}
-
-void
-getflag(u_int *bitmap, int bit, char *bitstr, char *buf, size_t len)
-{
- if (*bitmap & bit) {
- *bitmap &= ~bit;
- strlcat(buf, bitstr, len);
- strlcat(buf, ",", len);
- }
-}
diff --git a/usr.sbin/smtpd/smtpctl.c b/usr.sbin/smtpd/smtpctl.c
index 7d41c10a8e1..e8f0c77b1b0 100644
--- a/usr.sbin/smtpd/smtpctl.c
+++ b/usr.sbin/smtpd/smtpctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: smtpctl.c,v 1.72 2011/11/23 13:48:03 chl Exp $ */
+/* $OpenBSD: smtpctl.c,v 1.73 2011/12/14 18:42:27 eric Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@openbsd.org>
@@ -39,12 +39,16 @@
#include "smtpd.h"
#include "parser.h"
+#include "log.h"
void usage(void);
static void setup_env(struct smtpd *);
static void show_sizes(void);
static int show_command_output(struct imsg *);
static int show_stats_output(struct imsg *);
+static void show_queue(enum queue_kind, int);
+static void show_envelope(struct envelope *, int);
+static void getflag(u_int *, int, char *, char *, size_t);
int proctype;
struct imsgbuf *ibuf;
@@ -472,3 +476,97 @@ show_stats_output(struct imsg *imsg)
return (1);
}
+
+static void
+show_queue(enum queue_kind kind, int flags)
+{
+ struct qwalk *q;
+ struct envelope envelope;
+ u_int64_t evpid;
+
+ log_init(1);
+
+ if (chroot(PATH_SPOOL) == -1 || chdir(".") == -1)
+ err(1, "%s", PATH_SPOOL);
+
+ q = qwalk_new(kind, 0);
+
+ while (qwalk(q, &evpid)) {
+ if (! queue_envelope_load(kind, evpid, &envelope))
+ continue;
+ show_envelope(&envelope, flags);
+ }
+
+ qwalk_close(q);
+}
+
+static void
+show_envelope(struct envelope *e, int flags)
+{
+ char status[128];
+
+ status[0] = '\0';
+
+ getflag(&e->status, DS_TEMPFAILURE, "TEMPFAIL",
+ status, sizeof(status));
+
+ if (e->status)
+ errx(1, "%016" PRIx64 ": unexpected status 0x%04x", e->id,
+ e->status);
+
+ getflag(&e->flags, DF_BOUNCE, "BOUNCE",
+ status, sizeof(status));
+ getflag(&e->flags, DF_AUTHENTICATED, "AUTH",
+ status, sizeof(status));
+ getflag(&e->flags, DF_ENQUEUED, "ENQUEUED",
+ status, sizeof(status));
+ getflag(&e->flags, DF_INTERNAL, "INTERNAL",
+ status, sizeof(status));
+
+ if (e->flags)
+ errx(1, "%016" PRIx64 ": unexpected flags 0x%04x", e->id,
+ e->flags);
+
+ if (status[0])
+ status[strlen(status) - 1] = '\0';
+ else
+ strlcpy(status, "-", sizeof(status));
+
+ switch (e->type) {
+ case D_MDA:
+ printf("MDA");
+ break;
+ case D_MTA:
+ printf("MTA");
+ break;
+ case D_BOUNCE:
+ printf("BOUNCE");
+ break;
+ default:
+ printf("UNKNOWN");
+ }
+
+ printf("|%016" PRIx64 "|%s|%s@%s|%s@%s|%" PRId64 "|%" PRId64 "|%u",
+ e->id,
+ status,
+ e->sender.user, e->sender.domain,
+ e->dest.user, e->dest.domain,
+ (int64_t) e->lasttry,
+ (int64_t) e->expire,
+ e->retry);
+
+ if (e->errorline[0] != '\0')
+ printf("|%s", e->errorline);
+
+ printf("\n");
+}
+
+static void
+getflag(u_int *bitmap, int bit, char *bitstr, char *buf, size_t len)
+{
+ if (*bitmap & bit) {
+ *bitmap &= ~bit;
+ strlcat(buf, bitstr, len);
+ strlcat(buf, ",", len);
+ }
+}
diff --git a/usr.sbin/smtpd/smtpctl/Makefile b/usr.sbin/smtpd/smtpctl/Makefile
index 526ed5c54e3..6dbdd1e1c9c 100644
--- a/usr.sbin/smtpd/smtpctl/Makefile
+++ b/usr.sbin/smtpd/smtpctl/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.20 2011/11/02 12:01:20 eric Exp $
+# $OpenBSD: Makefile,v 1.21 2011/12/14 18:42:27 eric Exp $
.PATH: ${.CURDIR}/..
@@ -17,7 +17,7 @@ CFLAGS+= -Wshadow -Wpointer-arith -Wcast-qual
CFLAGS+= -Wsign-compare -Wbounded
SRCS= enqueue.c parser.c log.c
-SRCS+= queue_backend.c queue_fsqueue.c queue_fsqueue_ascii.c queue_shared.c
+SRCS+= queue_backend.c queue_fsqueue.c queue_fsqueue_ascii.c
SRCS+= smtpctl.c stats.c util.c
LDADD+= -lutil
diff --git a/usr.sbin/smtpd/smtpd.h b/usr.sbin/smtpd/smtpd.h
index 5021a49130d..fe02ebb5a05 100644
--- a/usr.sbin/smtpd/smtpd.h
+++ b/usr.sbin/smtpd/smtpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: smtpd.h,v 1.264 2011/12/14 17:55:55 eric Exp $ */
+/* $OpenBSD: smtpd.h,v 1.265 2011/12/14 18:42:27 eric Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -1099,7 +1099,6 @@ void qwalk_close(void *);
/* queue_shared.c */
void queue_message_update(struct envelope *);
int bounce_record_message(struct envelope *, struct envelope *);
-void show_queue(enum queue_kind, int);
/* ramqueue.c */