[PATCH 1/2] Stop varnishd from segfaulting if no non-transient storage backends has been defined. Print error message and exit instead.
Martin Blix Grydeland
martin at varnish-software.com
Tue Jul 24 14:44:51 CEST 2012
Fixes: #1176
---
bin/varnishd/mgt/mgt.h | 2 +-
bin/varnishd/mgt/mgt_main.c | 11 ++++++++---
bin/varnishd/storage/stevedore_mgt.c | 16 ++++++++++++++--
3 files changed, 23 insertions(+), 6 deletions(-)
diff --git a/bin/varnishd/mgt/mgt.h b/bin/varnishd/mgt/mgt.h
index 512c6dc..c0f0f96 100644
--- a/bin/varnishd/mgt/mgt.h
+++ b/bin/varnishd/mgt/mgt.h
@@ -93,7 +93,7 @@ void mgt_SHM_Size_Adjust(void);
/* stevedore_mgt.c */
-void STV_Config(const char *spec);
+int STV_Config(const char *spec);
void STV_Config_Transient(void);
/* mgt_vcc.c */
diff --git a/bin/varnishd/mgt/mgt_main.c b/bin/varnishd/mgt/mgt_main.c
index 7b42437..1bb20c5 100644
--- a/bin/varnishd/mgt/mgt_main.c
+++ b/bin/varnishd/mgt/mgt_main.c
@@ -321,7 +321,7 @@ main(int argc, char * const *argv)
const char *P_arg = NULL;
const char *S_arg = NULL;
const char *s_arg = "file";
- int s_arg_given = 0;
+ int s_arg_given = 0, stv_count = 0;
const char *T_arg = NULL;
char *p, *vcl = NULL;
struct cli cli[1];
@@ -473,7 +473,7 @@ main(int argc, char * const *argv)
break;
case 's':
s_arg_given = 1;
- STV_Config(optarg);
+ stv_count = STV_Config(optarg);
break;
case 't':
MCF_ParamSet(cli, "default_ttl", optarg);
@@ -610,7 +610,12 @@ main(int argc, char * const *argv)
/* If no -s argument specified, process default -s argument */
if (!s_arg_given)
- STV_Config(s_arg);
+ stv_count = STV_Config(s_arg);
+ if (!stv_count) {
+ fprintf(stderr, "At least one non-transient storage backend "
+ "must be configured\n");
+ exit(1);
+ }
/* Configure Transient storage, if user did not */
STV_Config_Transient();
diff --git a/bin/varnishd/storage/stevedore_mgt.c b/bin/varnishd/storage/stevedore_mgt.c
index 4251839..6ab2e8e 100644
--- a/bin/varnishd/storage/stevedore_mgt.c
+++ b/bin/varnishd/storage/stevedore_mgt.c
@@ -88,14 +88,21 @@ static const struct choice STV_choice[] = {
{ NULL, NULL }
};
-void
+/*--------------------------------------------------------------------
+ * Configure a stevedore by parsing 'spec'. Will exit() on error.
+ *
+ * Return value: Number of configured stevedores (not counting
+ * transient)
+ */
+
+int
STV_Config(const char *spec)
{
char **av;
const char *p, *q;
struct stevedore *stv;
const struct stevedore *stv2;
- int ac, l;
+ int ac, l, count;
static unsigned seq = 0;
ASSERT_MGT();
@@ -145,7 +152,9 @@ STV_Config(const char *spec)
bprintf(stv->ident, "%.*s", l, spec);
}
+ count = 0;
VTAILQ_FOREACH(stv2, &stv_stevedores, list) {
+ count++;
if (strcmp(stv2->ident, stv->ident))
continue;
ARGV_ERR("(-s%s=%s) already defined once\n",
@@ -163,7 +172,10 @@ STV_Config(const char *spec)
stv_transient = stv;
} else {
VTAILQ_INSERT_TAIL(&stv_stevedores, stv, list);
+ count++;
}
+
+ return (count);
}
/*--------------------------------------------------------------------*/
--
1.7.9.5
More information about the varnish-dev
mailing list