[master] 0f32c87 Make VSM_Name() return the -i argument to varnishd.
Poul-Henning Kamp
phk at FreeBSD.org
Tue Jun 6 12:38:06 CEST 2017
commit 0f32c873b2b77ab910072976925631ab7040305f
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Tue Jun 6 10:36:44 2017 +0000
Make VSM_Name() return the -i argument to varnishd.
diff --git a/bin/varnishd/mgt/mgt_main.c b/bin/varnishd/mgt/mgt_main.c
index 3918608..df1fbda 100644
--- a/bin/varnishd/mgt/mgt_main.c
+++ b/bin/varnishd/mgt/mgt_main.c
@@ -743,9 +743,8 @@ main(int argc, char * const *argv)
VJ_master(JAIL_MASTER_LOW);
}
- if (VIN_n_Arg(n_arg, &p, &dirname) != 0)
+ if (VIN_n_Arg(n_arg, &dirname) != 0)
ARGV_ERR("Invalid instance (-n) name: %s\n", strerror(errno));
- free(p);
if (i_arg == NULL || *i_arg == '\0')
i_arg = "varnishd";
diff --git a/include/vapi/vsm.h b/include/vapi/vsm.h
index 52d8167..0739c96 100644
--- a/include/vapi/vsm.h
+++ b/include/vapi/vsm.h
@@ -100,7 +100,7 @@ int VSM_n_Arg(struct VSM_data *vd, const char *n_arg);
const char *VSM_Name(const struct VSM_data *vd);
/*
- * Return the instance name.
+ * Return the instance name (-i argument to varnishd)
*/
int VSM_Open(struct VSM_data *vd);
diff --git a/include/vin.h b/include/vin.h
index e0fe073..c594980 100644
--- a/include/vin.h
+++ b/include/vin.h
@@ -32,5 +32,5 @@
#define VIN_H_INCLUDED
/* This function lives in both libvarnish and libvarnishapi */
-int VIN_n_Arg(const char *n_arg, char **name, char **dir);
+int VIN_n_Arg(const char *n_arg, char **dir);
#endif
diff --git a/lib/libvarnish/vin.c b/lib/libvarnish/vin.c
index fecc554..78ab952 100644
--- a/lib/libvarnish/vin.c
+++ b/lib/libvarnish/vin.c
@@ -44,7 +44,7 @@
#include "vin.h"
int
-VIN_n_Arg(const char *n_arg, char **name, char **dir)
+VIN_n_Arg(const char *n_arg, char **dir)
{
char nm[PATH_MAX];
char dn[PATH_MAX];
@@ -83,18 +83,10 @@ VIN_n_Arg(const char *n_arg, char **name, char **dir)
strcat(dn, "/");
- if (name != NULL) {
- *name = strdup(nm);
- if (*name == NULL)
- return (-1);
- }
if (dir != NULL) {
*dir = strdup(dn);
- if (*dir == NULL) {
- if (name != NULL)
- free(*name);
+ if (*dir == NULL)
return (-1);
- }
}
return (0);
}
diff --git a/lib/libvarnishapi/vsm.c b/lib/libvarnishapi/vsm.c
index 83bab97..35551d4 100644
--- a/lib/libvarnishapi/vsm.c
+++ b/lib/libvarnishapi/vsm.c
@@ -70,7 +70,6 @@ VSM_New(void)
if (vd == NULL)
return (vd);
- REPLACE(vd->name, "");
vd->vsm_fd = -1;
CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
@@ -129,7 +128,6 @@ VSM_ResetError(struct VSM_data *vd)
int
VSM_n_Arg(struct VSM_data *vd, const char *arg)
{
- char *name = NULL;
char *dname = NULL;
struct vsb *vsb;
@@ -137,22 +135,19 @@ VSM_n_Arg(struct VSM_data *vd, const char *arg)
if (vd->head)
return (vsm_diag(vd, "VSM_n_Arg: Already open"));
- if (VIN_n_Arg(arg, &name, &dname))
+ if (VIN_n_Arg(arg, &dname))
return (vsm_diag(vd, "Invalid instance name: %s",
strerror(errno)));
- AN(name);
AN(dname);
vsb = VSB_new_auto();
AN(vsb);
VSB_printf(vsb, "%s%s", dname, VSM_FILENAME);
AZ(VSB_finish(vsb));
- REPLACE(vd->name, name);
REPLACE(vd->dname, dname);
REPLACE(vd->iname, VSB_data(vsb));
VSB_destroy(&vsb);
- free(name);
free(dname);
return (1);
@@ -163,10 +158,12 @@ VSM_n_Arg(struct VSM_data *vd, const char *arg)
const char *
VSM_Name(const struct VSM_data *vd)
{
+ struct VSM_fantom vt;
CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
-
- return (vd->name);
+ if (VSM_Get(vd, &vt, "Arg", "-i", ""))
+ return (vt.b);
+ return ("");
}
/*--------------------------------------------------------------------*/
@@ -181,7 +178,6 @@ VSM_Delete(struct VSM_data *vd)
if (vd->vsc != NULL)
VSC_Delete(vd);
VSM_ResetError(vd);
- free(vd->name);
free(vd->dname);
FREE_OBJ(vd);
}
diff --git a/lib/libvarnishapi/vsm_api.h b/lib/libvarnishapi/vsm_api.h
index e357a8f..e9402b0 100644
--- a/lib/libvarnishapi/vsm_api.h
+++ b/lib/libvarnishapi/vsm_api.h
@@ -37,7 +37,6 @@ struct VSM_data {
struct vsb *diag;
- char *name;
char *dname;
char *iname;
More information about the varnish-commit
mailing list