On Fri, Feb 3, 2012 at 9:22 PM, Magnus Fromreide <[email protected]>wrote:
> On Fri, 2012-02-03 at 14:47 +0100, Bart Van Assche wrote:
> > It is known that backwards and forwards adjustments of the system
> > clock can cause snmpd and libsnmp to behave different than documented.
> > The patch below addresses this. Because of the impact of this patch
> > (it changes the ABI somewhat by storing monotonic clock values instead
> > of wall clock times in some struct members) I'm posting it here as an
> > RFC.
>
> Initial impressions:
>
> * netsnmp_get_agent_runtime() is a good idea. I think that should
> be added regardless of the rest of the patch.
> * I dislike that netsnmp_get_monotonic_clock might return
> gettimeofday but I suppose that there isn't much to do about
> that but maybe it is possible to get a better name for the
> function? One could do heroics with clock and assume that
> machines that lack clock_gettime have a stable clock tick but I
> do not think it isn't worth the effort.
>
As far as I know all sufficiently modern POSIX systems (including Cygwin)
support CLOCK_MONOTONIC. The code that invokes gettimeofday() is only there
to make sure that the Net-SNMP source code still compiles on older systems
without CLOCK_MONOTONIC support.
Was there any uses of gettimeofday that were looking for absolute time
> as opposed to the relative time that CLOCK_MONOTONIC represents?
>
If you grep in the source code for "starttime" you will see that several
MIB implementations depend on that time being a wall clock time:
$ git grep -w starttime | grep 'c:' | grep -v agent/snmp_agent.c
agent/mibgroup/host/hr_swinst.c:#define starttime (*(const struct
timeval*)netsnmp_get_agent_starttime())
agent/mibgroup/host/hr_swinst.c: if (stat_buf.st_mtime >
starttime.tv_sec)
agent/mibgroup/host/hr_swinst.c: long_return =
(stat_buf.st_mtime - starttime.tv_sec) * 100;
agent/mibgroup/if-mib/data_access/interface_openbsd.c:#define starttime
(*(const struct timeval*)netsnmp_get_agent_starttime())
agent/mibgroup/if-mib/data_access/interface_openbsd.c: if
(timercmp(&ifp->ifm_data.ifi_lastchange, &starttime, >)) {
agent/mibgroup/if-mib/data_access/interface_openbsd.c:
entry->lastchange = (ifp->ifm_data.ifi_lastchange.tv_sec -
starttime.tv_sec) * 100;
agent/mibgroup/if-mib/data_access/interface_sysctl.c:#define starttime
(*(const struct timeval*)netsnmp_get_agent_starttime())
agent/mibgroup/if-mib/data_access/interface_sysctl.c:
TIMEVAL_TO_TIMESPEC(&starttime, &startspec);
agent/mibgroup/if-mib/data_access/interface_sysctl.c: if
(timercmp(&ifp->ifm_data.ifi_lastchange, &starttime, >)) {
agent/mibgroup/if-mib/data_access/interface_sysctl.c:
starttime.tv_sec) * 100;
agent/mibgroup/mibII/interfaces.c:#define starttime (*(const struct
timeval*)netsnmp_get_agent_starttime())
agent/mibgroup/mibII/interfaces.c: else if
(if_msg.ifm_data.ifi_lastchange.tv_sec < starttime.tv_sec)
agent/mibgroup/mibII/interfaces.c: starttime.tv_sec) * 100
+
agent/mibgroup/mibII/interfaces.c: - starttime.tv_usec) /
10000);
agent/mibgroup/mibII/interfaces.c: else if
(ifnet.if_lastchange.tv_sec < starttime.tv_sec)
agent/mibgroup/mibII/interfaces.c:
((ifnet.if_lastchange.tv_sec - starttime.tv_sec) * 100
agent/mibgroup/mibII/interfaces.c: starttime.tv_usec) /
10000);
agent/mibgroup/mibII/interfaces.c: } else if
(ifmd.ifmd_data.ifi_lastchange.tv_sec < starttime.tv_sec) {
agent/mibgroup/mibII/interfaces.c: starttime.tv_sec) * 100
+
agent/mibgroup/mibII/interfaces.c: starttime.tv_usec) /
10000));
Bart.
------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
Net-snmp-coders mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders