[Olsr-dev] RFC: fix gettimeofday moves time backwards

Ferry Huberts (spam-protected)
Wed Jun 27 10:17:36 CEST 2012



On 27-06-12 09:52, Ferry Huberts wrote:
> Guys,
>
> The gettimeofday() call does not guarantee that time moves forward (at
> least on Linux) and it seems to me that our code depends on that.
>
> The following sites use gettimeofday():
>> ./lib/secure/src/olsrd_secure.c:1089:  gettimeofday(&now, NULL);
>> ./lib/pud/nmealib/src/time.c:31:    gettimeofday(&tp, NULL);
>> ./lib/httpinfo/src/olsrd_httpinfo.c:315:  gettimeofday(&start_time,
>> NULL);
>> ./lib/httpinfo/src/olsrd_httpinfo.c:833:    gettimeofday(&now, NULL);
>> ./lib/tas/src/os_unix.c:133:  gettimeofday(&timeVal, NULL);
>> ./lib/jsoninfo/src/olsrd_jsoninfo.c:326:  gettimeofday(&start_time,
>> NULL);
>> ./src/scheduler.c:92:  if (gettimeofday(&tv, NULL) != 0) {
>> ./src/scheduler.c:545:  if (gettimeofday(&first_tv, NULL)) {
>> ./src/scheduler.c:729:  gettimeofday(&now, NULL);
>> ./src/olsr_spf.c:338:  gettimeofday(&t1, NULL);
>> ./src/olsr_spf.c:433:  gettimeofday(&t2, NULL);
>> ./src/olsr_spf.c:444:  gettimeofday(&t3, NULL);
>> ./src/olsr_spf.c:506:  gettimeofday(&t4, NULL);
>> ./src/olsr_spf.c:514:  gettimeofday(&t5, NULL);
>> ./src/win32/compat.c:113:gettimeofday(struct timeval *TVal, void
>> *TZone __attribute__ ((unused)))
>> ./src/win32/sys/time.h:96:int gettimeofday(struct timeval *TVal, void
>> *TZone);
>> ./CHANGELOG:847:function instead of gettimeofday(2). This prevents
>> possible problems
>> ./gui/linux-gtk/src/nodes.c:97:      gettimeofday(&now, (struct
>> timezone *)NULL);
>> ./gui/linux-gtk/src/nodes.c:107:        gettimeofday(&now, (struct
>> timezone *)NULL);
>> ./gui/linux-gtk/src/nodes.c:145:      gettimeofday(&now, (struct
>> timezone *)NULL);
>> ./gui/linux-gtk/src/nodes.c:189:          gettimeofday(&now, (struct
>> timezone *)NULL);
>> ./gui/linux-gtk/src/nodes.c:369:      gettimeofday(&now, (struct
>> timezone *)NULL);
>> ./gui/linux-gtk/src/nodes.c:526:  gettimeofday(&now, (struct timezone
>> *)NULL);
>> ./gui/linux-gtk/src/nodes.c:561:  gettimeofday(&now, (struct timezone
>> *)NULL);
>
>
> I propose to adjust these calls to use the
> clock_gettime(CLOCK_MONOTONIC, ...) call.
>
> I know this call is available on Linux but don't know about the other
> platforms. I can try win32 and Android myself but have no way to check
> bsd variants.
>
> What do you think?
>


Please disregard.
clock_gettime(CLOCK_MONOTONIC, ...) has some undefined start time.

-- 
Ferry Huberts






More information about the Olsr-dev mailing list