diff options
Diffstat (limited to 'src/libs/zbxsysinfo/freebsd/uptime.c')
-rw-r--r-- | src/libs/zbxsysinfo/freebsd/uptime.c | 48 |
1 files changed, 8 insertions, 40 deletions
diff --git a/src/libs/zbxsysinfo/freebsd/uptime.c b/src/libs/zbxsysinfo/freebsd/uptime.c index 7ec6b486d6c..0db7da844e4 100644 --- a/src/libs/zbxsysinfo/freebsd/uptime.c +++ b/src/libs/zbxsysinfo/freebsd/uptime.c @@ -19,6 +19,7 @@ #include "common.h" #include "sysinfo.h" +#include "log.h" int SYSTEM_UPTIME(AGENT_REQUEST *request, AGENT_RESULT *result) { @@ -31,7 +32,10 @@ int SYSTEM_UPTIME(AGENT_REQUEST *request, AGENT_RESULT *result) return SYSINFO_RET_OK; } else + { + SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Cannot obtain system information: %s", zbx_strerror(errno))); return SYSINFO_RET_FAIL; + } #elif defined(HAVE_FUNCTION_SYSCTL_KERN_BOOTTIME) int mib[2], now; size_t len; @@ -43,54 +47,18 @@ int SYSTEM_UPTIME(AGENT_REQUEST *request, AGENT_RESULT *result) len = sizeof(uptime); if (0 != sysctl(mib, 2, &uptime, &len, NULL, 0)) - return SYSINFO_RET_FAIL; - - now = time(NULL); - - SET_UI64_RESULT(result, now - uptime.tv_sec); - - return SYSINFO_RET_OK; -#elif defined(HAVE_KSTAT_H) /* Solaris */ - kstat_ctl_t *kc; - kstat_t *kp; - kstat_named_t *kn; - - long hz; - long secs; - - /* open kstat */ - kc = kstat_open(); - if (0 == kc) - return SYSINFO_RET_FAIL; - - /* read uptime counter */ - kp = kstat_lookup(kc, "unix", 0, "system_misc"); - if (0 == kp) - { - kstat_close(kc); - return SYSINFO_RET_FAIL; - } - - if (-1 == kstat_read(kc, kp, 0)) { - kstat_close(kc); + SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Cannot obtain system information: %s", zbx_strerror(errno))); return SYSINFO_RET_FAIL; } - kn = (kstat_named_t*)kstat_data_lookup(kp, "clk_intr"); - - hz = sysconf(_SC_CLK_TCK); - - /* make sure we do not divide by 0 */ - assert(hz); - secs = get_kstat_numeric_value(kn) / hz; + now = time(NULL); - /* close kstat */ - kstat_close(kc); + SET_UI64_RESULT(result, now - uptime.tv_sec); - SET_UI64_RESULT(result, secs); return SYSINFO_RET_OK; #else + SET_MSG_RESULT(result, zbx_strdup(NULL, "Agent was compiled without support for uptime information.")); return SYSINFO_RET_FAIL; #endif } |