summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorHenning Brauer <henning@cvs.openbsd.org>2002-07-17 11:17:01 +0000
committerHenning Brauer <henning@cvs.openbsd.org>2002-07-17 11:17:01 +0000
commitac871b980828875d530df5e10dedc81af51c1d40 (patch)
tree49147915bd3f2e9f7557d876945cbf796895c89f /usr.sbin
parentd0bca6135c72be8e31dd3c564d3d737fdd78bed3 (diff)
introduce fdcache, a simple wrapper to keep a copy of fds outside
server_conf. needed to make the mod_log_* modules survive graceful restarts. has to be used with great care, as of now only appropriate for logfiles.
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/httpd/Makefile.bsd-wrapper5
-rw-r--r--usr.sbin/httpd/src/include/fdcache.h34
-rw-r--r--usr.sbin/httpd/src/main/Makefile.tmpl3
-rw-r--r--usr.sbin/httpd/src/main/fdcache.c95
4 files changed, 134 insertions, 3 deletions
diff --git a/usr.sbin/httpd/Makefile.bsd-wrapper b/usr.sbin/httpd/Makefile.bsd-wrapper
index 016930af700..817ab7d809c 100644
--- a/usr.sbin/httpd/Makefile.bsd-wrapper
+++ b/usr.sbin/httpd/Makefile.bsd-wrapper
@@ -1,5 +1,5 @@
# Build wrapper for Apache
-# $OpenBSD: Makefile.bsd-wrapper,v 1.27 2002/07/08 00:38:32 brad Exp $
+# $OpenBSD: Makefile.bsd-wrapper,v 1.28 2002/07/17 11:17:00 henning Exp $
# Our lndir is hacked; specify a full path to avoid potential conflicts
# with the one installed with X11.
@@ -198,7 +198,8 @@ INCFILES= \
src/include/util_script.h \
src/os/unix/os-inline.c \
src/os/unix/os.h \
- src/include/util_uri.h
+ src/include/util_uri.h \
+ src/include/fdcache.h
XMLFILES= \
src/lib/expat-lite/asciitab.h \
diff --git a/usr.sbin/httpd/src/include/fdcache.h b/usr.sbin/httpd/src/include/fdcache.h
new file mode 100644
index 00000000000..597bde12216
--- /dev/null
+++ b/usr.sbin/httpd/src/include/fdcache.h
@@ -0,0 +1,34 @@
+/* $OpenBSD: fdcache.h,v 1.1 2002/07/17 11:17:00 henning Exp $ */
+
+/*
+ * Copyright (c) 2002 Henning Brauer
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+int fdcache_open(char *, int, mode_t);
+void fdcache_closeall();
diff --git a/usr.sbin/httpd/src/main/Makefile.tmpl b/usr.sbin/httpd/src/main/Makefile.tmpl
index 531dea66f74..f58dad0c9ce 100644
--- a/usr.sbin/httpd/src/main/Makefile.tmpl
+++ b/usr.sbin/httpd/src/main/Makefile.tmpl
@@ -11,7 +11,7 @@ OBJS= alloc.o buff.o \
http_config.o http_core.o http_log.o \
http_main.o http_protocol.o http_request.o http_vhost.o \
util.o util_date.o util_script.o util_uri.o util_md5.o \
- rfc1413.o
+ rfc1413.o fdcache.o
.c.o:
$(CC) -c $(INCLUDES) $(CFLAGS) $<
@@ -163,3 +163,4 @@ util_uri.o: util_uri.c $(INCDIR)/httpd.h $(INCDIR)/ap_config.h \
$(INCDIR)/ap_ctype.h $(INCDIR)/hsregex.h $(INCDIR)/ap_alloc.h \
$(INCDIR)/buff.h $(INCDIR)/ap.h $(INCDIR)/util_uri.h \
$(INCDIR)/http_log.h $(INCDIR)/http_conf_globals.h uri_delims.h
+fdcache.o: fdcache.c
diff --git a/usr.sbin/httpd/src/main/fdcache.c b/usr.sbin/httpd/src/main/fdcache.c
new file mode 100644
index 00000000000..d9807b2c346
--- /dev/null
+++ b/usr.sbin/httpd/src/main/fdcache.c
@@ -0,0 +1,95 @@
+/* $OpenBSD: fdcache.c,v 1.1 2002/07/17 11:17:00 henning Exp $ */
+
+/*
+ * Copyright (c) 2002 Henning Brauer
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+
+struct fdcache {
+ char *fname;
+ int fd;
+ struct fdcache *next;
+};
+
+struct fdcache *fdc;
+
+int
+fdcache_open(char *fn, int flags, mode_t mode)
+{
+ struct fdcache *fdcp = NULL, *tmp = NULL;
+
+ for(fdcp = fdc; fdcp && strncmp(fn, fdcp->fname, 1024);
+ fdcp = fdcp->next);
+ /* nothing */
+
+ if (fdcp == NULL)
+ {
+ /* need to open */
+ tmp = calloc(1, sizeof(struct fdcache));
+ if (tmp == NULL) {
+ fprintf(stderr, "calloc failed\n");
+ exit(1);
+ }
+ tmp->fname = malloc(strlen(fn) + 1);
+ if (tmp->fname == NULL) {
+ fprintf(stderr, "malloc failed\n");
+ exit(1);
+ }
+ strlcpy(tmp->fname, fn, strlen(fn) + 1);
+ if ((tmp->fd = open(fn, flags, mode)) < 0) {
+ fprintf(stderr, "Cannot open %s: %s\n",
+ tmp->fname, strerror(errno));
+ exit(1);
+ }
+ tmp->next = fdc;
+ fdc = tmp;
+ return(fdc->fd);
+ } else
+ return(fdcp->fd); /* fd cached */
+}
+
+void
+fdcache_closeall()
+{
+ struct fdcache *fdcp = NULL;
+
+ for(fdcp = fdc; fdcp; fdcp = fdcp->next)
+ {
+ if (fdcp->fd > 0)
+ close(fdcp->fd);
+ free(fdcp->fname);
+ }
+ if (fdc != NULL)
+ free(fdc);
+}
+