Module Name: src Committed By: martin Date: Mon Sep 12 10:30:39 UTC 2022
Modified Files: src/libexec/httpd: bozohttpd.c bozohttpd.h main.c ssl-bozo.c Log Message: Add a -q option to make http quiet (no log messages). Usefull when running multiple instances and some for (high traffic) APIs e.g. to receive log data from appliences - it makes not sense to duplicate the whole log in the xferlog file (but we can't configure that at the syslog level due to other httpd instances using that). To generate a diff of this commit: cvs rdiff -u -r1.141 -r1.142 src/libexec/httpd/bozohttpd.c cvs rdiff -u -r1.72 -r1.73 src/libexec/httpd/bozohttpd.h cvs rdiff -u -r1.29 -r1.30 src/libexec/httpd/main.c cvs rdiff -u -r1.31 -r1.32 src/libexec/httpd/ssl-bozo.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/libexec/httpd/bozohttpd.c diff -u src/libexec/httpd/bozohttpd.c:1.141 src/libexec/httpd/bozohttpd.c:1.142 --- src/libexec/httpd/bozohttpd.c:1.141 Wed May 18 00:37:11 2022 +++ src/libexec/httpd/bozohttpd.c Mon Sep 12 10:30:39 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: bozohttpd.c,v 1.141 2022/05/18 00:37:11 mrg Exp $ */ +/* $NetBSD: bozohttpd.c,v 1.142 2022/09/12 10:30:39 martin Exp $ */ /* $eterna: bozohttpd.c,v 1.178 2011/11/18 09:21:15 mrg Exp $ */ @@ -2022,11 +2022,13 @@ debug__(bozohttpd_t *httpd, int level, c savederrno = errno; va_start(ap, fmt); - if (httpd->logstderr) { - vfprintf(stderr, fmt, ap); - fputs("\n", stderr); - } else - vsyslog(LOG_DEBUG, fmt, ap); + if (!httpd->nolog) { + if (httpd->logstderr) { + vfprintf(stderr, fmt, ap); + fputs("\n", stderr); + } else + vsyslog(LOG_DEBUG, fmt, ap); + } va_end(ap); errno = savederrno; } @@ -2039,12 +2041,14 @@ bozowarn(bozohttpd_t *httpd, const char va_list ap; va_start(ap, fmt); - if (httpd->logstderr || isatty(STDERR_FILENO)) { - //fputs("warning: ", stderr); - vfprintf(stderr, fmt, ap); - fputs("\n", stderr); - } else - vsyslog(LOG_INFO, fmt, ap); + if (!httpd->nolog) { + if (httpd->logstderr || isatty(STDERR_FILENO)) { + //fputs("warning: ", stderr); + vfprintf(stderr, fmt, ap); + fputs("\n", stderr); + } else + vsyslog(LOG_INFO, fmt, ap); + } va_end(ap); } @@ -2054,12 +2058,14 @@ bozoerr(bozohttpd_t *httpd, int code, co va_list ap; va_start(ap, fmt); - if (httpd->logstderr || isatty(STDERR_FILENO)) { - //fputs("error: ", stderr); - vfprintf(stderr, fmt, ap); - fputs("\n", stderr); - } else - vsyslog(LOG_ERR, fmt, ap); + if (!httpd->nolog) { + if (httpd->logstderr || isatty(STDERR_FILENO)) { + //fputs("error: ", stderr); + vfprintf(stderr, fmt, ap); + fputs("\n", stderr); + } else + vsyslog(LOG_ERR, fmt, ap); + } va_end(ap); exit(code); } @@ -2591,6 +2597,10 @@ bozo_setup(bozohttpd_t *httpd, bozoprefs strcmp(cp, "true") == 0) { httpd->logstderr = 1; } + if ((cp = bozo_get_pref(prefs, "no log")) != NULL && + strcmp(cp, "true") == 0) { + httpd->nolog = 1; + } if ((cp = bozo_get_pref(prefs, "bind address")) != NULL) { httpd->bindaddress = bozostrdup(httpd, NULL, cp); } Index: src/libexec/httpd/bozohttpd.h diff -u src/libexec/httpd/bozohttpd.h:1.72 src/libexec/httpd/bozohttpd.h:1.73 --- src/libexec/httpd/bozohttpd.h:1.72 Wed May 18 00:37:11 2022 +++ src/libexec/httpd/bozohttpd.h Mon Sep 12 10:30:39 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: bozohttpd.h,v 1.72 2022/05/18 00:37:11 mrg Exp $ */ +/* $NetBSD: bozohttpd.h,v 1.73 2022/09/12 10:30:39 martin Exp $ */ /* $eterna: bozohttpd.h,v 1.39 2011/11/18 09:21:15 mrg Exp $ */ @@ -103,6 +103,7 @@ typedef struct bozohttpd_t { char *virtbase; /* virtual directory base */ int unknown_slash; /* unknown vhosts go to normal slashdir */ int logstderr; /* log to stderr (even if not tty) */ + int nolog; /* do not log anything */ int background; /* drop into daemon mode */ int foreground; /* keep daemon mode in foreground */ char *pidfile; /* path to the pid file, if any */ Index: src/libexec/httpd/main.c diff -u src/libexec/httpd/main.c:1.29 src/libexec/httpd/main.c:1.30 --- src/libexec/httpd/main.c:1.29 Tue Aug 24 09:47:36 2021 +++ src/libexec/httpd/main.c Mon Sep 12 10:30:39 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: main.c,v 1.29 2021/08/24 09:47:36 mrg Exp $ */ +/* $NetBSD: main.c,v 1.30 2022/09/12 10:30:39 martin Exp $ */ /* $eterna: main.c,v 1.6 2011/11/18 09:21:15 mrg Exp $ */ /* from: eterna: bozohttpd.c,v 1.159 2009/05/23 02:14:30 mrg Exp */ @@ -102,6 +102,8 @@ usage(bozohttpd_t *httpd, char *progname bozowarn(httpd, " -P pidfile\t\tpid file path"); if (have_user) bozowarn(httpd, " -p dir\t\t\"public_html\" directory name"); + if (have_core) + bozowarn(httpd, " -q\t\tquiet mode, no logging"); if (have_dirindex) bozowarn(httpd, " -R readme\t\tput readme file in footer " "of directory index"); @@ -164,7 +166,7 @@ main(int argc, char **argv) */ while ((c = getopt(argc, argv, - "C:EGHI:L:M:m:P:R:S:T:U:VXZ:bc:defhi:np:st:uv:x:z:")) != -1) { + "C:EGHI:L:M:m:P:R:S:T:U:VXZ:bc:defhi:np:qst:uv:x:z:")) != -1) { switch (c) { case 'b': @@ -310,6 +312,10 @@ main(int argc, char **argv) bozo_set_pref(&httpd, &prefs, "public_html", optarg); break; + case 'q': + bozo_set_pref(&httpd, &prefs, "no log", "true"); + break; + case 'R': if (!have_dirindex) goto no_dirindex_support; Index: src/libexec/httpd/ssl-bozo.c diff -u src/libexec/httpd/ssl-bozo.c:1.31 src/libexec/httpd/ssl-bozo.c:1.32 --- src/libexec/httpd/ssl-bozo.c:1.31 Tue Aug 24 09:53:26 2021 +++ src/libexec/httpd/ssl-bozo.c Mon Sep 12 10:30:39 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: ssl-bozo.c,v 1.31 2021/08/24 09:53:26 mrg Exp $ */ +/* $NetBSD: ssl-bozo.c,v 1.32 2022/09/12 10:30:39 martin Exp $ */ /* $eterna: ssl-bozo.c,v 1.15 2011/11/18 09:21:15 mrg Exp $ */ @@ -121,6 +121,9 @@ bozo_clear_ssl_queue(bozohttpd_t *httpd) do { static const char sslfmt[] = "SSL Error: %s:%s:%s"; + if (httpd->nolog) + continue; + if (httpd->logstderr || isatty(STDERR_FILENO)) { fprintf(stderr, sslfmt, ERR_lib_error_string(sslcode), @@ -144,11 +147,13 @@ bozo_ssl_warn(bozohttpd_t *httpd, const va_list ap; va_start(ap, fmt); - if (httpd->logstderr || isatty(STDERR_FILENO)) { - vfprintf(stderr, fmt, ap); - fputs("\n", stderr); - } else - vsyslog(LOG_ERR, fmt, ap); + if (!httpd->nolog) { + if (httpd->logstderr || isatty(STDERR_FILENO)) { + vfprintf(stderr, fmt, ap); + fputs("\n", stderr); + } else + vsyslog(LOG_ERR, fmt, ap); + } va_end(ap); bozo_clear_ssl_queue(httpd); @@ -164,11 +169,13 @@ bozo_ssl_err(bozohttpd_t *httpd, int cod va_list ap; va_start(ap, fmt); - if (httpd->logstderr || isatty(STDERR_FILENO)) { - vfprintf(stderr, fmt, ap); - fputs("\n", stderr); - } else - vsyslog(LOG_ERR, fmt, ap); + if (!httpd->nolog) { + if (httpd->logstderr || isatty(STDERR_FILENO)) { + vfprintf(stderr, fmt, ap); + fputs("\n", stderr); + } else + vsyslog(LOG_ERR, fmt, ap); + } va_end(ap); bozo_clear_ssl_queue(httpd);