summaryrefslogtreecommitdiffstats
path: root/src/libs/zbxsysinfo/solaris/uptime.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libs/zbxsysinfo/solaris/uptime.c')
-rw-r--r--src/libs/zbxsysinfo/solaris/uptime.c156
1 files changed, 33 insertions, 123 deletions
diff --git a/src/libs/zbxsysinfo/solaris/uptime.c b/src/libs/zbxsysinfo/solaris/uptime.c
index fc5e21cf..814ad97d 100644
--- a/src/libs/zbxsysinfo/solaris/uptime.c
+++ b/src/libs/zbxsysinfo/solaris/uptime.c
@@ -19,124 +19,11 @@
#include "config.h"
-#include <errno.h>
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-/* Definitions of uint32_t under OS/X */
-#ifdef HAVE_STDINT_H
- #include <stdint.h>
-#endif
-#ifdef HAVE_STRINGS_H
- #include <strings.h>
-#endif
-#ifdef HAVE_FCNTL_H
- #include <fcntl.h>
-#endif
-#ifdef HAVE_DIRENT_H
- #include <dirent.h>
-#endif
-/* Linux */
-#ifdef HAVE_SYS_VFS_H
- #include <sys/vfs.h>
-#endif
-#ifdef HAVE_SYS_SYSINFO_H
- #include <sys/sysinfo.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_STATVFS_H
- #include <sys/statvfs.h>
-#endif
-/* Solaris */
-#ifdef HAVE_SYS_PROCFS_H
-/* This is needed to access the correct procfs.h definitions */
- #define _STRUCTURED_PROC 1
- #include <sys/procfs.h>
-#endif
-#ifdef HAVE_SYS_LOADAVG_H
- #include <sys/loadavg.h>
-#endif
-#ifdef HAVE_SYS_SOCKET_H
- #include <sys/socket.h>
-#endif
-#ifdef HAVE_NETINET_IN_H
- #include <netinet/in.h>
-#endif
-#ifdef HAVE_ARPA_INET_H
- #include <arpa/inet.h>
-#endif
-/* OpenBSD/Solaris */
-#ifdef HAVE_SYS_PARAM_H
- #include <sys/param.h>
-#endif
-
-#ifdef HAVE_SYS_MOUNT_H
- #include <sys/mount.h>
-#endif
-
-/* HP-UX */
-#ifdef HAVE_SYS_PSTAT_H
- #include <sys/pstat.h>
-#endif
-
-#ifdef HAVE_NETDB_H
- #include <netdb.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SWAP_H
- #include <sys/swap.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_SYS_SYSCTL_H
- #include <sys/sysctl.h>
-#endif
-
-/* Solaris */
-#ifdef HAVE_SYS_SYSCALL_H
- #include <sys/syscall.h>
-#endif
-
-/* FreeBSD */
-#ifdef HAVE_VM_VM_PARAM_H
- #include <vm/vm_param.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_VMMETER_H
- #include <sys/vmmeter.h>
-#endif
-/* FreeBSD */
-#ifdef HAVE_SYS_TIME_H
- #include <sys/time.h>
-#endif
-
-#ifdef HAVE_MACH_HOST_INFO_H
- #include <mach/host_info.h>
-#endif
-#ifdef HAVE_MACH_MACH_HOST_H
- #include <mach/mach_host.h>
-#endif
-
-
-#ifdef HAVE_KSTAT_H
- #include <kstat.h>
-#endif
-
-#ifdef HAVE_LDAP
- #include <ldap.h>
-#endif
-
#include "common.h"
#include "sysinfo.h"
#if 1
-int SYSTEM_UPTIME(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+int SYSTEM_UPTIME(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
kstat_ctl_t *kc;
kstat_t *kp;
@@ -144,7 +31,11 @@ int SYSTEM_UPTIME(const char *cmd, const char *param,double *value, const char
time_t now;
- int result = SYSINFO_RET_FAIL;
+ int ret = SYSINFO_RET_FAIL;
+
+ assert(result);
+
+ clean_result(result);
kc = kstat_open();
@@ -155,24 +46,30 @@ int SYSTEM_UPTIME(const char *cmd, const char *param,double *value, const char
{
kn = (kstat_named_t*) kstat_data_lookup(kp, "boot_time");
time(&now);
- *value=difftime(now, (time_t) kn->value.ul);
- result = SYSINFO_RET_OK;
+ result->type |= AR_DOUBLE;
+ result->dbl = difftime(now, (time_t) kn->value.ul);
+ ret = SYSINFO_RET_OK;
}
kstat_close(kc);
}
- return result;
+ return ret;
}
#endif
#if 0
-int SYSTEM_UPTIME(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+int SYSTEM_UPTIME(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_SYSINFO_UPTIME
struct sysinfo info;
+ assert(result);
+
+ clean_result(result);
+
if( 0 == sysinfo(&info))
{
- *value=(double)info.uptime;
+ result->type |= AR_DOUBLE;
+ result->dbl = (double)info.uptime;
return SYSINFO_RET_OK;
}
else
@@ -185,6 +82,10 @@ int SYSTEM_UPTIME(const char *cmd, const char *parameter,double *value, const c
struct timeval uptime;
int now;
+ assert(result);
+
+ clean_result(result);
+
mib[0]=CTL_KERN;
mib[1]=KERN_BOOTTIME;
@@ -197,8 +98,8 @@ int SYSTEM_UPTIME(const char *cmd, const char *parameter,double *value, const c
}
now=time(NULL);
-
- *value=(double)(now-uptime.tv_sec);
+ result->type |= AR_DOUBLE;
+ result->dbl = (double)(now-uptime.tv_sec);
return SYSINFO_RET_OK;
#else
/* Solaris */
@@ -210,6 +111,10 @@ int SYSTEM_UPTIME(const char *cmd, const char *parameter,double *value, const c
long hz;
long secs;
+ assert(result);
+
+ clean_result(result);
+
hz = sysconf(_SC_CLK_TCK);
/* open kstat */
@@ -237,9 +142,14 @@ int SYSTEM_UPTIME(const char *cmd, const char *parameter,double *value, const c
/* close kstat */
kstat_close(kc);
- *value=(double)secs;
+ result->type |= AR_DOUBLE;
+ result->dbl = (double)secs;
return SYSINFO_RET_OK;
#else
+ assert(result);
+
+ clean_result(result);
+
return SYSINFO_RET_FAIL;
#endif
#endif