keepalive: use ctime_r() for a safer multi-thread usage
authorVictor Seva <linuxmaniac@torreviejawireless.org>
Tue, 12 May 2020 14:37:09 +0000 (16:37 +0200)
committerVictor Seva <linuxmaniac@torreviejawireless.org>
Tue, 12 May 2020 14:45:23 +0000 (16:45 +0200)
src/modules/keepalive/keepalive_rpc.c

index 3a72b31..e6a64db 100644 (file)
@@ -78,24 +78,19 @@ static void keepalive_rpc_list(rpc_t *rpc, void *ctx)
 {
        void *sub;
        ka_dest_t *dest;
-       char *_ctime;
-       char *_utime;
-       char *_dtime;
+       char t_buf[26] = {0};
 
        for(dest = ka_destinations_list->first; dest != NULL; dest = dest->next) {
                rpc->add(ctx, "{", &sub);
 
                rpc->struct_add(sub, "SS", "uri", &dest->uri, "owner", &dest->owner);
 
-               _ctime = ctime(&dest->last_checked);
-               _ctime[strlen(_ctime) - 1] = '\0';
-               rpc->struct_add(sub, "s", "last checked", _ctime);
-               _utime = ctime(&dest->last_up);
-               _utime[strlen(_utime) - 1] = '\0';
-               rpc->struct_add(sub, "s", "last up", _utime);
-               _dtime = ctime(&dest->last_down);
-               _dtime[strlen(_dtime) - 1] = '\0';
-               rpc->struct_add(sub, "s", "last down", _dtime);
+               ctime_r(&dest->last_checked, t_buf);
+               rpc->struct_add(sub, "s", "last checked", t_buf);
+               ctime_r(&dest->last_up, t_buf);
+               rpc->struct_add(sub, "s", "last up", t_buf);
+               ctime_r(&dest->last_down, t_buf);
+               rpc->struct_add(sub, "s", "last down", t_buf);
                rpc->struct_add(sub, "d", "state", (int) dest->state);
        }