Ad Widget

Collapse

a double overflow may cause wrong value

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • scotti
    Member
    • Dec 2005
    • 32

    #1

    a double overflow may cause wrong value

    when using zabbix_get to get system.cpu.intr from linux, there always get a wrong value like "4294967295", this's because the data type for the "value" in SYSTEM_CPU_INTR(src/libs/zbxsysinfo/linux/cpu.c) is "double" which has a limit of 4 bytes only( 4294967296 in maximum ); this can be fixed in the following ways:

    int SYSTEM_CPU_INTR(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
    {
    int ret = SYSINFO_RET_FAIL;
    char line[MAX_STRING_LEN];

    char name[MAX_STRING_LEN];
    unsigned long long value = 0;

    FILE *f;

    assert(result);

    init_result(result);

    f=fopen("/proc/stat","r");
    if(f)
    {
    while(fgets(line,MAX_STRING_LEN,f) != NULL)
    {
    if(sscanf(line,"%s\t%lld\n", name, &value) != 2)
    Last edited by scotti; 07-09-2006, 05:40.
Working...