Ad Widget

Collapse

system.boottime for OpenBSD (needs testing)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • freak
    Member
    • Oct 2007
    • 52

    #1

    system.boottime for OpenBSD (needs testing)

    I've been fiddling around trying to enable system.boottime for OpenBSD. I'm not a programmer, I guess this is the biggest thing I've been doing in C now, so please be a bit patient

    I've tested the build on OpenBSD 4.1 and Debian Sid now - the latter was quite a pain .. which I hadn't expected.

    I based this on svn tags/1.4.2/ but it seems to work with the current trunk as well.

    Okay, so first I had to fix one thing: sysctl.h requires param.h to be included before its inclusion, so I added these #ifdefs:

    ./configure.in
    Code:
    --- tags/1.4.2-new/configure.in 2007-10-17 16:10:51.000000000 +0200
    +++ tags/1.4.2/configure.in     2007-10-16 14:23:50.000000000 +0200
    @@ -232,11 +232,6 @@
     [
     #include <stdlib.h>
     #include <sys/types.h>
    -
    -#ifdef HAVE_SYS_PARAM_H
    -#include <sys/param.h>
    -#endif /* HAVE_SYS_PARAM_H */
    -
     #include <sys/sysctl.h>
     #include <vm/vm_param.h>
     #include <sys/vmmeter.h>
    @@ -333,11 +328,6 @@
     AC_TRY_COMPILE(
     [
            #include <sys/types.h>
    -
    -       #ifdef HAVE_SYS_PARAM_H
    -       #include <sys/param.h>
    -       #endif /* HAVE_SYS_PARAM_H */
    -
            #include <sys/sysctl.h>
            #include <unistd.h>
            #include <time.h>
    @@ -362,11 +352,6 @@
     AC_TRY_COMPILE(
     [
            #include <sys/types.h>
    -
    -       #ifdef HAVE_SYS_PARAM_H
    -       #include <sys/param.h>
    -       #endif /* HAVE_SYS_PARAM_H */
    -
            #include <sys/sysctl.h>
     ],
     [
    @@ -387,11 +372,6 @@
     AC_TRY_COMPILE(
     [
            #include <sys/types.h>
    -
    -       #ifdef HAVE_SYS_PARAM_H
    -       #include <sys/param.h>
    -       #endif /* HAVE_SYS_PARAM_H */
    -
            #include <sys/sysctl.h>
     ],
     [
    ./src/libs/zbxsysinfo/openbsd/Makefile.am
    Code:
    --- tags/1.4.2-new/src/libs/zbxsysinfo/openbsd/Makefile.am      2007-10-16 14:33:20.000000000 +0200
    +++ tags/1.4.2/src/libs/zbxsysinfo/openbsd/Makefile.am  2007-10-16 14:21:36.000000000 +0200
    @@ -15,5 +15,4 @@
            proc.c \
            sensors.c \
            swap.c \
    -       uptime.c \
    -       boottime.c
    +       uptime.c
    ./src/libs/zbxsysinfo/openbsd/openbsd.c
    Code:
    --- tags/1.4.2-sra/src/libs/zbxsysinfo/openbsd/openbsd.c        2007-10-16 13:36:11.000000000 +0200
    +++ tags/1.4.2/src/libs/zbxsysinfo/openbsd/openbsd.c    2007-10-16 14:21:36.000000000 +0200
    @@ -56,7 +56,6 @@
            {"system.swap.out",     CF_USEUPARAM,   SYSTEM_SWAP_OUT,        0,      "all,count"},
    
            {"system.uptime",       0,              SYSTEM_UPTIME,          0,      0},
    -       {"system.boottime",     0,              SYSTEM_BOOTTIME,        0,      0},
    
            {0}
            };
    And finally there's this piece of code, inspired by the implementation of system.uptime and the uptime implementation in OpenBSD/src/usr.bin/w/w.c which is basically the same):

    ./src/libs/zbxsysinfo/openbsd/boottime.c
    Code:
    #include "common.h"
    
    #include "sysinfo.h"
    
    int     SYSTEM_BOOTTIME(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
    {
            int     mib[2];
            size_t  len;
            struct timeval  boottime;
            int     ret = SYSINFO_RET_FAIL;
    
            assert(result);
            init_result(result);
    
            mib[0]=CTL_KERN;
            mib[1]=KERN_BOOTTIME;
            len=sizeof(boottime);
            if (sysctl(mib, 2, &boottime, (size_t *) &len, NULL, 0) != -1)
            {
                    SET_UI64_RESULT(result, boottime.tv_sec);
                    ret = SYSINFO_RET_OK;
            }
    
            return ret;
    }
    So I'd appreciate any testing and comments


    Sebastian
Working...