A few questions regarding times() usage in SNMPv3.

First, there is a bug in Linux times() that will return -1 a small
time frame just before times() wrap. See
http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=e3d5a27d5862b6425d0879272e24abecf7245105
for a fix but only for some arches.
A workaround for this problem:
static unsigned long snmp_times(void)
{
#if defined(GNU_LINUX)
  unsigned long ret;

  errno = 0;
  ret = times(NULL); /* Linux can handle NULL */
  /* Workaround broken syscall impl.
   * Fixed in 2.6.29 for some archs
   */
  if (errno)
    ret = (unsigned long) (-errno);
  return ret;

/* probably one can do this instead:
  ret = times(NULL);
  if (ret == ~0) {
    errno = 0;
    ret = times(NULL);
    if (ret == ~0 && errno)
      ret = (unsigned long) (-errno);
  }
  return ret;
*/
#else
  struct tms dummy; /* Only return value is used */
  return times(&dummy);
#endif

Secondly, Linux times() can take a NULL arg and that saves
a lot of work in the kernel.

Now to my real question, I don't understand why you need to
handle wrapping especially:
  
1540               clock_t now = times(&dummy);
1541               /* fixme: -1 is fault code... */
1542               unsigned int result;
1543             
1544               if (now < snmpv3startClock) {
1545                   result = UINT_MAX - snmpv3startClock + now;
1546               } else {
1547                   result = now - snmpv3startClock;
1548               }
1549               if (result < lastcalltime) {
1550                   /* wrapped */
1551                   wrapcounter++;
1552               }
1553               lastcalltime = result;
1554               result =  (UINT_MAX/clockticks)*wrapcounter + 
result/clockticks;

Should be possible to just do:

static unsigned long secs;

now = snmp_times();
diff = now - lastcalltime;
diff /= clockticks;
if (!diff)
   return secs; /* no change */
lastcalltime = now;
secs += diff;
return secs;

 Jocke


------------------------------------------------------------------------------
Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT
is a gathering of tech-side developers & brand creativity professionals. Meet
the minds behind Google Creative Lab, Visual Complexity, Processing, & 
iPhoneDevCamp asthey present alongside digital heavyweights like Barbarian
Group, R/GA, & Big Spaceship. http://www.creativitycat.com 
_______________________________________________
Net-snmp-coders mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders

Reply via email to