[nut-Bugs][313634] Use difftime for time comparison

nut-bugs at alioth.debian.org nut-bugs at alioth.debian.org
Fri Feb 15 23:11:02 UTC 2013


nut-Bugs item #313634, was changed at 16/02/2013 00:11 by Arnaud Quette
You can respond by visiting: 
https://alioth.debian.org/tracker/?func=detail&atid=411542&aid=313634&group_id=30602

>Status: Closed
Priority: 3
Submitted By: Arnaud Quette (aquette)
Assigned to: Vaclav Krpec (vencik-guest)
Summary: Use difftime for time comparison 
Category: None
Group: None
Resolution: None


Initial Comment:
prefer to use difftime() for time comparison.

Missing implementations:
- mge-utalk
- snmp-ups
- usbhid-ups
- maybe some others...

----------------------------------------------------------------------

>Comment By: Arnaud Quette (aquette)
Date: 16/02/2013 00:11

Message:
Now handled on GitHub: https://github.com/networkupstools/nut/issues/10

----------------------------------------------------------------------

Comment By: Vaclav Krpec (vencik-guest)
Date: 26/09/2012 10:27

Message:
As for the clock_[gs]ettime, these will require wrappers for portability reasons.
If we want to use them (where possible, e.g. on Linux), I suggest to create our own opaque timer type + appropriate get/set/cmp/inc/dec etc iface that can be implemented either by the monotonic clock (if available) or simply by time_t (otherwise).
Then, usage of this type & iface should be wide-spread throughout the code, replacing time_t.
Shall I do it in scope of this bugfix?  I'd recommend to create a feature req. for such a change (not a bug), however, I can do it, instantly...


----------------------------------------------------------------------

Comment By: Vaclav Krpec (vencik-guest)
Date: 26/09/2012 10:01

Message:
On second thoughts, that shouldn't be real problem; however, at least it will be unified...

----------------------------------------------------------------------

Comment By: Vaclav Krpec (vencik-guest)
Date: 26/09/2012 08:58

Message:
I've found at least 2 occurrences of the following practice as well (generalised & compacted):
nextpoll = now + interval;
/* ... */
if (difftime(nextpoll, now) < 0.0) /* or if (nextpoll < now) etc */

This is the same problem (for non numeric implementations of time_t).
I'm fixing it, too.


----------------------------------------------------------------------

Comment By: Charles Lepple (clepple-guest)
Date: 24/09/2012 14:41

Message:
See also the patches for this bug, which tries to replace some instances of difftime() with a version that considers clock rollback:

https://alioth.debian.org/tracker/index.php?func=detail&aid=313714&group_id=30602&atid=411544

https://github.com/baruch/nut/commits/master/

----------------------------------------------------------------------

You can respond by visiting: 
https://alioth.debian.org/tracker/?func=detail&atid=411542&aid=313634&group_id=30602



More information about the NUT-tracker mailing list