mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-27 15:10:09 +01:00
logging: add error argument to _nm_log() to support "%m" format specifier
A gnu extension to printf adds the format specifier "%m"
to print @errno. To preserve the error number until the
point where the logging statement is constructed, pass
it as an additional argument to _nm_log().
This is not (yet) used from NM internal code. But systemd is adding
similar functionality to its logging functions. Add the same also to
nm-logging, to support systemd's usage of "%m".
(cherry picked from commit 5162426d41)
This commit is contained in:
parent
6e8c5b51b1
commit
edeaccc9eb
3 changed files with 9 additions and 3 deletions
|
|
@ -57,7 +57,7 @@ G_STMT_START { \
|
|||
if (nm_logging_enabled (_l, LOGD_DHCP)) { \
|
||||
const char *_location = strrchr (file "", '/'); \
|
||||
\
|
||||
_nm_log (_location ? _location + 1 : file, line, func, _l, LOGD_DHCP, format, ## __VA_ARGS__); \
|
||||
_nm_log (_location ? _location + 1 : file, line, func, _l, LOGD_DHCP, 0, format, ## __VA_ARGS__); \
|
||||
} \
|
||||
} G_STMT_END
|
||||
|
||||
|
|
|
|||
|
|
@ -362,6 +362,7 @@ _nm_log (const char *file,
|
|||
const char *func,
|
||||
NMLogLevel level,
|
||||
NMLogDomain domain,
|
||||
int error,
|
||||
const char *fmt,
|
||||
...)
|
||||
{
|
||||
|
|
@ -379,6 +380,10 @@ _nm_log (const char *file,
|
|||
if (!(logging[level] & domain))
|
||||
return;
|
||||
|
||||
/* Make sure that %m maps to the specified error */
|
||||
if (error != 0)
|
||||
errno = error;
|
||||
|
||||
va_start (args, fmt);
|
||||
msg = g_strdup_vprintf (fmt, args);
|
||||
va_end (args);
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@ typedef enum { /*< skip >*/
|
|||
#define nm_log(level, domain, ...) \
|
||||
G_STMT_START { \
|
||||
if (nm_logging_enabled ((level), (domain))) { \
|
||||
_nm_log (__FILE__, __LINE__, G_STRFUNC, (level), (domain), __VA_ARGS__); \
|
||||
_nm_log (__FILE__, __LINE__, G_STRFUNC, (level), (domain), 0, __VA_ARGS__); \
|
||||
} \
|
||||
} G_STMT_END
|
||||
|
||||
|
|
@ -141,8 +141,9 @@ void _nm_log (const char *file,
|
|||
const char *func,
|
||||
NMLogLevel level,
|
||||
NMLogDomain domain,
|
||||
int error,
|
||||
const char *fmt,
|
||||
...) __attribute__((__format__ (__printf__, 6, 7)));
|
||||
...) __attribute__((__format__ (__printf__, 7, 8)));
|
||||
|
||||
const char *nm_logging_level_to_string (void);
|
||||
const char *nm_logging_domains_to_string (void);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue