2020-12-23 22:21:36 +01:00
|
|
|
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
2019-09-25 13:13:40 +02:00
|
|
|
/*
|
2019-10-01 09:20:35 +02:00
|
|
|
* Copyright (C) 2015 Red Hat, Inc.
|
2015-07-17 14:22:27 +02:00
|
|
|
*/
|
|
|
|
|
|
2020-09-01 17:27:17 +02:00
|
|
|
/* With autotools (and also meson), all our source files are expected to include <config.h>.
|
|
|
|
|
* as very first header. Then they are expected to include "config-extra.h" and a small set
|
|
|
|
|
* of headers that we always want to have included (depending on what sources we compile
|
|
|
|
|
* (as determined by NETWORKMANAGER_COMPILATION define) that can be "nm-glib-aux/nm-macros-internal.h"
|
|
|
|
|
* and similar.
|
|
|
|
|
*
|
|
|
|
|
* To simplify that, all our source files are only expected to include "nm-default.h" as first,
|
|
|
|
|
* and thereby rely on getting a basic set of headers already.
|
|
|
|
|
*/
|
|
|
|
|
|
2015-07-17 14:22:27 +02:00
|
|
|
#ifndef __NM_DEFAULT_H__
|
|
|
|
|
#define __NM_DEFAULT_H__
|
|
|
|
|
|
2021-02-04 21:46:19 +01:00
|
|
|
#include "nm-std-aux/nm-networkmanager-compilation.h"
|
2015-07-17 14:22:27 +02:00
|
|
|
|
|
|
|
|
#ifndef NETWORKMANAGER_COMPILATION
|
2018-01-02 13:37:06 +01:00
|
|
|
#error Define NETWORKMANAGER_COMPILATION accordingly
|
|
|
|
|
#endif
|
|
|
|
|
|
2021-02-04 18:04:13 +01:00
|
|
|
#if NETWORKMANAGER_COMPILATION < NM_NETWORKMANAGER_COMPILATION_SYSTEMD_SHARED
|
all: add "nm-std-aux/nm-default-std.h" as replacement for "nm-default.h"
autotools projects commonly should include "config.h" as first header.
Also, commonly we need more headers, like glib.h or our nm_auto macros.
Hence, almost all our sources should as first include "nm-default.h".
However, as we build different parts, "nm-default.h" gets controlled
by the NETWORKMANAGER_COMPILATION define which autotools/meson needs
to specify in the build options.
That is confusing.
One advantage of that was, that theoretically the same sources can
be built twice, with different behavior. However, we should avoid doing
that altogether and build static libraries (once) that we link multiple
times.
Another advantage was that if NETWORKMANAGER_COMPILATION is for example
set to build a DAEMON source, there is a check that we don't include
private headers from libnm-core. However, that should be better solved
by not having public, internal and private headers in the same
directory.
Instead, introduce different "nm-default-*.h" headers that don't require
special defines and behave in a consistent way. This way, we require
fewer CFLAGS and it's immediately clear by looking at the source alone
which headers are included. Also, you will be easier see when a wrong
nm-default-*.h header gets included.
Introduce the first replacement. The others will follow.
2021-02-04 07:34:17 +01:00
|
|
|
#error Dont include this header with such NETWORKMANAGER_COMPILATION
|
|
|
|
|
#endif
|
|
|
|
|
|
2018-01-02 13:37:06 +01:00
|
|
|
#ifndef G_LOG_DOMAIN
|
|
|
|
|
#if defined(NETWORKMANAGER_COMPILATION_TEST)
|
|
|
|
|
#define G_LOG_DOMAIN "test"
|
|
|
|
|
#elif NETWORKMANAGER_COMPILATION & NM_NETWORKMANAGER_COMPILATION_WITH_DAEMON
|
|
|
|
|
#define G_LOG_DOMAIN "NetworkManager"
|
|
|
|
|
#else
|
|
|
|
|
#error Need to define G_LOG_DOMAIN
|
|
|
|
|
#endif
|
2015-07-17 14:22:27 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
/* always include these headers for our internal source files. */
|
|
|
|
|
|
2016-02-19 14:57:48 +01:00
|
|
|
#ifndef ___CONFIG_H__
|
|
|
|
|
#define ___CONFIG_H__
|
|
|
|
|
#include <config.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
build: create "config-extra.h" header instead of passing directory variables via CFLAGS
1) the command line gets shorter. I frequently run `make V=1` to see
the command line arguments for the compiler, and there is a lot
of noise.
2) define each of these variables at one place. This makes it easy
to verify that for all compilation units, a particular
define has the same value. Previously that was not obvious or
even not the case (see commit e5d1a71396e107d1909744d26ad401f206c0c915
and commit d63cf1ef2faba57595112a82e962b9643cce4718).
The point is to avoid redundancy.
3) not all compilation units need all defines. In fact, most modules
would only need a few of these defines. We aimed to pass the necessary
minium of defines to each compilation unit, but that was non-obvious
to get right and often we set a define that wasn't used. See for example
"src_settings_plugins_ibft_cppflags" which needlessly had "-DSYSCONFDIR".
This question is now entirely avoided by just defining all variables in
a header. We don't care to find the minimum, because every component
gets anyway all defines from the header.
4) this also avoids the situation, where a module that previously did
not use a particular define gets modified to require it. Previously,
that would have required to identify the missing define, and add
it to the CFLAGS of the complation unit. Since every compilation
now includes "config-extra.h", all defines are available everywhere.
5) the fact that each define is now available in all compilation units
could be perceived as a downside. But it isn't, because these defines
should have a unique name and one specific value. Defining the same
name with different values, or refer to the same value by different
names is a bug, not a desirable feature. Since these defines should
be unique accross the entire tree, there is no problem in providing
them to every compilation unit.
6) the reason why we generate "config-extra.h" this way, instead of using
AC_DEFINE() in configure.ac, is due to the particular handling of
autoconf for directory variables. See [1].
With meson, it would be trivial to put them into "config.h.meson".
While that is not easy with autoconf, the "config-extra.h" workaround
seems still preferable to me.
[1] https://www.gnu.org/software/autoconf/manual/autoconf-2.63/html_node/Installation-Directory-Variables.html
2018-07-12 10:58:23 +02:00
|
|
|
#include "config-extra.h"
|
|
|
|
|
|
2016-04-05 21:18:43 +02:00
|
|
|
/* for internal compilation we don't want the deprecation macros
|
|
|
|
|
* to be in effect. Define the widest range of versions to effectively
|
|
|
|
|
* disable deprecation checks */
|
|
|
|
|
#define NM_VERSION_MIN_REQUIRED NM_VERSION_0_9_8
|
|
|
|
|
|
2016-09-09 14:31:30 +02:00
|
|
|
#ifndef NM_MORE_ASSERTS
|
|
|
|
|
#define NM_MORE_ASSERTS 0
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#if NM_MORE_ASSERTS == 0
|
|
|
|
|
/* The cast macros like NM_TYPE() are implemented via G_TYPE_CHECK_INSTANCE_CAST()
|
|
|
|
|
* and _G_TYPE_CIC(). The latter, by default performs runtime checks of the type
|
|
|
|
|
* by calling g_type_check_instance_cast().
|
|
|
|
|
* This check has a certain overhead without being helpful.
|
|
|
|
|
*
|
|
|
|
|
* Example 1:
|
|
|
|
|
* static void foo (NMType *obj)
|
|
|
|
|
* {
|
|
|
|
|
* access_obj_without_check (obj);
|
|
|
|
|
* }
|
|
|
|
|
* foo ((NMType *) obj);
|
|
|
|
|
* // There is no runtime check and passing an invalid pointer
|
|
|
|
|
* // leads to a crash.
|
|
|
|
|
*
|
|
|
|
|
* Example 2:
|
|
|
|
|
* static void foo (NMType *obj)
|
|
|
|
|
* {
|
|
|
|
|
* access_obj_without_check (obj);
|
|
|
|
|
* }
|
|
|
|
|
* foo (NM_TYPE (obj));
|
|
|
|
|
* // There is a runtime check which prints a g_warning(), but that doesn't
|
|
|
|
|
* // avoid the crash as NM_TYPE() cannot do anything then passing on the
|
|
|
|
|
* // invalid pointer.
|
|
|
|
|
*
|
|
|
|
|
* Example 3:
|
|
|
|
|
* static void foo (NMType *obj)
|
|
|
|
|
* {
|
|
|
|
|
* g_return_if_fail (NM_IS_TYPE (obj));
|
|
|
|
|
* access_obj_without_check (obj);
|
|
|
|
|
* }
|
|
|
|
|
* foo ((NMType *) obj);
|
|
|
|
|
* // There is a runtime check which prints a g_critical() which also avoids
|
|
|
|
|
* // the crash. That is actually helpful to catch bugs and avoid crashes.
|
|
|
|
|
*
|
|
|
|
|
* Example 4:
|
|
|
|
|
* static void foo (NMType *obj)
|
|
|
|
|
* {
|
|
|
|
|
* g_return_if_fail (NM_IS_TYPE (obj));
|
|
|
|
|
* access_obj_without_check (obj);
|
|
|
|
|
* }
|
|
|
|
|
* foo (NM_TYPE (obj));
|
|
|
|
|
* // The runtime check is performed twice, with printing a g_warning() and
|
|
|
|
|
* // a g_critical() and avoiding the crash.
|
|
|
|
|
*
|
|
|
|
|
* Example 3 is how it should be done. Type checks in NM_TYPE() are pointless.
|
|
|
|
|
* Disable them for our production builds.
|
|
|
|
|
*/
|
|
|
|
|
#ifndef G_DISABLE_CAST_CHECKS
|
|
|
|
|
#define G_DISABLE_CAST_CHECKS
|
|
|
|
|
#endif
|
|
|
|
|
#endif
|
|
|
|
|
|
2018-03-05 13:00:34 +01:00
|
|
|
#if NM_MORE_ASSERTS == 0
|
|
|
|
|
#ifndef G_DISABLE_CAST_CHECKS
|
|
|
|
|
/* Unless compiling with G_DISABLE_CAST_CHECKS, glib performs type checking
|
2018-09-30 11:30:18 -03:00
|
|
|
* during G_VARIANT_TYPE() via g_variant_type_checked_(). This is not necessary
|
2018-03-05 13:00:34 +01:00
|
|
|
* because commonly this cast is needed during something like
|
|
|
|
|
*
|
|
|
|
|
* g_variant_builder_init (&props, G_VARIANT_TYPE ("a{sv}"));
|
|
|
|
|
*
|
|
|
|
|
* Note that in if the variant type would be invalid, the check still
|
|
|
|
|
* wouldn't make the buggy code magically work. Instead of passing a
|
|
|
|
|
* bogus type string (bad), it would pass %NULL to g_variant_builder_init()
|
|
|
|
|
* (also bad).
|
|
|
|
|
*
|
|
|
|
|
* Also, a function like g_variant_builder_init() already validates
|
|
|
|
|
* the input type via something like
|
|
|
|
|
*
|
|
|
|
|
* g_return_if_fail (g_variant_type_is_container (type));
|
|
|
|
|
*
|
|
|
|
|
* So, by having G_VARIANT_TYPE() also validate the type, we validate
|
|
|
|
|
* twice, whereas the first validation is rather pointless because it
|
|
|
|
|
* doesn't prevent the function to be called with invalid arguments.
|
|
|
|
|
*
|
|
|
|
|
* Just patch G_VARIANT_TYPE() to perform no check.
|
|
|
|
|
*/
|
|
|
|
|
#undef G_VARIANT_TYPE
|
|
|
|
|
#define G_VARIANT_TYPE(type_string) ((const GVariantType *) (type_string))
|
|
|
|
|
#endif
|
|
|
|
|
#endif
|
|
|
|
|
|
2016-02-12 15:43:30 +01:00
|
|
|
#include <stdlib.h>
|
2018-01-02 13:37:06 +01:00
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#if (NETWORKMANAGER_COMPILATION) & NM_NETWORKMANAGER_COMPILATION_WITH_GLIB
|
|
|
|
|
|
2016-06-06 15:20:05 +02:00
|
|
|
#include <glib.h>
|
|
|
|
|
|
2018-01-02 13:37:06 +01:00
|
|
|
#if (NETWORKMANAGER_COMPILATION) & NM_NETWORKMANAGER_COMPILATION_WITH_GLIB_I18N_PROG
|
|
|
|
|
#if (NETWORKMANAGER_COMPILATION) & NM_NETWORKMANAGER_COMPILATION_WITH_GLIB_I18N_LIB
|
|
|
|
|
#error Cannot define NM_NETWORKMANAGER_COMPILATION_WITH_GLIB_I18N_PROG and NM_NETWORKMANAGER_COMPILATION_WITH_GLIB_I18N_LIB
|
|
|
|
|
#endif
|
|
|
|
|
#include <glib/gi18n.h>
|
|
|
|
|
#elif (NETWORKMANAGER_COMPILATION) & NM_NETWORKMANAGER_COMPILATION_WITH_GLIB_I18N_LIB
|
|
|
|
|
#include <glib/gi18n-lib.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2016-06-06 15:20:05 +02:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2021-01-27 17:05:42 +01:00
|
|
|
#include "nm-gassert-patch.h"
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2020-07-04 18:41:58 +02:00
|
|
|
#include "nm-std-aux/nm-std-aux.h"
|
2020-07-05 10:16:54 +02:00
|
|
|
#include "nm-std-aux/nm-std-utils.h"
|
2019-04-15 08:16:00 +02:00
|
|
|
#include "nm-glib-aux/nm-macros-internal.h"
|
|
|
|
|
#include "nm-glib-aux/nm-shared-utils.h"
|
|
|
|
|
#include "nm-glib-aux/nm-errno.h"
|
|
|
|
|
#include "nm-glib-aux/nm-hash-utils.h"
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2015-07-17 14:22:27 +02:00
|
|
|
/*****************************************************************************/
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2019-03-05 08:44:57 +01:00
|
|
|
#if (NETWORKMANAGER_COMPILATION) & NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_CORE
|
2018-01-02 13:37:06 +01:00
|
|
|
#include "nm-version.h"
|
|
|
|
|
#endif
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2015-08-04 12:08:20 +02:00
|
|
|
/*****************************************************************************/
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2018-01-02 13:37:06 +01:00
|
|
|
#if (NETWORKMANAGER_COMPILATION) & NM_NETWORKMANAGER_COMPILATION_WITH_DAEMON
|
2018-10-12 17:07:25 +02:00
|
|
|
#include "nm-core-types.h"
|
2015-07-17 14:22:27 +02:00
|
|
|
#include "nm-types.h"
|
2020-12-30 17:32:10 +01:00
|
|
|
#include "nm-log-core/nm-logging.h"
|
2018-01-02 13:37:06 +01:00
|
|
|
#endif
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2019-10-17 08:15:44 +02:00
|
|
|
#if (NETWORKMANAGER_COMPILATION) & NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_PRIVATE
|
|
|
|
|
#include "nm-libnm-utils.h"
|
|
|
|
|
#endif
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2018-01-02 13:37:06 +01:00
|
|
|
#if ((NETWORKMANAGER_COMPILATION) &NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM) \
|
|
|
|
|
&& !((NETWORKMANAGER_COMPILATION) \
|
|
|
|
|
& (NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_PRIVATE \
|
|
|
|
|
| NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_CORE_INTERNAL))
|
|
|
|
|
#include "NetworkManager.h"
|
|
|
|
|
#endif
|
2015-07-17 14:22:27 +02:00
|
|
|
|
2018-01-02 13:37:06 +01:00
|
|
|
#endif /* NM_NETWORKMANAGER_COMPILATION_WITH_GLIB */
|
2015-07-17 14:22:27 +02:00
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#endif /* __NM_DEFAULT_H__ */
|