diff options
author | Eric Faurot <eric@cvs.openbsd.org> | 2012-09-28 12:00:10 +0000 |
---|---|---|
committer | Eric Faurot <eric@cvs.openbsd.org> | 2012-09-28 12:00:10 +0000 |
commit | 2622e9922c6cfb031333d53d6301d67a922d884f (patch) | |
tree | 3c326032b37878a20026a20ff59fa69accfff0eb /usr.sbin | |
parent | 58465d3d205a572260271f42a3805f173d40a8b9 (diff) |
smtpd.h/control.c cleanups:
- move session_socket_* prototypes under util.c
- move struct ctl_conn in control.c
- make static functions static
- remove unused functions
- call unlink() in control_shutdown()
- make control_close() take a ctl_conn * instead of a fd
ok chl@ gilles@
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/smtpd/control.c | 72 | ||||
-rw-r--r-- | usr.sbin/smtpd/smtpd.h | 16 |
2 files changed, 36 insertions, 52 deletions
diff --git a/usr.sbin/smtpd/control.c b/usr.sbin/smtpd/control.c index d46c768a37b..de3392ba425 100644 --- a/usr.sbin/smtpd/control.c +++ b/usr.sbin/smtpd/control.c @@ -1,4 +1,4 @@ -/* $OpenBSD: control.c,v 1.74 2012/09/27 17:47:49 chl Exp $ */ +/* $OpenBSD: control.c,v 1.75 2012/09/28 12:00:09 eric Exp $ */ /* * Copyright (c) 2012 Gilles Chehade <gilles@openbsd.org> @@ -43,31 +43,35 @@ #define CONTROL_BACKLOG 5 -/* control specific headers */ +struct ctl_conn { + TAILQ_ENTRY(ctl_conn) entry; + uint8_t flags; +#define CTL_CONN_NOTIFY 0x01 + struct imsgev iev; +}; + struct { struct event ev; int fd; } control_state; -void control_imsg(struct imsgev *, struct imsg *); -__dead void control_shutdown(void); -int control_init(void); -void control_listen(void); -void control_cleanup(void); -void control_accept(int, short, void *); -struct ctl_conn *control_connbyfd(int); -void control_close(int); -void control_sig_handler(int, short, void *); -void control_dispatch_ext(int, short, void *); - -struct ctl_connlist ctl_conns; +static void control_imsg(struct imsgev *, struct imsg *); +static void control_shutdown(void); +static void control_listen(void); +static void control_accept(int, short, void *); +static struct ctl_conn *control_connbyfd(int); +static void control_close(struct ctl_conn *); +static void control_sig_handler(int, short, void *); +static void control_dispatch_ext(int, short, void *); static struct stat_backend *stat_backend = NULL; extern const char *backend_stat; +static TAILQ_HEAD(, ctl_conn) ctl_conns; + #define CONTROL_FD_RESERVE 5 -void +static void control_imsg(struct imsgev *iev, struct imsg *imsg) { struct ctl_conn *c; @@ -111,7 +115,7 @@ control_imsg(struct imsgev *iev, struct imsg *imsg) imsg_to_str(imsg->hdr.type)); } -void +static void control_sig_handler(int sig, short event, void *p) { switch (sig) { @@ -124,7 +128,6 @@ control_sig_handler(int sig, short event, void *p) } } - pid_t control(void) { @@ -229,14 +232,15 @@ control(void) return (0); } -void +static void control_shutdown(void) { log_info("control process exiting"); + unlink(SMTPD_SOCKET); _exit(0); } -void +static void control_listen(void) { if (listen(control_state.fd, CONTROL_BACKLOG) == -1) @@ -247,14 +251,8 @@ control_listen(void) event_add(&control_state.ev, NULL); } -void -control_cleanup(void) -{ - (void)unlink(SMTPD_SOCKET); -} - /* ARGSUSED */ -void +static void control_accept(int listenfd, short event, void *arg) { int connfd; @@ -293,7 +291,7 @@ pause: event_del(&control_state.ev); } -struct ctl_conn * +static struct ctl_conn * control_connbyfd(int fd) { struct ctl_conn *c; @@ -305,19 +303,13 @@ control_connbyfd(int fd) return (c); } -void -control_close(int fd) +static void +control_close(struct ctl_conn *c) { - struct ctl_conn *c; - - if ((c = control_connbyfd(fd)) == NULL) { - log_warn("control_close: fd %d: not found", fd); - return; - } TAILQ_REMOVE(&ctl_conns, c, entry); event_del(&c->iev.ev); + close(c->iev.ibuf.fd); imsg_clear(&c->iev.ibuf); - close(fd); free(c); stat_backend->decrement("control.session", 1); @@ -332,7 +324,7 @@ control_close(int fd) } /* ARGSUSED */ -void +static void control_dispatch_ext(int fd, short event, void *arg) { struct ctl_conn *c; @@ -356,21 +348,21 @@ control_dispatch_ext(int fd, short event, void *arg) if (event & EV_READ) { if ((n = imsg_read(&c->iev.ibuf)) == -1 || n == 0) { - control_close(fd); + control_close(c); return; } } if (event & EV_WRITE) { if (msgbuf_write(&c->iev.ibuf.w) < 0) { - control_close(fd); + control_close(c); return; } } for (;;) { if ((n = imsg_get(&c->iev.ibuf, &imsg)) == -1) { - control_close(fd); + control_close(c); return; } diff --git a/usr.sbin/smtpd/smtpd.h b/usr.sbin/smtpd/smtpd.h index c4a82b32f87..3a27e368f2c 100644 --- a/usr.sbin/smtpd/smtpd.h +++ b/usr.sbin/smtpd/smtpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: smtpd.h,v 1.369 2012/09/27 18:57:25 eric Exp $ */ +/* $OpenBSD: smtpd.h,v 1.370 2012/09/28 12:00:09 eric Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -203,14 +203,6 @@ struct imsgev { short events; }; -struct ctl_conn { - TAILQ_ENTRY(ctl_conn) entry; - uint8_t flags; -#define CTL_CONN_NOTIFY 0x01 - struct imsgev iev; -}; -TAILQ_HEAD(ctl_connlist, ctl_conn); - struct ctl_id { objid_t id; char name[MAX_NAME_SIZE]; @@ -947,9 +939,6 @@ void config_peers(struct peer *, uint); /* control.c */ pid_t control(void); -void session_socket_blockmode(int, enum blockmodes); -void session_socket_no_linger(int); -int session_socket_error(int); /* delivery.c */ @@ -1192,3 +1181,6 @@ void *xcalloc(size_t, size_t, const char *); char *xstrdup(const char *, const char *); void *xmemdup(const void *, size_t, const char *); void log_envelope(const struct envelope *, const char *, const char *); +void session_socket_blockmode(int, enum blockmodes); +void session_socket_no_linger(int); +int session_socket_error(int); |