diff options
Diffstat (limited to 'src/vcli.c')
-rw-r--r-- | src/vcli.c | 69 |
1 files changed, 34 insertions, 35 deletions
@@ -424,33 +424,36 @@ vcli_handshake(struct vcli_conn *conn) | |||
424 | } | 424 | } |
425 | 425 | ||
426 | int | 426 | int |
427 | vcli_connect(struct VSM_data *vd, struct vcli_conn *conn) | 427 | vcli_connect(struct vsm *vsm, struct vcli_conn *conn) |
428 | { | 428 | { |
429 | struct VSM_fantom vt; | ||
430 | struct sockaddr_in vcli_sa; | 429 | struct sockaddr_in vcli_sa; |
431 | char *s, *portstr, *p; | 430 | char *portstr, *p; |
432 | unsigned long n; | 431 | unsigned long n; |
433 | short pn; | 432 | short pn; |
434 | struct hostent *hp; | 433 | struct hostent *hp; |
435 | 434 | char *T_arg = NULL, *S_arg = NULL; | |
436 | memset(conn, 0, sizeof(*conn)); | 435 | memset(conn, 0, sizeof(*conn)); |
437 | 436 | ||
438 | if (!VSM_Get(vd, &vt, "Arg", "-T", "")) { | 437 | T_arg = VSM_Dup(vsm, "Arg", "-T"); |
438 | if (!T_arg) { | ||
439 | snmp_log(LOG_ERR, "no -T arg in shared memory\n"); | 439 | snmp_log(LOG_ERR, "no -T arg in shared memory\n"); |
440 | return SNMP_ERR_GENERR; | 440 | return SNMP_ERR_GENERR; |
441 | } | 441 | } |
442 | DEBUGMSGTL(("varnish_mib:vcli", "-T '%s'\n", (char*) vt.b)); | 442 | S_arg = VSM_Dup(vsm, "Arg", "-S"); |
443 | if (!S_arg) { | ||
444 | free(T_arg); | ||
445 | snmp_log(LOG_ERR, "no -S arg in shared memory\n"); | ||
446 | return SNMP_ERR_GENERR; | ||
447 | } | ||
443 | 448 | ||
444 | s = strdup(vt.b); | 449 | DEBUGMSGTL(("varnish_mib:vcli", "-T '%s'\n", (char*) T_arg)); |
445 | if (!s) { | 450 | |
446 | snmp_log(LOG_ERR, "out of memory\n"); | 451 | for (portstr = T_arg; !ISSPACE(*portstr); portstr++) |
447 | return SNMP_ERR_GENERR; | ||
448 | } | ||
449 | for (portstr = s; !ISSPACE(*portstr); portstr++) | ||
450 | ; | 452 | ; |
451 | if (!*portstr) { | 453 | if (!*portstr) { |
452 | snmp_log(LOG_ERR, "unrecognized -T arg: %s\n", s); | 454 | snmp_log(LOG_ERR, "unrecognized -T arg: %s\n", T_arg); |
453 | free(s); | 455 | free(T_arg); |
456 | free(S_arg); | ||
454 | return SNMP_ERR_GENERR; | 457 | return SNMP_ERR_GENERR; |
455 | } | 458 | } |
456 | for (*portstr++ = 0; ISSPACE(*portstr); portstr++) | 459 | for (*portstr++ = 0; ISSPACE(*portstr); portstr++) |
@@ -458,44 +461,40 @@ vcli_connect(struct VSM_data *vd, struct vcli_conn *conn) | |||
458 | 461 | ||
459 | n = pn = strtoul(portstr, &p, 0); | 462 | n = pn = strtoul(portstr, &p, 0); |
460 | if (n != pn || (*p && !ISSPACE(*p))) { | 463 | if (n != pn || (*p && !ISSPACE(*p))) { |
461 | snmp_log(LOG_ERR, "unrecognized -T arg: %s\n", s); | 464 | snmp_log(LOG_ERR, "unrecognized -T arg: %s\n", T_arg); |
462 | free(s); | 465 | free(T_arg); |
466 | free(S_arg); | ||
463 | return SNMP_ERR_GENERR; | 467 | return SNMP_ERR_GENERR; |
464 | } | 468 | } |
465 | 469 | ||
466 | hp = gethostbyname(s); | 470 | hp = gethostbyname(T_arg); |
467 | if (!hp) { | 471 | if (!hp) { |
468 | snmp_log(LOG_ERR, "unknown host name %s\n", s); | 472 | snmp_log(LOG_ERR, "unknown host name %s\n", T_arg); |
469 | free(s); | 473 | free(T_arg); |
474 | free(S_arg); | ||
470 | return SNMP_ERR_GENERR; | 475 | return SNMP_ERR_GENERR; |
471 | } | 476 | } |
472 | 477 | ||
473 | vcli_sa.sin_family = hp->h_addrtype; | 478 | vcli_sa.sin_family = hp->h_addrtype; |
474 | if (vcli_sa.sin_family != AF_INET) { | 479 | if (vcli_sa.sin_family != AF_INET) { |
475 | snmp_log(LOG_ERR, "unknown host name %s\n", s); | 480 | snmp_log(LOG_ERR, "unknown host name %s\n", T_arg); |
476 | free(s); | 481 | free(T_arg); |
482 | free(S_arg); | ||
477 | return SNMP_ERR_GENERR; | 483 | return SNMP_ERR_GENERR; |
478 | } | 484 | } |
479 | 485 | ||
480 | memmove(&vcli_sa.sin_addr, hp->h_addr, 4); | 486 | memmove(&vcli_sa.sin_addr, hp->h_addr, 4); |
481 | vcli_sa.sin_port = htons(pn); | 487 | vcli_sa.sin_port = htons(pn); |
482 | 488 | ||
483 | conn->fd = open_socket(&vcli_sa, s); | 489 | conn->fd = open_socket(&vcli_sa, T_arg); |
484 | free(s); | 490 | free(T_arg); |
485 | if (conn->fd == -1) | 491 | if (conn->fd == -1) { |
486 | return SNMP_ERR_GENERR; | 492 | free(S_arg); |
487 | |||
488 | if (!VSM_Get(vd, &vt, "Arg", "-S", "")) { | ||
489 | snmp_log(LOG_ERR, "no -S arg in shared memory\n"); | ||
490 | return SNMP_ERR_GENERR; | ||
491 | } | ||
492 | DEBUGMSGTL(("varnish_mib:vcli", "-S '%s'\n", (char*) vt.b)); | ||
493 | s = strdup(vt.b); | ||
494 | if (!s) { | ||
495 | snmp_log(LOG_ERR, "out of memory\n"); | ||
496 | return SNMP_ERR_GENERR; | 493 | return SNMP_ERR_GENERR; |
497 | } | 494 | } |
498 | conn->secret = s; | 495 | |
496 | DEBUGMSGTL(("varnish_mib:vcli", "-S '%s'\n", S_arg)); | ||
497 | conn->secret = S_arg; | ||
499 | 498 | ||
500 | if (vcli_handshake(conn)) { | 499 | if (vcli_handshake(conn)) { |
501 | vcli_disconnect(conn); | 500 | vcli_disconnect(conn); |