r1581 - in trunk/varnish-cache: . bin/varnishd include lib/libvarnishapi
des at projects.linpro.no
des at projects.linpro.no
Tue Jun 26 13:52:25 CEST 2007
Author: des
Date: 2007-06-26 13:52:25 +0200 (Tue, 26 Jun 2007)
New Revision: 1581
Added:
trunk/varnish-cache/bin/varnishd/instance.c
trunk/varnish-cache/lib/libvarnishapi/instance.c
Modified:
trunk/varnish-cache/INSTALL
trunk/varnish-cache/bin/varnishd/Makefile.am
trunk/varnish-cache/bin/varnishd/heritage.h
trunk/varnish-cache/bin/varnishd/mgt_child.c
trunk/varnish-cache/bin/varnishd/varnishd.1
trunk/varnish-cache/bin/varnishd/varnishd.c
trunk/varnish-cache/configure.ac
trunk/varnish-cache/include/varnishapi.h
trunk/varnish-cache/lib/libvarnishapi/Makefile.am
trunk/varnish-cache/lib/libvarnishapi/shmlog.c
Log:
Further refine -n handling. The argument to -n is now either an absolute
path, or a path relative to $localstatedir/varnish. By default, it is set
to the host name, which results in $localstatedir/varnish/$hostname.
This logic is centralized in instance.c, which is compiled into both
varnishd and libvarnishapi, with prototypes in varnishapi.h and heritage.h.
Modified: trunk/varnish-cache/INSTALL
===================================================================
--- trunk/varnish-cache/INSTALL 2007-06-26 11:42:30 UTC (rev 1580)
+++ trunk/varnish-cache/INSTALL 2007-06-26 11:52:25 UTC (rev 1581)
@@ -5,10 +5,13 @@
and 'make install'.
If you obtained the sources directly from the Subversion repository,
-you will need to run autogen.sh first to create the 'configure' script.
+you will need to run autogen.sh first to create the configure script.
-Additional 'configure' options of interest:
+Varnish will store run-time state in $localstatedir/varnish; you may
+want to tune this using configure's --localstatedir parameter.
+Additional configure options of interest:
+
--enable-developer-warnings
enable strict warnings (default is NO)
--enable-debugging-symbols
Modified: trunk/varnish-cache/bin/varnishd/Makefile.am
===================================================================
--- trunk/varnish-cache/bin/varnishd/Makefile.am 2007-06-26 11:42:30 UTC (rev 1580)
+++ trunk/varnish-cache/bin/varnishd/Makefile.am 2007-06-26 11:52:25 UTC (rev 1581)
@@ -34,6 +34,7 @@
cache_ws.c \
hash_simple_list.c \
hash_classic.c \
+ instance.c \
mgt_child.c \
mgt_cli.c \
mgt_event.c \
Modified: trunk/varnish-cache/bin/varnishd/heritage.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/heritage.h 2007-06-26 11:42:30 UTC (rev 1580)
+++ trunk/varnish-cache/bin/varnishd/heritage.h 2007-06-26 11:52:25 UTC (rev 1581)
@@ -63,7 +63,7 @@
/* Hash method */
struct hash_slinger *hash;
- const char *n_arg;
+ char name[1024];
};
struct params {
@@ -128,3 +128,5 @@
extern struct heritage heritage;
void child_main(void);
+
+int varnish_instance(const char *n_arg, char *name, size_t namelen, char *dir, size_t dirlen);
Added: trunk/varnish-cache/bin/varnishd/instance.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/instance.c (rev 0)
+++ trunk/varnish-cache/bin/varnishd/instance.c 2007-06-26 11:52:25 UTC (rev 1581)
@@ -0,0 +1 @@
+link ../../lib/libvarnishapi/instance.c
\ No newline at end of file
Property changes on: trunk/varnish-cache/bin/varnishd/instance.c
___________________________________________________________________
Name: svn:special
+ *
Modified: trunk/varnish-cache/bin/varnishd/mgt_child.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/mgt_child.c 2007-06-26 11:42:30 UTC (rev 1580)
+++ trunk/varnish-cache/bin/varnishd/mgt_child.c 2007-06-26 11:52:25 UTC (rev 1581)
@@ -204,7 +204,7 @@
AZ(close(heritage.fds[0]));
AZ(close(heritage.fds[3]));
- setproctitle("Varnish-Chld %s", heritage.n_arg);
+ setproctitle("Varnish-Chld %s", heritage.name);
signal(SIGINT, SIG_DFL);
signal(SIGTERM, SIG_DFL);
@@ -408,7 +408,7 @@
e->name = "mgt_sigchild";
AZ(ev_add(mgt_evb, e));
- setproctitle("Varnish-Mgr %s", heritage.n_arg);
+ setproctitle("Varnish-Mgr %s", heritage.name);
sac.sa_handler = SIG_IGN;
sac.sa_flags = SA_RESTART;
Modified: trunk/varnish-cache/bin/varnishd/varnishd.1
===================================================================
--- trunk/varnish-cache/bin/varnishd/varnishd.1 2007-06-26 11:42:30 UTC (rev 1580)
+++ trunk/varnish-cache/bin/varnishd/varnishd.1 2007-06-26 11:52:25 UTC (rev 1581)
@@ -28,7 +28,7 @@
.\"
.\" $Id$
.\"
-.Dd June 15, 2007
+.Dd June 26, 2007
.Dt VARNISHD 1
.Os
.Sh NAME
@@ -130,9 +130,13 @@
for a list of supported algorithms.
.It Fl n
Specify a name for this instance.
-This is a shortcut for specifying the
-.Va name
-run-time parameter.
+Amonst other things, this name is used to construct the name of the
+directory in which
+.Nm
+keeps temporary files and persistent state.
+If the specified name begins with a forward slash, it is interpreted
+as the absolute path to the directory which should be used for this
+purpose.
.It Fl P Ar file
Write the process's PID to the specified
.Ar file .
@@ -402,14 +406,6 @@
The depth of the TCP listen queue.
.Pp
The default is 512.
-.It Va name
-The name of this
-.Nm
-instance.
-All temporary files are stored in
-.Pa /tmp/ Ns Va name .
-.Pp
-The default is the hostname.
.It Va overflow_max
The maximum depth of the overflow queue as a percentage of
.Va thread_pool_max .
Modified: trunk/varnish-cache/bin/varnishd/varnishd.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/varnishd.c 2007-06-26 11:42:30 UTC (rev 1580)
+++ trunk/varnish-cache/bin/varnishd/varnishd.c 2007-06-26 11:52:25 UTC (rev 1581)
@@ -50,6 +50,10 @@
#include "compat/daemon.h"
#endif
+#ifndef HAVE_STRLCPY
+#include "compat/strlcpy.h"
+#endif
+
#include "vsb.h"
#include "vpf.h"
@@ -409,13 +413,14 @@
const char *f_arg = NULL;
int f_fd = -1;
const char *h_arg = "classic";
- const char *n_arg = "/tmp";
+ const char *n_arg = NULL;
const char *P_arg = NULL;
const char *s_arg = "file";
const char *T_arg = NULL;
char *p;
struct cli cli[1];
struct pidfh *pfh = NULL;
+ char dirname[1024];
setbuf(stdout, NULL);
setbuf(stderr, NULL);
@@ -524,7 +529,7 @@
fprintf(stderr, "One of -b or -f must be specified\n");
usage();
}
-
+
if (f_arg != NULL) {
f_fd = open(f_arg, O_RDONLY);
if (f_fd < 0) {
@@ -534,20 +539,25 @@
}
}
- if (mkdir(n_arg, 0755) < 0 && errno != EEXIST) {
+ if (varnish_instance(n_arg, heritage.name, sizeof heritage.name,
+ dirname, sizeof dirname) != 0) {
+ fprintf(stderr, "Invalid instance name: %s\n",
+ strerror(errno));
+ exit(1);
+ }
+
+ if (mkdir(dirname, 0755) < 0 && errno != EEXIST) {
fprintf(stderr, "Cannot create working directory '%s': %s\n",
- n_arg, strerror(errno));
+ dirname, strerror(errno));
exit(1);
}
- if (chdir(n_arg) < 0) {
+ if (chdir(dirname) < 0) {
fprintf(stderr, "Cannot change to working directory '%s': %s\n",
- n_arg, strerror(errno));
+ dirname, strerror(errno));
exit(1);
}
- heritage.n_arg = n_arg;
-
/* XXX: should this be relative to the -n arg ? */
if (P_arg && (pfh = vpf_open(P_arg, 0600, NULL)) == NULL) {
perror(P_arg);
Modified: trunk/varnish-cache/configure.ac
===================================================================
--- trunk/varnish-cache/configure.ac 2007-06-26 11:42:30 UTC (rev 1580)
+++ trunk/varnish-cache/configure.ac 2007-06-26 11:52:25 UTC (rev 1581)
@@ -102,6 +102,11 @@
AC_CHECK_FUNCS([epoll_ctl])
AC_CHECK_FUNCS([poll])
+# Run-time directory
+VARNISH_STATE_DIR=`eval "echo $localstatedir/varnish"`
+AC_DEFINE_UNQUOTED(VARNISH_STATE_DIR, "$VARNISH_STATE_DIR",
+ [Base directory for run-time state])
+
# Now that we're done using the compiler to look for functions and
# libraries, set CFLAGS to what we want them to be for our own code
Modified: trunk/varnish-cache/include/varnishapi.h
===================================================================
--- trunk/varnish-cache/include/varnishapi.h 2007-06-26 11:42:30 UTC (rev 1580)
+++ trunk/varnish-cache/include/varnishapi.h 2007-06-26 11:52:25 UTC (rev 1581)
@@ -58,21 +58,7 @@
struct varnish_stats *VSL_OpenStats(const char *varnish_name);
extern const char *VSL_tags[256];
-/* varnish_debug.c */
-void vdb_panic(const char *, ...) V_DEAD;
+/* instance.c */
+int varnish_instance(const char *n_arg, char *name, size_t namelen, char *dir, size_t dirlen);
-/* varnish_log.c */
-typedef struct vlo_buffer vlo_buffer_t;
-vlo_buffer_t *vlo_open(const char *, size_t, int);
-ssize_t vlo_write(vlo_buffer_t *, const void *, size_t);
-vlo_buffer_t *vlo_attach(const char *);
-ssize_t vlo_read(vlo_buffer_t *, const void *, size_t);
-#if 0
-uuid_t vlo_get_uuid(vlo_buffer_t *);
#endif
-int vlo_close(vlo_buffer_t *);
-
-/* varnish_util.c */
-int vut_open_lock(const char *, int, int, int);
-
-#endif
Modified: trunk/varnish-cache/lib/libvarnishapi/Makefile.am
===================================================================
--- trunk/varnish-cache/lib/libvarnishapi/Makefile.am 2007-06-26 11:42:30 UTC (rev 1580)
+++ trunk/varnish-cache/lib/libvarnishapi/Makefile.am 2007-06-26 11:52:25 UTC (rev 1581)
@@ -6,6 +6,7 @@
libvarnishapi_la_SOURCES = \
base64.c \
+ instance.c \
shmlog.c
libvarnishapi_la_CFLAGS = -include config.h
Added: trunk/varnish-cache/lib/libvarnishapi/instance.c
===================================================================
--- trunk/varnish-cache/lib/libvarnishapi/instance.c (rev 0)
+++ trunk/varnish-cache/lib/libvarnishapi/instance.c 2007-06-26 11:52:25 UTC (rev 1581)
@@ -0,0 +1,65 @@
+/*-
+ * Copyright (c) 2007 Linpro AS
+ * All rights reserved.
+ *
+ * Author: Dag-Erling Smørgrav <des at linpro.no>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. 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 AUTHOR 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 AUTHOR 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.
+ *
+ * $Id$
+ */
+
+#include <errno.h>
+#include <stdio.h>
+#include <unistd.h>
+
+#include "varnishapi.h"
+
+int
+varnish_instance(const char *n_arg,
+ char *name, size_t namelen,
+ char *dir, size_t dirlen)
+{
+ size_t len;
+
+ if (n_arg == NULL) {
+ if (gethostname(name, namelen) != 0)
+ return (-1);
+ } else {
+ len = snprintf(name, namelen, "%s", n_arg);
+ if (len >= namelen) {
+ errno = ENAMETOOLONG;
+ return (-1);
+ }
+ }
+
+ if (*name == '/')
+ len = snprintf(dir, dirlen, "%s", name);
+ else
+ len = snprintf(dir, dirlen, "%s/%s", VARNISH_STATE_DIR, name);
+
+ if (len >= dirlen) {
+ errno = ENAMETOOLONG;
+ return (-1);
+ }
+ return (0);
+}
Property changes on: trunk/varnish-cache/lib/libvarnishapi/instance.c
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: trunk/varnish-cache/lib/libvarnishapi/shmlog.c
===================================================================
--- trunk/varnish-cache/lib/libvarnishapi/shmlog.c 2007-06-26 11:42:30 UTC (rev 1580)
+++ trunk/varnish-cache/lib/libvarnishapi/shmlog.c 2007-06-26 11:52:25 UTC (rev 1581)
@@ -29,16 +29,18 @@
* $Id$
*/
+#include <sys/mman.h>
+
+#include <assert.h>
+#include <ctype.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <regex.h>
#include <stdio.h>
-#include <errno.h>
-#include <ctype.h>
+#include <stdlib.h>
#include <string.h>
-#include <stdlib.h>
#include <unistd.h>
-#include <fcntl.h>
-#include <regex.h>
-#include <sys/mman.h>
-#include <assert.h>
#include "shmlog.h"
#include "miniobj.h"
@@ -106,28 +108,36 @@
{
int i;
struct shmloghead slh;
- char buf[BUFSIZ];
+ char name[PATH_MAX], dirname[PATH_MAX], logname[PATH_MAX];
if (vsl_lh != NULL)
return (0);
- sprintf(buf, "/tmp/%s/%s", varnish_name, SHMLOG_FILENAME);
+ if (varnish_instance(varnish_name, name,
+ sizeof name, dirname, sizeof dirname) != 0) {
+ fprintf(stderr, "Invalid instance name: %s\n",
+ strerror(errno));
+ return (1);
+ }
- vsl_fd = open(buf, O_RDONLY);
+ /* XXX check overflow */
+ snprintf(logname, sizeof logname, "%s/%s", dirname, SHMLOG_FILENAME);
+
+ vsl_fd = open(logname, O_RDONLY);
if (vsl_fd < 0) {
fprintf(stderr, "Cannot open %s: %s\n",
- buf, strerror(errno));
+ logname, strerror(errno));
return (1);
}
i = read(vsl_fd, &slh, sizeof slh);
if (i != sizeof slh) {
fprintf(stderr, "Cannot read %s: %s\n",
- buf, strerror(errno));
+ logname, strerror(errno));
return (1);
}
if (slh.magic != SHMLOGHEAD_MAGIC) {
fprintf(stderr, "Wrong magic number in file %s\n",
- buf);
+ logname);
return (1);
}
@@ -135,7 +145,7 @@
PROT_READ, MAP_SHARED|MAP_HASSEMAPHORE, vsl_fd, 0);
if (vsl_lh == MAP_FAILED) {
fprintf(stderr, "Cannot mmap %s: %s\n",
- buf, strerror(errno));
+ logname, strerror(errno));
return (1);
}
return (0);
@@ -172,17 +182,12 @@
int
VSL_OpenLog(struct VSL_data *vd, const char *varnish_name)
{
- char hostname[1024];
unsigned char *p;
CHECK_OBJ_NOTNULL(vd, VSL_MAGIC);
if (vd->fi != NULL)
return (0);
- if (varnish_name == NULL) {
- gethostname(hostname, sizeof hostname);
- varnish_name = hostname;
- }
if (vsl_shmem_map(varnish_name))
return (-1);
More information about the varnish-commit
mailing list