Skip to content

Commit

Permalink
Merge pull request networkupstools#49 from bstepankova/FTY
Browse files Browse the repository at this point in the history
Problem: snmp-ups segfaults
  • Loading branch information
jimklimov authored Feb 20, 2018
2 parents d04fe4c + 09b286e commit 2dc9ff5
Showing 1 changed file with 27 additions and 18 deletions.
45 changes: 27 additions & 18 deletions drivers/snmp-ups.c
Original file line number Diff line number Diff line change
Expand Up @@ -561,18 +561,18 @@ void upsdrv_initups(void)
dstate_addcmd("shutdown.return");
dstate_addcmd("shutdown.stayoff");
}
/* Publish sysContact and sysLocation for all subdrivers */
/* sysContact.0 */
if (nut_snmp_get_str(".1.3.6.1.2.1.1.4.0", model, sizeof(model), NULL) == TRUE)
dstate_setinfo("device.contact", "%s", model);
else
upsdebugx(2, "Can't get and publish sysContact for device.contact");
/* sysLocation.0 */
if (nut_snmp_get_str(".1.3.6.1.2.1.1.6.0", model, sizeof(model), NULL) == TRUE)
dstate_setinfo("device.location", "%s", model);
else
upsdebugx(2, "Can't get and publish sysLocation for device.location");
/* Publish sysContact and sysLocation for all subdrivers */
/* sysContact.0 */
if (nut_snmp_get_str(".1.3.6.1.2.1.1.4.0", model, sizeof(model), NULL) == TRUE)
dstate_setinfo("device.contact", "%s", model);
else
upsdebugx(2, "Can't get and publish sysContact for device.contact");

/* sysLocation.0 */
if (nut_snmp_get_str(".1.3.6.1.2.1.1.6.0", model, sizeof(model), NULL) == TRUE)
dstate_setinfo("device.location", "%s", model);
else
upsdebugx(2, "Can't get and publish sysLocation for device.location");
}

void upsdrv_cleanup(void)
Expand Down Expand Up @@ -1753,6 +1753,9 @@ void free_info(snmp_info_t *su_info_p)
* the MIB, based on a test using a template OID */
int base_snmp_template_index(const snmp_info_t *su_info_p)
{
if (!su_info_p)
return -1;

int base_index = -1;
char test_OID[SU_INFOSIZE];
int template_type = get_template_type(su_info_p->info_type);
Expand Down Expand Up @@ -2221,17 +2224,23 @@ bool_t daisychain_init()
dstate_setinfo("device.model", "daisychain (1+%ld)", devices_count - 1);
}
}
}
}
else {
daisychain_enabled = FALSE;
upsdebugx(1, "No device.count entry found, daisychain support not needed");
}

/* Finally, compute and store the base OID index and NUT offset */
device_template_index_base = base_snmp_template_index(su_find_info("device.model"));
upsdebugx(1, "%s: device_template_index_base = %i", __func__, device_template_index_base);
device_template_offset = device_template_index_base - 1;
upsdebugx(1, "%s: device_template_offset = %i", __func__, device_template_offset);
/* Finally, compute and store the base OID index and NUT offset */
su_info_p = su_find_info("device.model");
if (su_info_p != NULL) {
device_template_index_base = base_snmp_template_index(su_info_p);
upsdebugx(1, "%s: device_template_index_base = %i", __func__, device_template_index_base);
device_template_offset = device_template_index_base - 1;
upsdebugx(1, "%s: device_template_offset = %i", __func__, device_template_offset);
}
else {
upsdebugx(1, "%s: No device.model entry found.", __func__);
}

return daisychain_enabled;
}
Expand Down

0 comments on commit 2dc9ff5

Please sign in to comment.