summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@cvs.openbsd.org>2016-04-15 16:42:40 +0000
committerIngo Schwarze <schwarze@cvs.openbsd.org>2016-04-15 16:42:40 +0000
commitbe961748122c333d012180bf5f1a2dbfe284c4e5 (patch)
treefb87e39757fe1ed2692dd8481aca06464e3bb9dd /usr.bin
parentb4323358431548bc3774a4ee393a48c12cb0b441 (diff)
prefer warn[x](3) over fprintf(3) where appropriate
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/mandoc/cgi.c42
1 files changed, 19 insertions, 23 deletions
diff --git a/usr.bin/mandoc/cgi.c b/usr.bin/mandoc/cgi.c
index 178561fb1f0..0d0f00c4d3c 100644
--- a/usr.bin/mandoc/cgi.c
+++ b/usr.bin/mandoc/cgi.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cgi.c,v 1.66 2016/04/15 15:13:02 schwarze Exp $ */
+/* $OpenBSD: cgi.c,v 1.67 2016/04/15 16:42:39 schwarze Exp $ */
/*
* Copyright (c) 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2014, 2015, 2016 Ingo Schwarze <schwarze@usta.de>
@@ -19,6 +19,7 @@
#include <sys/time.h>
#include <ctype.h>
+#include <err.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
@@ -562,7 +563,7 @@ pg_searchres(const struct req *req, struct manpage *r, size_t sz)
for (i = 0; i < sz; i++) {
if (validate_filename(r[i].file))
continue;
- fprintf(stderr, "invalid filename %s in %s database\n",
+ warnx("invalid filename %s in %s database",
r[i].file, req->q.manpath);
pg_error_internal();
return;
@@ -822,8 +823,7 @@ format(const struct req *req, const char *file)
mparse_result(mp, &man, NULL);
if (man == NULL) {
- fprintf(stderr, "fatal mandoc error: %s/%s\n",
- req->q.manpath, file);
+ warnx("fatal mandoc error: %s/%s", req->q.manpath, file);
pg_error_internal();
mparse_free(mp);
mchars_free();
@@ -887,8 +887,7 @@ pg_show(struct req *req, const char *fullpath)
*/
if (chdir(manpath) == -1) {
- fprintf(stderr, "chdir %s: %s\n",
- manpath, strerror(errno));
+ warn("chdir %s", manpath);
pg_error_internal();
free(manpath);
return;
@@ -929,9 +928,8 @@ pg_search(const struct req *req)
* relative to the manpath root.
*/
- if (-1 == (chdir(req->q.manpath))) {
- fprintf(stderr, "chdir %s: %s\n",
- req->q.manpath, strerror(errno));
+ if (chdir(req->q.manpath) == -1) {
+ warn("chdir %s", req->q.manpath);
pg_error_internal();
return;
}
@@ -1006,7 +1004,7 @@ main(void)
itimer.it_interval.tv_sec = 2;
itimer.it_interval.tv_usec = 0;
if (setitimer(ITIMER_VIRTUAL, &itimer, NULL) == -1) {
- fprintf(stderr, "setitimer: %s\n", strerror(errno));
+ warn("setitimer");
pg_error_internal();
return EXIT_FAILURE;
}
@@ -1017,9 +1015,8 @@ main(void)
* relative to the same position.
*/
- if (-1 == chdir(MAN_DIR)) {
- fprintf(stderr, "MAN_DIR: %s: %s\n",
- MAN_DIR, strerror(errno));
+ if (chdir(MAN_DIR) == -1) {
+ warn("MAN_DIR: %s", MAN_DIR);
pg_error_internal();
return EXIT_FAILURE;
}
@@ -1140,9 +1137,8 @@ pathgen(struct req *req)
size_t dpsz;
ssize_t len;
- if (NULL == (fp = fopen("manpath.conf", "r"))) {
- fprintf(stderr, "%s/manpath.conf: %s\n",
- MAN_DIR, strerror(errno));
+ if ((fp = fopen("manpath.conf", "r")) == NULL) {
+ warn("%s/manpath.conf", MAN_DIR);
pg_error_internal();
exit(EXIT_FAILURE);
}
@@ -1156,14 +1152,14 @@ pathgen(struct req *req)
req->p = mandoc_realloc(req->p,
(req->psz + 1) * sizeof(char *));
if ( ! validate_urifrag(dp)) {
- fprintf(stderr, "%s/manpath.conf contains "
- "unsafe path \"%s\"\n", MAN_DIR, dp);
+ warnx("%s/manpath.conf contains "
+ "unsafe path \"%s\"", MAN_DIR, dp);
pg_error_internal();
exit(EXIT_FAILURE);
}
- if (NULL != strchr(dp, '/')) {
- fprintf(stderr, "%s/manpath.conf contains "
- "path with slash \"%s\"\n", MAN_DIR, dp);
+ if (strchr(dp, '/') != NULL) {
+ warnx("%s/manpath.conf contains "
+ "path with slash \"%s\"", MAN_DIR, dp);
pg_error_internal();
exit(EXIT_FAILURE);
}
@@ -1173,8 +1169,8 @@ pathgen(struct req *req)
}
free(dp);
- if ( req->p == NULL ) {
- fprintf(stderr, "%s/manpath.conf is empty\n", MAN_DIR);
+ if (req->p == NULL) {
+ warnx("%s/manpath.conf is empty", MAN_DIR);
pg_error_internal();
exit(EXIT_FAILURE);
}