Sat Aug 27 15:33:59 2011 UTC ()
Don't check for __attribute__ being defined, it won't. Check for GCC 3.x
or compatible and define BOZO_PRINTFLIKE / BOZO_DEAD. Fix fallout.


(joerg)
diff -r1.27 -r1.28 src/libexec/httpd/bozohttpd.c
diff -r1.18 -r1.19 src/libexec/httpd/bozohttpd.h
diff -r1.13 -r1.14 src/libexec/httpd/daemon-bozo.c
diff -r1.2 -r1.3 src/libexec/httpd/main.c
diff -r1.11 -r1.12 src/libexec/httpd/ssl-bozo.c

cvs diff -r1.27 -r1.28 src/libexec/httpd/bozohttpd.c (expand / switch to unified diff)

--- src/libexec/httpd/bozohttpd.c 2011/03/29 07:22:31 1.27
+++ src/libexec/httpd/bozohttpd.c 2011/08/27 15:33:59 1.28
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: bozohttpd.c,v 1.27 2011/03/29 07:22:31 jmmv Exp $ */ 1/* $NetBSD: bozohttpd.c,v 1.28 2011/08/27 15:33:59 joerg Exp $ */
2 2
3/* $eterna: bozohttpd.c,v 1.176 2010/09/20 22:26:28 mrg Exp $ */ 3/* $eterna: bozohttpd.c,v 1.176 2010/09/20 22:26:28 mrg Exp $ */
4 4
5/* 5/*
6 * Copyright (c) 1997-2010 Matthew R. Green 6 * Copyright (c) 1997-2010 Matthew R. Green
7 * All rights reserved. 7 * All rights reserved.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
@@ -144,30 +144,26 @@ @@ -144,30 +144,26 @@
144#include <errno.h> 144#include <errno.h>
145#include <fcntl.h> 145#include <fcntl.h>
146#include <netdb.h> 146#include <netdb.h>
147#include <pwd.h> 147#include <pwd.h>
148#include <grp.h> 148#include <grp.h>
149#include <signal.h> 149#include <signal.h>
150#include <stdarg.h> 150#include <stdarg.h>
151#include <stdlib.h> 151#include <stdlib.h>
152#include <string.h> 152#include <string.h>
153#include <syslog.h> 153#include <syslog.h>
154#include <time.h> 154#include <time.h>
155#include <unistd.h> 155#include <unistd.h>
156 156
157#ifndef __attribute__ 
158#define __attribute__(x) 
159#endif /* __attribute__ */ 
160 
161#include "bozohttpd.h" 157#include "bozohttpd.h"
162 158
163#ifndef MAX_WAIT_TIME 159#ifndef MAX_WAIT_TIME
164#define MAX_WAIT_TIME 60 /* hang around for 60 seconds max */ 160#define MAX_WAIT_TIME 60 /* hang around for 60 seconds max */
165#endif 161#endif
166 162
167/* variables and functions */ 163/* variables and functions */
168#ifndef LOG_FTP 164#ifndef LOG_FTP
169#define LOG_FTP LOG_DAEMON 165#define LOG_FTP LOG_DAEMON
170#endif 166#endif
171 167
172volatile sig_atomic_t alarmhit; 168volatile sig_atomic_t alarmhit;
173 169
@@ -1402,29 +1398,30 @@ bozo_process_request(bozo_httpreq_t *req @@ -1402,29 +1398,30 @@ bozo_process_request(bozo_httpreq_t *req
1402 goto cleanup; 1398 goto cleanup;
1403 } 1399 }
1404 1400
1405 /* validate requested range */ 1401 /* validate requested range */
1406 if (request->hr_last_byte_pos == -1 || 1402 if (request->hr_last_byte_pos == -1 ||
1407 request->hr_last_byte_pos >= sb.st_size) 1403 request->hr_last_byte_pos >= sb.st_size)
1408 request->hr_last_byte_pos = sb.st_size - 1; 1404 request->hr_last_byte_pos = sb.st_size - 1;
1409 if (request->hr_have_range && 1405 if (request->hr_have_range &&
1410 request->hr_first_byte_pos > request->hr_last_byte_pos) { 1406 request->hr_first_byte_pos > request->hr_last_byte_pos) {
1411 request->hr_have_range = 0; /* punt */ 1407 request->hr_have_range = 0; /* punt */
1412 request->hr_first_byte_pos = 0; 1408 request->hr_first_byte_pos = 0;
1413 request->hr_last_byte_pos = sb.st_size - 1; 1409 request->hr_last_byte_pos = sb.st_size - 1;
1414 } 1410 }
1415 debug((httpd, DEBUG_FAT, "have_range %d first_pos %qd last_pos %qd", 1411 debug((httpd, DEBUG_FAT, "have_range %d first_pos %lld last_pos %lld",
1416 request->hr_have_range, 1412 request->hr_have_range,
1417 request->hr_first_byte_pos, request->hr_last_byte_pos)); 1413 (long long)request->hr_first_byte_pos,
 1414 (long long)request->hr_last_byte_pos));
