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:
@@ -21,21 +21,22 @@
|
|||||||
#define _NMLOG_ENABLED(level) ((level) <= LOG_ERR)
|
#define _NMLOG_ENABLED(level) ((level) <= LOG_ERR)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define _NMLOG(always_enabled, level, ...) \
|
#define _NMLOG(always_enabled, level, ...) \
|
||||||
G_STMT_START \
|
G_STMT_START \
|
||||||
{ \
|
{ \
|
||||||
if ((always_enabled) || _NMLOG_ENABLED(level)) { \
|
if ((always_enabled) || _NMLOG_ENABLED(level)) { \
|
||||||
GTimeVal _tv; \
|
gint64 _tv; \
|
||||||
\
|
\
|
||||||
g_get_current_time(&_tv); \
|
_tv = g_get_real_time(); \
|
||||||
g_print( \
|
g_print("nm-dhcp-helper[%ld] %-7s [%" G_GINT64_FORMAT \
|
||||||
"nm-dhcp-helper[%ld] %-7s [%ld.%04ld] " _NM_UTILS_MACRO_FIRST(__VA_ARGS__) "\n", \
|
".%04d] " _NM_UTILS_MACRO_FIRST(__VA_ARGS__) "\n", \
|
||||||
(long) getpid(), \
|
(long) getpid(), \
|
||||||
nm_utils_syslog_to_str(level), \
|
nm_utils_syslog_to_str(level), \
|
||||||
_tv.tv_sec, \
|
(_tv / NM_UTILS_USEC_PER_SEC), \
|
||||||
_tv.tv_usec / 100 _NM_UTILS_MACRO_REST(__VA_ARGS__)); \
|
((int) ((_tv % NM_UTILS_USEC_PER_SEC) / (((gint64) 100)))) \
|
||||||
} \
|
_NM_UTILS_MACRO_REST(__VA_ARGS__)); \
|
||||||
} \
|
} \
|
||||||
|
} \
|
||||||
G_STMT_END
|
G_STMT_END
|
||||||
|
|
||||||
#define _LOGD(...) _NMLOG(TRUE, LOG_INFO, __VA_ARGS__)
|
#define _LOGD(...) _NMLOG(TRUE, LOG_INFO, __VA_ARGS__)
|
||||||
|
@@ -665,7 +665,7 @@ _nm_log_impl(const char *file,
|
|||||||
char msg_stack[400];
|
char msg_stack[400];
|
||||||
gs_free char *msg_heap = NULL;
|
gs_free char *msg_heap = NULL;
|
||||||
const char *msg;
|
const char *msg;
|
||||||
GTimeVal tv;
|
gint64 tv;
|
||||||
int errsv;
|
int errsv;
|
||||||
const NMLogDomain *cur_log_state;
|
const NMLogDomain *cur_log_state;
|
||||||
NMLogDomain cur_log_state_copy[_LOGL_N_REAL];
|
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
|
* 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
|
* lines are formatted and aligned in a consistent way, which aids reading the
|
||||||
* logs. */
|
* logs. */
|
||||||
#define MESSAGE_FMT "%s%-7s [%ld.%04ld] %s"
|
#define MESSAGE_FMT "%s%-7s [%" G_GINT64_FORMAT ".%04d] %s"
|
||||||
#define MESSAGE_ARG(prefix, tv, msg) \
|
#define MESSAGE_ARG(prefix, tv, msg) \
|
||||||
prefix, nm_log_level_desc[level].level_str, (tv).tv_sec, ((tv).tv_usec / 100), (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)
|
if (g->debug_stderr)
|
||||||
g_printerr(MESSAGE_FMT "\n", MESSAGE_ARG(g->prefix, tv, msg));
|
g_printerr(MESSAGE_FMT "\n", MESSAGE_ARG(g->prefix, tv, msg));
|
||||||
|
Reference in New Issue
Block a user