2020-01-01 09:07:35 +01:00
|
|
|
// SPDX-License-Identifier: LGPL-2.1+
|
2019-09-25 13:13:40 +02:00
|
|
|
/*
|
2019-10-01 09:20:35 +02:00
|
|
|
* Copyright (C) 2014 - 2018 Red Hat, Inc.
|
2014-07-22 12:55:23 -05:00
|
|
|
*/
|
|
|
|
|
|
2019-01-31 12:49:28 +01:00
|
|
|
#ifndef __NM_SD_ADAPT_SHARED_H__
|
|
|
|
|
#define __NM_SD_ADAPT_SHARED_H__
|
2014-07-22 12:55:23 -05:00
|
|
|
|
2016-02-19 14:57:48 +01:00
|
|
|
#include "nm-default.h"
|
2014-07-22 12:55:23 -05:00
|
|
|
|
2019-04-15 08:16:00 +02:00
|
|
|
#include "nm-glib-aux/nm-logging-fwd.h"
|
2018-12-28 16:20:12 +01:00
|
|
|
|
2015-01-10 14:51:41 +01:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2019-01-31 12:56:07 +01:00
|
|
|
/* strerror() is not thread-safe. Patch systemd-sources via a define. */
|
|
|
|
|
#define strerror(errsv) nm_strerror_native (errsv)
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2019-05-14 15:31:37 +02:00
|
|
|
/* systemd detects whether compiler supports "-Wstringop-truncation" to disable
|
|
|
|
|
* the warning at particular places. Since we anyway build with -Wno-pragma,
|
|
|
|
|
* we don't do that and just let systemd call
|
|
|
|
|
*
|
|
|
|
|
* _Pragma("GCC diagnostic ignored \"-Wstringop-truncation\"")
|
|
|
|
|
*
|
|
|
|
|
* regadless whether that would result in a -Wpragma warning. */
|
|
|
|
|
#define HAVE_WSTRINGOP_TRUNCATION 1
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2017-10-30 12:42:57 +01:00
|
|
|
static inline int
|
|
|
|
|
_nm_log_get_max_level_realm (void)
|
|
|
|
|
{
|
|
|
|
|
/* inline function, to avoid coverity warning about constant expression. */
|
2019-05-03 15:08:04 +02:00
|
|
|
return 7 /* LOG_DEBUG */;
|
2017-10-30 12:42:57 +01:00
|
|
|
}
|
|
|
|
|
#define log_get_max_level_realm(realm) _nm_log_get_max_level_realm ()
|
2017-06-14 12:07:26 +02:00
|
|
|
|
|
|
|
|
#define log_internal_realm(level, error, file, line, func, format, ...) \
|
2015-01-10 14:51:41 +01:00
|
|
|
({ \
|
2015-09-23 16:02:35 +02:00
|
|
|
const int _nm_e = (error); \
|
2019-05-03 15:08:04 +02:00
|
|
|
const NMLogLevel _nm_l = nm_log_level_from_syslog (LOG_PRI (level)); \
|
2015-09-23 16:02:35 +02:00
|
|
|
\
|
logging: make nm-logging thread-safe
NetworkManager is single-threaded and uses a mainloop.
However, sometimes we may need multiple threads. For example, we will
need to write sysctl values asynchronously, using the glib thread-pool.
For that to work, we also need to switch the network-namespace of the
thread-pool thread. We want to use NMPNetns for that. Hence it's better
to have NMPNetns thread-safe, instead of coming up with a duplicate
implementation. But NMPNetns may want to log, so we also need nm-logging
thread-safe.
In general, code under "shared/nm-utils" and nm-logging should be usable
from multiple threads. It's simpler to make this code thread-safe than
re-implementing it. Also, it's a bad limitation to be unable to log
from other threads. If there is an error, the best we can often do is to
log about it.
Make nm-logging thread-safe. Actually, we only need to be able to log
from multiple threads. We don't need to setup or configure logging from
multiple threads. This restriction allows us to access logging from the
main-thread without any thread-synchronization (because all changes in
the logging setup are also done from the main-thread).
So, while logging from other threads requires a mutex, logging from the
main-thread is lock-free.
2019-01-16 16:40:45 +01:00
|
|
|
if (_nm_log_enabled_impl (!(NM_THREAD_SAFE_ON_MAIN_THREAD), _nm_l, LOGD_SYSTEMD)) { \
|
2015-01-10 14:51:41 +01:00
|
|
|
const char *_nm_location = strrchr ((""file), '/'); \
|
2014-11-11 22:26:00 +01:00
|
|
|
\
|
logging: make nm-logging thread-safe
NetworkManager is single-threaded and uses a mainloop.
However, sometimes we may need multiple threads. For example, we will
need to write sysctl values asynchronously, using the glib thread-pool.
For that to work, we also need to switch the network-namespace of the
thread-pool thread. We want to use NMPNetns for that. Hence it's better
to have NMPNetns thread-safe, instead of coming up with a duplicate
implementation. But NMPNetns may want to log, so we also need nm-logging
thread-safe.
In general, code under "shared/nm-utils" and nm-logging should be usable
from multiple threads. It's simpler to make this code thread-safe than
re-implementing it. Also, it's a bad limitation to be unable to log
from other threads. If there is an error, the best we can often do is to
log about it.
Make nm-logging thread-safe. Actually, we only need to be able to log
from multiple threads. We don't need to setup or configure logging from
multiple threads. This restriction allows us to access logging from the
main-thread without any thread-synchronization (because all changes in
the logging setup are also done from the main-thread).
So, while logging from other threads requires a mutex, logging from the
main-thread is lock-free.
2019-01-16 16:40:45 +01:00
|
|
|
_nm_log_impl (_nm_location ? _nm_location + 1 : (""file), (line), (func), !(NM_THREAD_SAFE_ON_MAIN_THREAD), _nm_l, LOGD_SYSTEMD, _nm_e, NULL, NULL, ("%s"format), "libsystemd: ", ## __VA_ARGS__); \
|
2014-11-11 22:26:00 +01:00
|
|
|
} \
|
2015-01-10 14:51:41 +01:00
|
|
|
(_nm_e > 0 ? -_nm_e : _nm_e); \
|
|
|
|
|
})
|
2014-07-22 12:55:23 -05:00
|
|
|
|
2015-01-10 14:51:41 +01:00
|
|
|
#define log_assert_failed(text, file, line, func) \
|
2014-07-22 12:55:23 -05:00
|
|
|
G_STMT_START { \
|
2015-01-10 14:51:41 +01:00
|
|
|
log_internal (LOG_CRIT, 0, file, line, func, "Assertion '%s' failed at %s:%u, function %s(). Aborting.", text, file, line, func); \
|
|
|
|
|
g_assert_not_reached (); \
|
2014-07-22 12:55:23 -05:00
|
|
|
} G_STMT_END
|
|
|
|
|
|
2015-10-07 10:07:17 +02:00
|
|
|
#define log_assert_failed_unreachable(text, file, line, func) \
|
|
|
|
|
G_STMT_START { \
|
|
|
|
|
log_internal (LOG_CRIT, 0, file, line, func, "Code should not be reached '%s' at %s:%u, function %s(). Aborting.", text, file, line, func); \
|
|
|
|
|
g_assert_not_reached (); \
|
|
|
|
|
} G_STMT_END
|
|
|
|
|
|
2015-01-10 14:51:41 +01:00
|
|
|
#define log_assert_failed_return(text, file, line, func) \
|
2015-07-05 12:04:21 +02:00
|
|
|
({ \
|
2015-01-10 14:51:41 +01:00
|
|
|
log_internal (LOG_DEBUG, 0, file, line, func, "Assertion '%s' failed at %s:%u, function %s(). Ignoring.", text, file, line, func); \
|
|
|
|
|
g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, text); \
|
2015-07-05 12:04:21 +02:00
|
|
|
(void) 0; \
|
|
|
|
|
})
|
2014-07-22 12:55:23 -05:00
|
|
|
|
2018-12-28 18:11:16 +01:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2020-05-13 17:20:09 +02:00
|
|
|
#ifndef VALGRIND
|
2018-12-28 18:11:16 +01:00
|
|
|
#define VALGRIND 0
|
2020-05-13 17:20:09 +02:00
|
|
|
#endif
|
2018-12-28 18:11:16 +01:00
|
|
|
|
|
|
|
|
#define ENABLE_DEBUG_HASHMAP 0
|
|
|
|
|
|
2015-09-16 15:49:02 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
|
* The remainder of the header is only enabled when building the systemd code
|
|
|
|
|
* itself.
|
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
2018-01-02 13:37:06 +01:00
|
|
|
#if (NETWORKMANAGER_COMPILATION) & NM_NETWORKMANAGER_COMPILATION_WITH_SYSTEMD
|
2015-09-16 15:49:02 +02:00
|
|
|
|
|
|
|
|
#include <sys/syscall.h>
|
2016-02-29 14:30:15 +01:00
|
|
|
#include <sys/ioctl.h>
|
2015-09-16 15:49:02 +02:00
|
|
|
|
2020-03-23 17:27:34 +01:00
|
|
|
#define ENABLE_GSHADOW FALSE
|
|
|
|
|
|
2019-05-14 15:31:37 +02:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
/* systemd cannot be compiled with "-Wdeclaration-after-statement". In particular
|
|
|
|
|
* in combintation with assert_cc(). */
|
|
|
|
|
NM_PRAGMA_WARNING_DISABLE ("-Wdeclaration-after-statement")
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2018-02-15 10:25:44 +01:00
|
|
|
static inline pid_t
|
|
|
|
|
raw_getpid (void) {
|
|
|
|
|
#if defined(__alpha__)
|
|
|
|
|
return (pid_t) syscall (__NR_getxpid);
|
|
|
|
|
#else
|
|
|
|
|
return (pid_t) syscall (__NR_getpid);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-11 18:11:13 +01:00
|
|
|
static inline pid_t _nm_gettid(void) {
|
2018-12-28 18:11:16 +01:00
|
|
|
return (pid_t) syscall(SYS_gettid);
|
2016-03-09 12:27:56 +01:00
|
|
|
}
|
2019-03-11 18:11:13 +01:00
|
|
|
#define gettid() _nm_gettid ()
|
2016-03-09 12:27:56 +01:00
|
|
|
|
2018-12-28 18:11:16 +01:00
|
|
|
/* we build with C11 and thus <uchar.h> provides char32_t,char16_t. */
|
|
|
|
|
#define HAVE_CHAR32_T 1
|
|
|
|
|
#define HAVE_CHAR16_T 1
|
2016-08-11 13:05:14 +02:00
|
|
|
|
2018-12-28 18:11:16 +01:00
|
|
|
#if defined(HAVE_DECL_REALLOCARRAY) && HAVE_DECL_REALLOCARRAY == 1
|
|
|
|
|
#define HAVE_REALLOCARRAY 1
|
|
|
|
|
#else
|
|
|
|
|
#define HAVE_REALLOCARRAY 0
|
2014-07-22 12:55:23 -05:00
|
|
|
#endif
|
|
|
|
|
|
2018-12-28 18:11:16 +01:00
|
|
|
#if defined(HAVE_DECL_EXPLICIT_BZERO) && HAVE_DECL_EXPLICIT_BZERO == 1
|
|
|
|
|
#define HAVE_EXPLICIT_BZERO 1
|
|
|
|
|
#else
|
|
|
|
|
#define HAVE_EXPLICIT_BZERO 0
|
2014-07-22 12:55:23 -05:00
|
|
|
#endif
|
|
|
|
|
|
2019-12-15 14:28:45 +01:00
|
|
|
#if defined(HAVE_DECL_PIDFD_OPEN) && HAVE_DECL_PIDFD_OPEN == 1
|
|
|
|
|
#define HAVE_PIDFD_OPEN 1
|
|
|
|
|
#else
|
|
|
|
|
#define HAVE_PIDFD_OPEN 0
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#if defined(HAVE_DECL_PIDFD_SEND_SIGNAL) && HAVE_DECL_PIDFD_SEND_SIGNAL == 1
|
|
|
|
|
#define HAVE_PIDFD_SEND_SIGNAL 1
|
|
|
|
|
#else
|
|
|
|
|
#define HAVE_PIDFD_SEND_SIGNAL 0
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#if defined(HAVE_DECL_RT_SIGQUEUEINFO) && HAVE_DECL_RT_SIGQUEUEINFO == 1
|
|
|
|
|
#define HAVE_RT_SIGQUEUEINFO 1
|
|
|
|
|
#else
|
|
|
|
|
#define HAVE_RT_SIGQUEUEINFO 0
|
|
|
|
|
#endif
|
|
|
|
|
|
2018-01-02 13:37:06 +01:00
|
|
|
#endif /* (NETWORKMANAGER_COMPILATION) & NM_NETWORKMANAGER_COMPILATION_WITH_SYSTEMD */
|
2015-09-16 15:49:02 +02:00
|
|
|
|
2018-12-28 18:11:16 +01:00
|
|
|
/*****************************************************************************/
|
2014-07-22 12:55:23 -05:00
|
|
|
|
2019-01-31 12:49:28 +01:00
|
|
|
#endif /* __NM_SD_ADAPT_SHARED_H__ */
|