summaryrefslogtreecommitdiffabout
path: root/src/vcli.c
Side-by-side diff
Diffstat (limited to 'src/vcli.c') (more/less context) (ignore whitespace changes)
-rw-r--r--src/vcli.c69
1 files changed, 34 insertions, 35 deletions
diff --git a/src/vcli.c b/src/vcli.c
index c204cf3..499c365 100644
--- a/src/vcli.c
+++ b/src/vcli.c
@@ -424,33 +424,36 @@ vcli_handshake(struct vcli_conn *conn)
}
int
-vcli_connect(struct VSM_data *vd, struct vcli_conn *conn)
+vcli_connect(struct vsm *vsm, struct vcli_conn *conn)
{
- struct VSM_fantom vt;
struct sockaddr_in vcli_sa;
- char *s, *portstr, *p;
+ char *portstr, *p;
unsigned long n;
short pn;
struct hostent *hp;
-
+ char *T_arg = NULL, *S_arg = NULL;
memset(conn, 0, sizeof(*conn));
- if (!VSM_Get(vd, &vt, "Arg", "-T", "")) {
+ T_arg = VSM_Dup(vsm, "Arg", "-T");
+ if (!T_arg) {
snmp_log(LOG_ERR, "no -T arg in shared memory\n");
return SNMP_ERR_GENERR;
}
- DEBUGMSGTL(("varnish_mib:vcli", "-T '%s'\n", (char*) vt.b));
+ S_arg = VSM_Dup(vsm, "Arg", "-S");
+ if (!S_arg) {
+ free(T_arg);
+ snmp_log(LOG_ERR, "no -S arg in shared memory\n");
+ return SNMP_ERR_GENERR;
+ }
- s = strdup(vt.b);
- if (!s) {
- snmp_log(LOG_ERR, "out of memory\n");
- return SNMP_ERR_GENERR;
- }
- for (portstr = s; !ISSPACE(*portstr); portstr++)
+ DEBUGMSGTL(("varnish_mib:vcli", "-T '%s'\n", (char*) T_arg));
+
+ for (portstr = T_arg; !ISSPACE(*portstr); portstr++)
;
if (!*portstr) {
- snmp_log(LOG_ERR, "unrecognized -T arg: %s\n", s);
- free(s);
+ snmp_log(LOG_ERR, "unrecognized -T arg: %s\n", T_arg);
+ free(T_arg);
+ free(S_arg);
return SNMP_ERR_GENERR;
}
for (*portstr++ = 0; ISSPACE(*portstr); portstr++)
@@ -458,44 +461,40 @@ vcli_connect(struct VSM_data *vd, struct vcli_conn *conn)
n = pn = strtoul(portstr, &p, 0);
if (n != pn || (*p && !ISSPACE(*p))) {
- snmp_log(LOG_ERR, "unrecognized -T arg: %s\n", s);
- free(s);
+ snmp_log(LOG_ERR, "unrecognized -T arg: %s\n", T_arg);
+ free(T_arg);
+ free(S_arg);
return SNMP_ERR_GENERR;
}
- hp = gethostbyname(s);
+ hp = gethostbyname(T_arg);
if (!hp) {
- snmp_log(LOG_ERR, "unknown host name %s\n", s);
- free(s);
+ snmp_log(LOG_ERR, "unknown host name %s\n", T_arg);
+ free(T_arg);
+ free(S_arg);
return SNMP_ERR_GENERR;
}
vcli_sa.sin_family = hp->h_addrtype;
if (vcli_sa.sin_family != AF_INET) {
- snmp_log(LOG_ERR, "unknown host name %s\n", s);
- free(s);
+ snmp_log(LOG_ERR, "unknown host name %s\n", T_arg);
+ free(T_arg);
+ free(S_arg);
return SNMP_ERR_GENERR;
}
memmove(&vcli_sa.sin_addr, hp->h_addr, 4);
vcli_sa.sin_port = htons(pn);
- conn->fd = open_socket(&vcli_sa, s);
- free(s);
- if (conn->fd == -1)
- return SNMP_ERR_GENERR;
-
- if (!VSM_Get(vd, &vt, "Arg", "-S", "")) {
- snmp_log(LOG_ERR, "no -S arg in shared memory\n");
- return SNMP_ERR_GENERR;
- }
- DEBUGMSGTL(("varnish_mib:vcli", "-S '%s'\n", (char*) vt.b));
- s = strdup(vt.b);
- if (!s) {
- snmp_log(LOG_ERR, "out of memory\n");
+ conn->fd = open_socket(&vcli_sa, T_arg);
+ free(T_arg);
+ if (conn->fd == -1) {
+ free(S_arg);
return SNMP_ERR_GENERR;
}
- conn->secret = s;
+
+ DEBUGMSGTL(("varnish_mib:vcli", "-S '%s'\n", S_arg));
+ conn->secret = S_arg;
if (vcli_handshake(conn)) {
vcli_disconnect(conn);

Return to:

Send suggestions and report system problems to the System administrator.