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: e3f88f311f

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1572
This commit is contained in:
Thomas Haller 2023-03-17 12:16:29 +01:00
parent 2c9faea63c
commit 575e35d1ca
No known key found for this signature in database
GPG Key ID: 29C2366E4DFC5728
2 changed files with 22 additions and 20 deletions

View File

@ -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__)

View File

@ -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));