]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: hlua: return wall-clock date, not internal date in core.now()
authorWilly Tarreau <w@1wt.eu>
Thu, 27 Apr 2023 16:44:14 +0000 (18:44 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 27 Apr 2023 16:44:14 +0000 (18:44 +0200)
That's hopefully the last one affected by this. It was a bit trickier
because there's the promise in the doc that the date is monotonous, so
we continue to use now-start_time as the uptime value and add it to
start_date to get the current date. It was also emphasized by commit
28360dc ("MEDIUM: clock: force internal time to wrap early after boot"),
causing core.now() to return a date of Mar 20 on Apr 27. No backport is
needed.

src/hlua_fcn.c

index 188fcf4fdb2222da5dda288dc77ce25f24632663..8d87c34a674f92bf234d75f9b83be023506f7553 100644 (file)
@@ -300,12 +300,20 @@ void *hlua_checkudata(lua_State *L, int ud, int class_ref)
 /* This function return the current date at epoch format in milliseconds. */
 int hlua_now(lua_State *L)
 {
+       /* WT: the doc says "returns the current time" and later says that it's
+        * monotonic. So the best fit is to use start_date+(now-start_time).
+        */
+       struct timeval tv;
+
+       tv_remain(&start_time, &now, &tv);
+       tv_add(&tv, &tv, &start_date);
+
        lua_newtable(L);
        lua_pushstring(L, "sec");
-       lua_pushinteger(L, now.tv_sec);
+       lua_pushinteger(L, tv.tv_sec);
        lua_rawset(L, -3);
        lua_pushstring(L, "usec");
-       lua_pushinteger(L, now.tv_usec);
+       lua_pushinteger(L, tv.tv_usec);
        lua_rawset(L, -3);
        return 1;
 }