1418 if (request->hr_have_range) 1415 if (request->hr_have_range)
1419 bozo_printf(httpd, "%s 206 Partial Content\r\n", 1416 bozo_printf(httpd, "%s 206 Partial Content\r\n",
1420 request->hr_proto); 1417 request->hr_proto);
1421 else 1418 else
1422 bozo_printf(httpd, "%s 200 OK\r\n", request->hr_proto); 1419 bozo_printf(httpd, "%s 200 OK\r\n", request->hr_proto);
1423 1420
1424 if (request->hr_proto != httpd->consts.http_09) { 1421 if (request->hr_proto != httpd->consts.http_09) {
1425 type = bozo_content_type(request, file); 1422 type = bozo_content_type(request, file);
1426 encoding = bozo_content_encoding(request, file); 1423 encoding = bozo_content_encoding(request, file);
1427 1424
1428 bozo_print_header(request, &sb, type, encoding); 1425 bozo_print_header(request, &sb, type, encoding);
1429 bozo_printf(httpd, "\r\n"); 1426 bozo_printf(httpd, "\r\n");
1430 } 1427 }
@@ -1838,27 +1835,27 @@ bozodgetln(bozohttpd_t *httpd, int fd, s @@ -1838,27 +1835,27 @@ bozodgetln(bozohttpd_t *httpd, int fd, s
1838 * the same spec defines CRLF as the line 1835 * the same spec defines CRLF as the line
1839 * terminator, it is recommended in section 19.3 1836 * terminator, it is recommended in section 19.3
1840 * to do the LF trick for tolerance. 1837 * to do the LF trick for tolerance.
1841 */ 1838 */
1842 if (got_cr) 1839 if (got_cr)
1843 len -= 2; 1840 len -= 2;
1844 else 1841 else
1845 len -= 1; 1842 len -= 1;
1846 break; 1843 break;
1847 } 1844 }
1848 1845
1849 } 1846 }
1850 httpd->getln_buffer[len] = '\0'; 1847 httpd->getln_buffer[len] = '\0';
1851 debug((httpd, DEBUG_OBESE, "bozodgetln returns: ``%s'' with len %d", 1848 debug((httpd, DEBUG_OBESE, "bozodgetln returns: ``%s'' with len %zd",
1852 httpd->getln_buffer, len)); 1849 httpd->getln_buffer, len));
1853 *lenp = len; 1850 *lenp = len;
1854 return httpd->getln_buffer; 1851 return httpd->getln_buffer;
1855} 1852}
1856 1853
1857void * 1854void *
1858bozorealloc(bozohttpd_t *httpd, void *ptr, size_t size) 1855bozorealloc(bozohttpd_t *httpd, void *ptr, size_t size)
1859{ 1856{
1860 void *p; 1857 void *p;
1861 1858
1862 p = realloc(ptr, size); 1859 p = realloc(ptr, size);
1863 if (p == NULL) { 1860 if (p == NULL) {
1864 (void)bozo_http_error(httpd, 500, NULL, 1861 (void)bozo_http_error(httpd, 500, NULL,

cvs diff -r1.18 -r1.19 src/libexec/httpd/bozohttpd.h (expand / switch to unified diff)

--- src/libexec/httpd/bozohttpd.h 2011/03/29 07:22:31 1.18
+++ src/libexec/httpd/bozohttpd.h 2011/08/27 15:33:59 1.19
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: bozohttpd.h,v 1.18 2011/03/29 07:22:31 jmmv Exp $ */ 1/* $NetBSD: bozohttpd.h,v 1.19 2011/08/27 15:33:59 joerg Exp $ */
2 2
3/* $eterna: bozohttpd.h,v 1.37 2010/09/20 22:26:28 mrg Exp $ */ 3/* $eterna: bozohttpd.h,v 1.37 2010/09/20 22:26:28 mrg Exp $ */
4 4
5/* 5/*
6 * Copyright (c) 1997-2010 Matthew R. Green 6 * Copyright (c) 1997-2010 Matthew R. Green
7 * All rights reserved. 7 * All rights reserved.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
@@ -162,31 +162,36 @@ typedef struct bozoprefs_t { @@ -162,31 +162,36 @@ typedef struct bozoprefs_t {
162#define DEBUG_OBESE 3 162#define DEBUG_OBESE 3
163#define DEBUG_EXPLODING 4 163#define DEBUG_EXPLODING 4
164 164
165#define strornull(x) ((x) ? (x) : "<null>") 165#define strornull(x) ((x) ? (x) : "<null>")
166 166
167#ifndef NO_DEBUG 167#ifndef NO_DEBUG
168void debug__(bozohttpd_t *, int, const char *, ...) 168void debug__(bozohttpd_t *, int, const char *, ...)
169 __attribute__((__format__(__printf__, 3, 4))); 169 __attribute__((__format__(__printf__, 3, 4)));
170#define debug(x) debug__ x 170#define debug(x) debug__ x
171#else 171#else
172#define debug(x)  172#define debug(x)
173#endif /* NO_DEBUG */ 173#endif /* NO_DEBUG */
174 174
 175#if defined(__GNUC__) && __GNUC__ >= 3
 176#define BOZO_PRINTFLIKE(x,y) __attribute__((__format__(__printf__, x,y)))
 177#define BOZO_DEAD __attribute__((__noreturn__))
 178#endif
 179
175void bozo_warn(bozohttpd_t *, const char *, ...) 180void bozo_warn(bozohttpd_t *, const char *, ...)
176 __attribute__((__format__(__printf__, 2, 3))); 181 BOZO_PRINTFLIKE(2, 3);
177void bozo_err(bozohttpd_t *, int, const char *, ...) 182void bozo_err(bozohttpd_t *, int, const char *, ...)
178 __attribute__((__format__(__printf__, 3, 4))) 183 BOZO_PRINTFLIKE(3, 4)
179 __attribute__((__noreturn__)); 184 BOZO_DEAD;
180int bozo_http_error(bozohttpd_t *, int, bozo_httpreq_t *, const char *); 185int bozo_http_error(bozohttpd_t *, int, bozo_httpreq_t *, const char *);
181 186
182int bozo_check_special_files(bozo_httpreq_t *, const char *); 187int bozo_check_special_files(bozo_httpreq_t *, const char *);
183char *bozo_http_date(char *, size_t); 188char *bozo_http_date(char *, size_t);
184void bozo_print_header(bozo_httpreq_t *, struct stat *, const char *, const char *); 189void bozo_print_header(bozo_httpreq_t *, struct stat *, const char *, const char *);
185 190
186char *bozodgetln(bozohttpd_t *, int, ssize_t *, ssize_t (*)(bozohttpd_t *, int, void *, size_t)); 191char *bozodgetln(bozohttpd_t *, int, ssize_t *, ssize_t (*)(bozohttpd_t *, int, void *, size_t));
187char *bozostrnsep(char **, const char *, ssize_t *); 192char *bozostrnsep(char **, const char *, ssize_t *);
188 193
189void *bozomalloc(bozohttpd_t *, size_t); 194void *bozomalloc(bozohttpd_t *, size_t);
190void *bozorealloc(bozohttpd_t *, void *, size_t); 195void *bozorealloc(bozohttpd_t *, void *, size_t);
191char *bozostrdup(bozohttpd_t *, const char *); 196char *bozostrdup(bozohttpd_t *, const char *);
192 197

cvs diff -r1.13 -r1.14 src/libexec/httpd/daemon-bozo.c (expand / switch to unified diff)

--- src/libexec/httpd/daemon-bozo.c 2011/03/29 07:22:31 1.13
+++ src/libexec/httpd/daemon-bozo.c 2011/08/27 15:33:59 1.14
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: daemon-bozo.c,v 1.13 2011/03/29 07:22:31 jmmv Exp $ */ 1/* $NetBSD: daemon-bozo.c,v 1.14 2011/08/27 15:33:59 joerg Exp $ */
2 2
3/* $eterna: daemon-bozo.c,v 1.22 2010/06/21 06:45:45 mrg Exp $ */ 3/* $eterna: daemon-bozo.c,v 1.22 2010/06/21 06:45:45 mrg Exp $ */
4 4
5/* 5/*
6 * Copyright (c) 1997-2010 Matthew R. Green 6 * Copyright (c) 1997-2010 Matthew R. Green
7 * All rights reserved. 7 * All rights reserved.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
@@ -67,27 +67,27 @@ static const char* pidfile_path = NULL; @@ -67,27 +67,27 @@ static const char* pidfile_path = NULL;
67static pid_t pidfile_pid = 0; 67static pid_t pidfile_pid = 0;
68 68
69/* ARGSUSED */ 69/* ARGSUSED */
70static void 70static void
71sigchild(int signo) 71sigchild(int signo)
72{ 72{
73 while (waitpid(-1, NULL, WNOHANG) > 0) { 73 while (waitpid(-1, NULL, WNOHANG) > 0) {
74 } 74 }
75} 75}
76 76
77/* Signal handler to exit in a controlled manner. This ensures that 77/* Signal handler to exit in a controlled manner. This ensures that
78 * any atexit(3) handlers are properly executed. */ 78 * any atexit(3) handlers are properly executed. */
79/* ARGSUSED */ 79/* ARGSUSED */
80static void 80BOZO_DEAD static void
81controlled_exit(int signo) 81controlled_exit(int signo)
82{ 82{
83 83
84 exit(EXIT_SUCCESS); 84 exit(EXIT_SUCCESS);
85} 85}
86 86
87static void 87static void
88remove_pidfile(void) 88remove_pidfile(void)
89{ 89{
90 90
91 if (pidfile_path != NULL && pidfile_pid == getpid()) { 91 if (pidfile_path != NULL && pidfile_pid == getpid()) {
92 (void)unlink(pidfile_path); 92 (void)unlink(pidfile_path);
93 pidfile_path = NULL; 93 pidfile_path = NULL;

cvs diff -r1.2 -r1.3 src/libexec/httpd/main.c (expand / switch to unified diff)

--- src/libexec/httpd/main.c 2011/03/29 07:22:31 1.2
+++ src/libexec/httpd/main.c 2011/08/27 15:33:59 1.3
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: main.c,v 1.2 2011/03/29 07:22:31 jmmv Exp $ */ 1/* $NetBSD: main.c,v 1.3 2011/08/27 15:33:59 joerg Exp $ */
2 2
3/* $eterna: main.c,v 1.4 2010/07/11 00:34:28 mrg Exp $ */ 3/* $eterna: main.c,v 1.4 2010/07/11 00:34:28 mrg Exp $ */
4/* from: eterna: bozohttpd.c,v 1.159 2009/05/23 02:14:30 mrg Exp */ 4/* from: eterna: bozohttpd.c,v 1.159 2009/05/23 02:14:30 mrg Exp */
5 5
6/* 6/*
7 * Copyright (c) 1997-2010 Matthew R. Green 7 * Copyright (c) 1997-2010 Matthew R. Green
8 * All rights reserved. 8 * All rights reserved.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -37,39 +37,35 @@ @@ -37,39 +37,35 @@
37 * main.c: C front end to bozohttpd 37 * main.c: C front end to bozohttpd
38 */ 38 */
39 39
40#include <sys/types.h> 40#include <sys/types.h>
41#include <sys/param.h> 41#include <sys/param.h>
42 42
43#include <errno.h> 43#include <errno.h>
44#include <stdlib.h> 44#include <stdlib.h>
45#include <string.h> 45#include <string.h>
46#include <syslog.h> 46#include <syslog.h>
47#include <time.h> 47#include <time.h>
48#include <unistd.h> 48#include <unistd.h>
49 49
50#ifndef __attribute__ 
51#define __attribute__(x) 
52#endif /* __attribute__ */ 
53 
54#include "bozohttpd.h" 50#include "bozohttpd.h"
55 51
56/* variables and functions */ 52/* variables and functions */
57#ifndef LOG_FTP 53#ifndef LOG_FTP
58#define LOG_FTP LOG_DAEMON 54#define LOG_FTP LOG_DAEMON
59#endif 55#endif
60 56
61/* print a usage message, and then exit */ 57/* print a usage message, and then exit */
62static void 58BOZO_DEAD static void
63usage(bozohttpd_t *httpd, char *progname) 59usage(bozohttpd_t *httpd, char *progname)
64{ 60{
65 bozo_warn(httpd, "usage: %s [options] slashdir [virtualhostname]", 61 bozo_warn(httpd, "usage: %s [options] slashdir [virtualhostname]",
66 progname); 62 progname);
67 bozo_warn(httpd, "options:"); 63 bozo_warn(httpd, "options:");
68#ifndef NO_DEBUG 64#ifndef NO_DEBUG
69 bozo_warn(httpd, " -d\t\t\tenable debug support"); 65 bozo_warn(httpd, " -d\t\t\tenable debug support");
70#endif 66#endif
71 bozo_warn(httpd, " -s\t\t\talways log to stderr"); 67 bozo_warn(httpd, " -s\t\t\talways log to stderr");
72#ifndef NO_USER_SUPPORT 68#ifndef NO_USER_SUPPORT
73 bozo_warn(httpd, " -u\t\t\tenable ~user/public_html support"); 69 bozo_warn(httpd, " -u\t\t\tenable ~user/public_html support");
74 bozo_warn(httpd, " -p dir\t\tchange `public_html' directory name]"); 70 bozo_warn(httpd, " -p dir\t\tchange `public_html' directory name]");
75#endif 71#endif

cvs diff -r1.11 -r1.12 src/libexec/httpd/ssl-bozo.c (expand / switch to unified diff)

--- src/libexec/httpd/ssl-bozo.c 2011/08/21 10:45:33 1.11
+++ src/libexec/httpd/ssl-bozo.c 2011/08/27 15:33:59 1.12
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: ssl-bozo.c,v 1.11 2011/08/21 10:45:33 hannken Exp $ */ 1/* $NetBSD: ssl-bozo.c,v 1.12 2011/08/27 15:33:59 joerg Exp $ */
2 2
3/* $eterna: ssl-bozo.c,v 1.13 2010/05/12 12:24:58 rtr Exp $ */ 3/* $eterna: ssl-bozo.c,v 1.13 2010/05/12 12:24:58 rtr Exp $ */
4 4
5/* 5/*
6 * Copyright (c) 1997-2010 Matthew R. Green 6 * Copyright (c) 1997-2010 Matthew R. Green
7 * All rights reserved. 7 * All rights reserved.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
@@ -54,27 +54,27 @@ typedef struct sslinfo_t { @@ -54,27 +54,27 @@ typedef struct sslinfo_t {
54 const SSL_METHOD *ssl_method; 54 const SSL_METHOD *ssl_method;
55 SSL *bozossl; 55 SSL *bozossl;
56 char *certificate_file; 56 char *certificate_file;
57 char *privatekey_file; 57 char *privatekey_file;
58} sslinfo_t; 58} sslinfo_t;
59 59
60/* 60/*
61 * bozo_ssl_err 61 * bozo_ssl_err
62 * 62 *
63 * bozo_ssl_err works just like bozo_err except in addition to printing 63 * bozo_ssl_err works just like bozo_err except in addition to printing
64 * the error provided by the caller at the point of error it pops and 64 * the error provided by the caller at the point of error it pops and
65 * prints all errors from the SSL error queue. 65 * prints all errors from the SSL error queue.
66 */ 66 */
67static void 67BOZO_DEAD static void
68bozo_ssl_err(bozohttpd_t *httpd, int code, const char *fmt, ...) 68bozo_ssl_err(bozohttpd_t *httpd, int code, const char *fmt, ...)
69{ 69{
70 va_list ap; 70 va_list ap;
71 71
72 va_start(ap, fmt); 72 va_start(ap, fmt);
73 if (httpd->logstderr || isatty(STDERR_FILENO)) { 73 if (httpd->logstderr || isatty(STDERR_FILENO)) {
74 vfprintf(stderr, fmt, ap); 74 vfprintf(stderr, fmt, ap);
75 fputs("\n", stderr); 75 fputs("\n", stderr);
76 } else 76 } else
77 vsyslog(LOG_ERR, fmt, ap); 77 vsyslog(LOG_ERR, fmt, ap);
78 va_end(ap); 78 va_end(ap);
79 79
80 unsigned int sslcode = ERR_get_error(); 80 unsigned int sslcode = ERR_get_error();