[Midnightbsd-cvs] src: usr.sbin/mailwrapper: Cleanups for mailwrapper(8): - K&R -> ANSI
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Mon Apr 28 00:00:57 EDT 2008
Log Message:
-----------
Cleanups for mailwrapper(8):
- K&R -> ANSI prototype [O]
- Do not bother to do free right before exit() or execve() [O]
- Remove some dead code in addarg()
- Make additional parameters specified in mailer.conf(5)
actually work and document the fact. [N]
- Avoid using __progname but instead use getprogname()
and setprogname() to provide more sensible messages. [O, N]
- Update $OpenBSD$ and $NetBSD$ to reflect the fact that we
have sync'ed with their code.
- WARNS=6
Improvements from FreeBSD, NetBSD and OpenBSD.
Modified Files:
--------------
src/usr.sbin/mailwrapper:
Makefile (r1.1.1.1 -> r1.2)
mailwrapper.8 (r1.1.1.1 -> r1.2)
mailwrapper.c (r1.1.1.1 -> r1.2)
pathnames.h (r1.1.1.1 -> r1.2)
-------------- next part --------------
Index: mailwrapper.c
===================================================================
RCS file: /home/cvs/src/usr.sbin/mailwrapper/mailwrapper.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L usr.sbin/mailwrapper/mailwrapper.c -L usr.sbin/mailwrapper/mailwrapper.c -u -r1.1.1.1 -r1.2
--- usr.sbin/mailwrapper/mailwrapper.c
+++ usr.sbin/mailwrapper/mailwrapper.c
@@ -1,5 +1,5 @@
-/* $OpenBSD: mailwrapper.c,v 1.6 1999/12/17 05:06:28 mickey Exp $ */
-/* $NetBSD: mailwrapper.c,v 1.3 1999/05/29 18:18:15 christos Exp $ */
+/* $OpenBSD: mailwrapper.c,v 1.16 2004/07/06 03:38:14 millert Exp $ */
+/* $NetBSD: mailwrapper.c,v 1.9 2003/03/09 08:10:43 mjl Exp $ */
/*
* Copyright (c) 1998
@@ -33,16 +33,17 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/usr.sbin/mailwrapper/mailwrapper.c,v 1.9 2003/07/06 12:44:11 charnier Exp $");
+/* $FreeBSD: src/usr.sbin/mailwrapper/mailwrapper.c,v 1.11 2006/08/07 10:29:18 delphij Exp $ */
+__MBSDID("$MIdnightBSD$");
#include <err.h>
#include <stdio.h>
#include <string.h>
-#include <stdlib.h>
#include <unistd.h>
+#include <stdlib.h>
#include <libutil.h>
+#include <sysexits.h>
#include <syslog.h>
-#include <stdarg.h>
#include "pathnames.h"
@@ -54,93 +55,66 @@
int main(int, char *[], char *[]);
static void initarg(struct arglist *);
-static void addarg(struct arglist *, const char *, int);
-static void freearg(struct arglist *, int);
-
-extern const char *__progname; /* from crt0.o */
+static void addarg(struct arglist *, const char *);
static void
-initarg(al)
- struct arglist *al;
+initarg(struct arglist *al)
{
al->argc = 0;
al->maxc = 10;
if ((al->argv = malloc(al->maxc * sizeof(char *))) == NULL)
- err(1, NULL);
+ err(EX_TEMPFAIL, "malloc");
}
static void
-addarg(al, arg, copy)
- struct arglist *al;
- const char *arg;
- int copy;
+addarg(struct arglist *al, const char *arg)
{
- char **argv2;
if (al->argc == al->maxc) {
al->maxc <<= 1;
-
- if ((argv2 = realloc(al->argv,
- al->maxc * sizeof(char *))) == NULL) {
- if (al->argv)
- free(al->argv);
- al->argv = NULL;
- err(1, NULL);
- } else {
- al->argv = argv2;
- }
+ al->argv = realloc(al->argv, al->maxc * sizeof(char *));
+ if (al->argv == NULL)
+ err(EX_TEMPFAIL, "realloc");
}
- if (copy) {
- if ((al->argv[al->argc++] = strdup(arg)) == NULL)
- err(1, NULL);
- } else
- al->argv[al->argc++] = (char *)arg;
-}
-
-static void
-freearg(al, copy)
- struct arglist *al;
- int copy;
-{
- size_t i;
- if (copy)
- for (i = 0; i < al->argc; i++)
- free(al->argv[i]);
- free(al->argv);
+ if (arg == NULL)
+ al->argv[al->argc++] = NULL;
+ else if ((al->argv[al->argc++] = strdup(arg)) == NULL)
+ err(EX_TEMPFAIL, "strdup");
}
int
-main(argc, argv, envp)
- int argc;
- char *argv[];
- char *envp[];
+main(int argc, char *argv[], char *envp[])
{
FILE *config;
char *line, *cp, *from, *to, *ap;
+ const char *progname;
size_t len, lineno = 0;
+ int i;
struct arglist al;
+ /* change __progname to mailwrapper so we get sensible error messages */
+ progname = getprogname();
+ setprogname("mailwrapper");
+
initarg(&al);
- for (len = 0; len < argc; len++)
- addarg(&al, argv[len], 0);
+ addarg(&al, argv[0]);
if ((config = fopen(_PATH_MAILERCONF, "r")) == NULL) {
- addarg(&al, NULL, 0);
- openlog("mailwrapper", LOG_PID, LOG_MAIL);
- syslog(LOG_INFO, "can't open %s, using %s as default MTA",
+ addarg(&al, NULL);
+ openlog(getprogname(), LOG_PID, LOG_MAIL);
+ syslog(LOG_INFO, "cannot open %s, using %s as default MTA",
_PATH_MAILERCONF, _PATH_DEFAULTMTA);
closelog();
execve(_PATH_DEFAULTMTA, al.argv, envp);
- freearg(&al, 0);
- err(1, "execing %s", _PATH_DEFAULTMTA);
+ err(EX_OSERR, "cannot exec %s", _PATH_DEFAULTMTA);
/*NOTREACHED*/
}
for (;;) {
if ((line = fparseln(config, &len, &lineno, NULL, 0)) == NULL) {
if (feof(config))
- errx(1, "no mapping in %s", _PATH_MAILERCONF);
- err(1, "can't parse line %lu", (u_long)lineno);
+ errx(EX_CONFIG, "no mapping in %s", _PATH_MAILERCONF);
+ err(EX_CONFIG, "cannot parse line %lu", (u_long)lineno);
}
#define WS " \t\n"
@@ -161,11 +135,12 @@
if ((to = strsep(&cp, WS)) == NULL)
goto parse_error;
- if (strcmp(from, __progname) == 0) {
- for (ap = strsep(&cp, WS); ap != NULL;
- ap = strsep(&cp, WS))
- if (*ap)
- addarg(&al, ap, 0);
+ if (strcmp(from, progname) == 0) {
+ for (ap = strsep(&cp, WS); ap != NULL;
+ ap = strsep(&cp, WS)) {
+ if (*ap)
+ addarg(&al, ap);
+ }
break;
}
@@ -174,17 +149,15 @@
(void)fclose(config);
- addarg(&al, NULL, 0);
+ for (i = 1; i < argc; i++)
+ addarg(&al, argv[i]);
+
+ addarg(&al, NULL);
execve(to, al.argv, envp);
- freearg(&al, 0);
- warn("execing %s", to);
- free(line);
- exit(1);
+ err(EX_OSERR, "cannot exec %s", to);
/*NOTREACHED*/
parse_error:
- freearg(&al, 0);
- free(line);
- errx(1, "parse error in %s at line %lu",
+ errx(EX_CONFIG, "parse error in %s at line %lu",
_PATH_MAILERCONF, (u_long)lineno);
/*NOTREACHED*/
}
Index: mailwrapper.8
===================================================================
RCS file: /home/cvs/src/usr.sbin/mailwrapper/mailwrapper.8,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L usr.sbin/mailwrapper/mailwrapper.8 -L usr.sbin/mailwrapper/mailwrapper.8 -u -r1.1.1.1 -r1.2
--- usr.sbin/mailwrapper/mailwrapper.8
+++ usr.sbin/mailwrapper/mailwrapper.8
@@ -1,5 +1,7 @@
-.\" $NetBSD: mailwrapper.8,v 1.6 1999/03/25 16:40:17 is Exp $
-.\" $FreeBSD: src/usr.sbin/mailwrapper/mailwrapper.8,v 1.12 2004/07/02 23:12:48 ru Exp $
+.\" $NetBSD: mailwrapper.8,v 1.11 2002/02/08 01:38:50 ross Exp $
+.\" $OpenBSD: mailwrapper.8,v 1.8 2003/06/12 12:59:51 jmc Exp $
+.\" $FreeBSD: src/usr.sbin/mailwrapper/mailwrapper.8,v 1.14 2006/09/29 17:57:02 ru Exp $
+.\" $MidnightBSD$
.\"
.\" Copyright (c) 1998
.\" Perry E. Metzger. All rights reserved.
@@ -31,7 +33,7 @@
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
.\" The following requests are required for all man pages.
-.Dd December 16, 1998
+.Dd August 7, 2006
.Dt MAILWRAPPER 8
.Os
.Sh NAME
@@ -84,10 +86,10 @@
based on calling name, or through a set of programs that provide
similar functionality.
.Pp
-Although having replacement programs that plug replace
+Although having drop-in replacements for
.Xr sendmail 8
helps in installing alternative MTAs, it essentially makes the
-configuration of the system depend on hard installing new programs in
+configuration of the system depend on hand installing new programs in
.Pa /usr .
This leads to configuration problems for many administrators, since
they may wish to install a new MTA without altering the system
@@ -131,14 +133,13 @@
is typically set up as a symbolic link to
.Nm
which is not usually invoked on its own.
+.Sh EXIT STATUS
+.Ex -std
.Sh DIAGNOSTICS
The
.Nm
-utility will return an error value and print a diagnostic if its configuration
-file is missing or malformed, or does not contain a mapping for the
-name under which
-.Nm
-was invoked.
+will print a diagnostic if its configuration file is missing or malformed,
+or does not contain a mapping for the name under which it was invoked.
.Sh SEE ALSO
.Xr mail 1 ,
.Xr mailq 1 ,
Index: Makefile
===================================================================
RCS file: /home/cvs/src/usr.sbin/mailwrapper/Makefile,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L usr.sbin/mailwrapper/Makefile -L usr.sbin/mailwrapper/Makefile -u -r1.1.1.1 -r1.2
--- usr.sbin/mailwrapper/Makefile
+++ usr.sbin/mailwrapper/Makefile
@@ -1,3 +1,4 @@
+# $MidnightBSD$
# $FreeBSD: src/usr.sbin/mailwrapper/Makefile,v 1.13 2004/10/18 17:20:29 ru Exp $
.if !defined(NO_MAILWRAPPER)
Index: pathnames.h
===================================================================
RCS file: /home/cvs/src/usr.sbin/mailwrapper/pathnames.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L usr.sbin/mailwrapper/pathnames.h -L usr.sbin/mailwrapper/pathnames.h -u -r1.1.1.1 -r1.2
--- usr.sbin/mailwrapper/pathnames.h
+++ usr.sbin/mailwrapper/pathnames.h
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/* $FreeBSD: src/usr.sbin/mailwrapper/pathnames.h,v 1.3 2000/01/10 03:20:13 imp Exp $ */
/*
More information about the Midnightbsd-cvs
mailing list