From 575e35d1ca1bb8d17001e8f50acb825e4f3d816d Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 17 Mar 2023 12:16:29 +0100 Subject: [PATCH] log,dhcp: avoid deprecated GTimeVal API and use g_get_real_time() GTimeVal is deprecated because it's not year 2038 safe (on architectures where gulong is 32 bit). Don't use it. It's easy to replace. See-also: https://gitlab.gnome.org/GNOME/glib/-/commit/e3f88f311fe260bc1b57a8f1b84a4b7189956383 https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1572 --- src/core/dhcp/nm-dhcp-helper.c | 31 ++++++++++++++++--------------- src/libnm-log-core/nm-logging.c | 11 ++++++----- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/core/dhcp/nm-dhcp-helper.c b/src/core/dhcp/nm-dhcp-helper.c index 213d94965a..ee95abb70b 100644 --- a/src/core/dhcp/nm-dhcp-helper.c +++ b/src/core/dhcp/nm-dhcp-helper.c @@ -21,21 +21,22 @@ #define _NMLOG_ENABLED(level) ((level) <= LOG_ERR) #endif -#define _NMLOG(always_enabled, level, ...) \ - G_STMT_START \ - { \ - if ((always_enabled) || _NMLOG_ENABLED(level)) { \ - GTimeVal _tv; \ - \ - g_get_current_time(&_tv); \ - g_print( \ - "nm-dhcp-helper[%ld] %-7s [%ld.%04ld] " _NM_UTILS_MACRO_FIRST(__VA_ARGS__) "\n", \ - (long) getpid(), \ - nm_utils_syslog_to_str(level), \ - _tv.tv_sec, \ - _tv.tv_usec / 100 _NM_UTILS_MACRO_REST(__VA_ARGS__)); \ - } \ - } \ +#define _NMLOG(always_enabled, level, ...) \ + G_STMT_START \ + { \ + if ((always_enabled) || _NMLOG_ENABLED(level)) { \ + gint64 _tv; \ + \ + _tv = g_get_real_time(); \ + g_print("nm-dhcp-helper[%ld] %-7s [%" G_GINT64_FORMAT \ + ".%04d] " _NM_UTILS_MACRO_FIRST(__VA_ARGS__) "\n", \ + (long) getpid(), \ + nm_utils_syslog_to_str(level), \ + (_tv / NM_UTILS_USEC_PER_SEC), \ + ((int) ((_tv % NM_UTILS_USEC_PER_SEC) / (((gint64) 100)))) \ + _NM_UTILS_MACRO_REST(__VA_ARGS__)); \ + } \ + } \ G_STMT_END #define _LOGD(...) _NMLOG(TRUE, LOG_INFO, __VA_ARGS__) diff --git a/src/libnm-log-core/nm-logging.c b/src/libnm-log-core/nm-logging.c index f53c27c184..0909e7992a 100644 --- a/src/libnm-log-core/nm-logging.c +++ b/src/libnm-log-core/nm-logging.c @@ -665,7 +665,7 @@ _nm_log_impl(const char *file, char msg_stack[400]; gs_free char *msg_heap = NULL; const char *msg; - GTimeVal tv; + gint64 tv; int errsv; const NMLogDomain *cur_log_state; NMLogDomain cur_log_state_copy[_LOGL_N_REAL]; @@ -721,11 +721,12 @@ _nm_log_impl(const char *file, * We also do this for all messages (for all levels), because then the logging * lines are formatted and aligned in a consistent way, which aids reading the * logs. */ -#define MESSAGE_FMT "%s%-7s [%ld.%04ld] %s" -#define MESSAGE_ARG(prefix, tv, msg) \ - prefix, nm_log_level_desc[level].level_str, (tv).tv_sec, ((tv).tv_usec / 100), (msg) +#define MESSAGE_FMT "%s%-7s [%" G_GINT64_FORMAT ".%04d] %s" +#define MESSAGE_ARG(prefix, tv, msg) \ + prefix, nm_log_level_desc[level].level_str, ((tv) / NM_UTILS_USEC_PER_SEC), \ + ((int) ((((tv) % NM_UTILS_USEC_PER_SEC)) / ((gint64) 100))), (msg) - g_get_current_time(&tv); + tv = g_get_real_time(); if (g->debug_stderr) g_printerr(MESSAGE_FMT "\n", MESSAGE_ARG(g->prefix, tv, msg));