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)
cache_ws.c \
hash_simple_list.c \
hash_classic.c \
+ instance.c \
mgt_child.c \
mgt_cli.c \
mgt_event.c \
/* Hash method */
struct hash_slinger *hash;
- const char *n_arg;
+ char name[1024];
};
struct params {
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);
--- /dev/null
+../../lib/libvarnishapi/instance.c
\ No newline at end of file
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);
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;
.\"
.\" $Id$
.\"
-.Dd June 15, 2007
+.Dd June 26, 2007
.Dt VARNISHD 1
.Os
.Sh NAME
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 .
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 .
#include "compat/daemon.h"
#endif
+#ifndef HAVE_STRLCPY
+#include "compat/strlcpy.h"
+#endif
+
#include "vsb.h"
#include "vpf.h"
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);
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) {
}
}
- 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);
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
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;
-
-/* 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);
+/* instance.c */
+int varnish_instance(const char *n_arg, char *name, size_t namelen, char *dir, size_t dirlen);
#endif
libvarnishapi_la_SOURCES = \
base64.c \
+ instance.c \
shmlog.c
libvarnishapi_la_CFLAGS = -include config.h
--- /dev/null
+/*-
+ * Copyright (c) 2007 Linpro AS
+ * All rights reserved.
+ *
+ * Author: Dag-Erling Smørgrav <des@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);
+}
* $Id$
*/
-#include <stdio.h>
-#include <errno.h>
+#include <sys/mman.h>
+
+#include <assert.h>
#include <ctype.h>
-#include <string.h>
-#include <stdlib.h>
-#include <unistd.h>
+#include <errno.h>
#include <fcntl.h>
+#include <limits.h>
#include <regex.h>
-#include <sys/mman.h>
-#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
#include "shmlog.h"
#include "miniobj.h"
{
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);
}
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);
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);