Hi,

attached all changes I made to snmpv3.c, lcd_time.c, system.h.
Used version: 5.0.9 (can be applied to 5.1.3.1 too)
System: Linux

Best regards,

Yegor Yefremov

>On Mon, 2005-08-15 at 11:03 +0200, Yegor Yefremov wrote:
Comment a accepted:

long get_uptime_in_sec(void)
{
        long ret;
        struct sysinfo *info = 
                        (struct sysinfo*)malloc(sizeof(struct sysinfo));
        
        if(sysinfo(info) < 0)
        {
                perror("Getting uptime");
                return -1;
        }
        
        ret = info->uptime;
        free(info);

        return ret;
}

I just wanted to show the main concept, that the usage of uptime is
safer and more precise then the usage of local time. What about the
platforms, so I checked it on the ARM9 System running uCLinux. I don't
think sysinfo call is portable. But I think every architecture should
offer the function to obtain the uptime. GetTickCount() under Windows
for example. One can define a macro to unite all architecture dependent
system calls.

Best regards,

Yegor Yefremov

>On Mon, 2005-08-15 at 11:03 +0200, Yegor Yefremov wrote:
>> Snmpv3_local_snmpEngineTime() gives a difference between start time
and
>> now in seconds. It means when you change the year you have too big
>> difference. But actually one wants to know the time difference from
>> system start (snmpv3 engine start time).
>> 
>> So I defined following function in system.c (and added a prototype to
>> system.h):
>> 
>> long get_uptime_in_sec(void)
>> {
>>      struct sysinfo *info =
>>      (struct sysinfo*)malloc(sizeof(struct sysinfo));
>>      
>>      if(sysinfo(info) < 0)
>>      {
>>              perror("Getting uptime");
>>              return -1;
>>      }
>>      
>>      return info->uptime;
>> }
>
>Two comments/questions:
>
>  a)  Doesn't this introduce a memory leak?
>You appear to be allocating new memory every time that
>'get_uptime_in_sec' is called, and never releasing it.
>
>  b)  What architecture(s) have you tried this with?
>How portable is the 'sysinfo' call?
>
>Dave




-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle
Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing &
QA
Security * Process Improvement & Measurement *
http://www.sqe.com/bsce5sf
_______________________________________________
Net-snmp-coders mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders


Attachment: system.h.diff
Description: system.h.diff

Attachment: lcd_time.c.diff
Description: lcd_time.c.diff

Attachment: snmpv3.c.diff
Description: snmpv3.c.diff

Reply via email to