summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Faurot <eric@cvs.openbsd.org>2013-10-27 18:51:00 +0000
committerEric Faurot <eric@cvs.openbsd.org>2013-10-27 18:51:00 +0000
commit60db32ed1676283ef0f262aa485d22e9d0954ffc (patch)
tree079098c7932f48db240f341e2486a3891d6d13bb
parent16dd0bc9233cb54f0ec67d3a15ed34cf0c0622a4 (diff)
use log_* functions instead of err*/warn*
-rw-r--r--usr.sbin/smtpd/util.c75
1 files changed, 45 insertions, 30 deletions
diff --git a/usr.sbin/smtpd/util.c b/usr.sbin/smtpd/util.c
index 8e3dbad81fd..91fd57b7910 100644
--- a/usr.sbin/smtpd/util.c
+++ b/usr.sbin/smtpd/util.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: util.c,v 1.98 2013/10/25 21:31:23 eric Exp $ */
+/* $OpenBSD: util.c,v 1.99 2013/10/27 18:50:59 eric Exp $ */
/*
* Copyright (c) 2000,2001 Markus Friedl. All rights reserved.
@@ -30,7 +30,6 @@
#include <arpa/inet.h>
#include <ctype.h>
-#include <err.h>
#include <errno.h>
#include <event.h>
#include <fcntl.h>
@@ -58,8 +57,10 @@ xmalloc(size_t size, const char *where)
{
void *r;
- if ((r = malloc(size)) == NULL)
- errx(1, "%s: malloc(%zu)", where, size);
+ if ((r = malloc(size)) == NULL) {
+ log_warnx("%s: malloc(%zu)", where, size);
+ fatalx("exiting");
+ }
return (r);
}
@@ -69,8 +70,10 @@ xcalloc(size_t nmemb, size_t size, const char *where)
{
void *r;
- if ((r = calloc(nmemb, size)) == NULL)
- errx(1, "%s: calloc(%zu, %zu)", where, nmemb, size);
+ if ((r = calloc(nmemb, size)) == NULL) {
+ log_warnx("%s: calloc(%zu, %zu)", where, nmemb, size);
+ fatalx("exiting");
+ }
return (r);
}
@@ -80,8 +83,10 @@ xstrdup(const char *str, const char *where)
{
char *r;
- if ((r = strdup(str)) == NULL)
- errx(1, "%s: strdup(%p)", where, str);
+ if ((r = strdup(str)) == NULL) {
+ log_warnx("%s: strdup(%p)", where, str);
+ fatalx("exiting");
+ }
return (r);
}
@@ -91,8 +96,10 @@ xmemdup(const void *ptr, size_t size, const char *where)
{
void *r;
- if ((r = malloc(size)) == NULL)
- errx(1, "%s: malloc(%zu)", where, size);
+ if ((r = malloc(size)) == NULL) {
+ log_warnx("%s: malloc(%zu)", where, size);
+ fatalx("exiting");
+ }
memmove(r, ptr, size);
return (r);
@@ -102,8 +109,10 @@ xmemdup(const void *ptr, size_t size, const char *where)
void
iobuf_xinit(struct iobuf *io, size_t size, size_t max, const char *where)
{
- if (iobuf_init(io, size, max) == -1)
- errx(1, "%s: iobuf_init(%p, %zu, %zu)", where, io, size, max);
+ if (iobuf_init(io, size, max) == -1) {
+ log_warnx("%s: iobuf_init(%p, %zu, %zu)", where, io, size, max);
+ fatalx("exiting");
+ }
}
void
@@ -116,8 +125,10 @@ iobuf_xfqueue(struct iobuf *io, const char *where, const char *fmt, ...)
len = iobuf_vfqueue(io, fmt, ap);
va_end(ap);
- if (len == -1)
- errx(1, "%s: iobuf_xfqueue(%p, %s, ...)", where, io, fmt);
+ if (len == -1) {
+ log_warnx("%s: iobuf_xfqueue(%p, %s, ...)", where, io, fmt);
+ fatalx("exiting");
+ }
}
#endif
@@ -223,28 +234,28 @@ ckdir(const char *path, mode_t mode, uid_t owner, gid_t group, int create)
if (stat(path, &sb) == -1) {
if (errno != ENOENT || create == 0) {
- warn("stat: %s", path);
+ log_warn("stat: %s", path);
return (0);
}
/* chmod is deferred to avoid umask effect */
if (mkdir(path, 0) == -1) {
- warn("mkdir: %s", path);
+ log_warn("mkdir: %s", path);
return (0);
}
if (chown(path, owner, group) == -1) {
- warn("chown: %s", path);
+ log_warn("chown: %s", path);
return (0);
}
if (chmod(path, mode) == -1) {
- warn("chmod: %s", path);
+ log_warn("chmod: %s", path);
return (0);
}
if (stat(path, &sb) == -1) {
- warn("stat: %s", path);
+ log_warn("stat: %s", path);
return (0);
}
}
@@ -254,17 +265,17 @@ ckdir(const char *path, mode_t mode, uid_t owner, gid_t group, int create)
/* check if it's a directory */
if (!S_ISDIR(sb.st_mode)) {
ret = 0;
- warnx("%s is not a directory", path);
+ log_warnx("%s is not a directory", path);
}
/* check that it is owned by owner/group */
if (sb.st_uid != owner) {
ret = 0;
- warnx("%s is not owned by uid %d", path, owner);
+ log_warnx("%s is not owned by uid %d", path, owner);
}
if (sb.st_gid != group) {
ret = 0;
- warnx("%s is not owned by gid %d", path, group);
+ log_warnx("%s is not owned by gid %d", path, group);
}
/* check permission */
@@ -272,7 +283,7 @@ ckdir(const char *path, mode_t mode, uid_t owner, gid_t group, int create)
ret = 0;
strmode(mode, mode_str);
mode_str[10] = '\0';
- warnx("%s must be %s (%o)", path, mode_str + 1, mode);
+ log_warnx("%s must be %s (%o)", path, mode_str + 1, mode);
}
return ret;
@@ -293,7 +304,7 @@ rmtree(char *path, int keepdir)
fts = fts_open(path_argv, FTS_PHYSICAL | FTS_NOCHDIR, NULL);
if (fts == NULL) {
- warn("fts_open: %s", path);
+ log_warn("fts_open: %s", path);
return (-1);
}
@@ -308,14 +319,14 @@ rmtree(char *path, int keepdir)
if (keepdir && depth == 0)
continue;
if (rmdir(e->fts_path) == -1) {
- warn("rmdir: %s", e->fts_path);
+ log_warn("rmdir: %s", e->fts_path);
ret = -1;
}
break;
case FTS_F:
if (unlink(e->fts_path) == -1) {
- warn("unlink: %s", e->fts_path);
+ log_warn("unlink: %s", e->fts_path);
ret = -1;
}
}
@@ -367,12 +378,16 @@ mktmpfile(void)
mode_t omode;
if (! bsnprintf(path, sizeof(path), "%s/smtpd.XXXXXXXXXX",
- PATH_TEMPORARY))
- err(1, "snprintf");
+ PATH_TEMPORARY)) {
+ log_warn("snprintf");
+ fatal("exiting");
+ }
omode = umask(7077);
- if ((fd = mkstemp(path)) == -1)
- err(1, "cannot create temporary file %s", path);
+ if ((fd = mkstemp(path)) == -1) {
+ log_warn("cannot create temporary file %s", path);
+ fatal("exiting");
+ }
umask(omode);
unlink(path);
return (fd);