Commit Graph

189 Commits

Author SHA1 Message Date
Thomas Haller
aed3c810b3 systemd: split "nm-sd.h" out of "nm-sd-adapt.h"
Now we have:

"nm-sd.h" is a header file of NetworkManager with utilities
related to systemd. It can be used anywhere freely.

Also, systemd headers that are considered public API (like
"sd-event.h") can be used without restrictions.

When compiling the systemd sources, we always must include
"nm-sd-adapt.h" as first. Similarly, systemd headers must
not include "nm-sd-adapt.h", because they are either public
(in which case the adapter is not needed) or they are internal
(in which case they are themself included via a systemd source).

Sometimes, we must internal API (like "dhcp-lease-internal.h").
In this case, we also must include "nm-sd-adapt.h".
2016-03-11 11:02:12 +01:00
Thomas Haller
a8bc65b1a1 systemd: integrate sd-event into glib main loop
We should not try to reimplement sd-event based on glib,
instead we should hook sd-event into the glib mainloop.
2016-03-11 09:28:12 +01:00
Thomas Haller
cd4f84b738 all: don't include error->code in log messages
GError codes are only unique per domain, so logging the code without
also indicating the domain is not helpful. And anyway, if the error
messages are not distinctive enough to tell the whole story then we
should fix the error messages.

Based-on-patch-by: Dan Winship <danw@gnome.org>
2016-03-03 18:54:20 +01:00
Thomas Haller
01b9b4104c all: clean-up usage of GError
Functions that take a GError** MUST fill it in on error. There is no
need to check whether error is NULL if the function it was passed to
had a failing return value.

Likewise, a proper GError must have a non-NULL message, so there's no
need to double-check that either.

Based-on-patch-by: Dan Winship <danw@gnome.org>
2016-03-03 18:54:20 +01:00
Thomas Haller
d22b3fabc5 core: use nm_utils_parse_debug_string() instead of g_parse_debug_string() 2016-02-21 18:31:39 +01:00
Thomas Haller
8bace23beb all: cleanup includes and let "nm-default.h" include "config.h"
- All internal source files (except "examples", which are not internal)
  should include "config.h" first. As also all internal source
  files should include "nm-default.h", let "config.h" be included
  by "nm-default.h" and include "nm-default.h" as first in every
  source file.
  We already wanted to include "nm-default.h" before other headers
  because it might contains some fixes (like "nm-glib.h" compatibility)
  that is required first.

- After including "nm-default.h", we optinally allow for including the
  corresponding header file for the source file at hand. The idea
  is to ensure that each header file is self contained.

- Don't include "config.h" or "nm-default.h" in any header file
  (except "nm-sd-adapt.h"). Public headers anyway must not include
  these headers, and internal headers are never included after
  "nm-default.h", as of the first previous point.

- Include all internal headers with quotes instead of angle brackets.
  In practice it doesn't matter, because in our public headers we must
  include other headers with angle brackets. As we use our public
  headers also to compile our interal source files, effectively the
  result must be the same. Still do it for consistency.

- Except for <config.h> itself. Include it with angle brackets as suggested by
  https://www.gnu.org/software/autoconf/manual/autoconf.html#Configuration-Headers
2016-02-19 17:53:25 +01:00
Thomas Haller
e1ea4b725e main: add argument --print-config to NetworkManager 2015-11-22 13:40:32 +01:00
Beniamino Galvani
f1b4eb9558 core: fix failed assertion when D-Bus service is already taken
When exiting after an error we must set the quitting flag in
nm-exported-object.c because during program destruction there can be
still exported objects which get disposed.

Fixes the following assertion:

 NetworkManager[14241]: (nm-exported-object.c:826):nm_exported_object_dispose: code should not be reached

 Process terminating with default action of signal 5 (SIGTRAP)
    at 0x7ACFD3B: _g_log_abort (gmessages.c:315)
    by 0x7ACFD3B: g_logv (gmessages.c:1041)
    by 0x7ACFEAE: g_log (gmessages.c:1079)
    by 0x7AD0196: g_warn_message (gmessages.c:1112)
    by 0x20F5B0:  nm_exported_object_dispose (nm-exported-object.c:826)
    by 0x316FC4:  dispose (nm-settings.c:2222)
    by 0x7841A5B: g_object_unref (gobject.c:3137)
    by 0x2330F3:  dispose (nm-manager.c:5249)
    by 0x7841A5B: g_object_unref (gobject.c:3137)
    by 0x23C511:  _nm_singleton_instance_destroy (NetworkManagerUtils.c:174)
    by 0x400FBE6: _dl_fini (in /usr/lib64/ld-2.21.so)
    by 0x8009647: __run_exit_handlers (in /usr/lib64/libc-2.21.so)
    by 0x8009694: exit (in /usr/lib64/libc-2.21.so)
2015-11-13 18:01:33 +01:00
Dan Williams
f9ee20a7b2 core: explicitly unexport objects when we're done with them
Previously most objects were implicitly unexported when they were
destroyed, but since refcounts may make the object live longer than
intended, we should explicitly unexport them when they should no
longer be present on the bus.

This means we can assume that objects will always be un-exported
already when they are destroyed, *except* when quitting where most
objects will live until exit because NM leaves interfaces up and
running on quit.
2015-11-10 18:12:12 +01:00
Thomas Haller
e908c9c293 trivial: fix spelling in comment
Fixes: 9a88d72fd4
2015-09-15 18:25:24 +02:00
Lubomir Rintel
9a88d72fd4 core: register G_TYPE_SOCKET early
Concurrent registrations later on can cause a deadlock due to a GLib bug.

https://bugzilla.gnome.org/show_bug.cgi?id=754795
2015-09-15 16:53:17 +02:00
Thomas Haller
31cde10b69 core: nm_singleton_instance_register() of NMManager instance
Register the singleton instance of NMManager as we do for other
singletons. That way, we get automatic destruction and the singleton
instance get's properly cleared (when the instance gets destroyed).
2015-08-13 10:06:42 +02:00
Thomas Haller
99ad9fedf5 platform: delay destruction of NMPlatform singleton until NMConfig gets destroyed
We want to create the platform instance rather late (especially after
claiming the D-Bus service). But we also want to destroy it very late,
because NMPlatform does not make use of any other singletons, but
other singletons make use of NMPlatform.
2015-08-13 10:06:42 +02:00
Thomas Haller
b9f00dbb19 manager: remove WiMAX rfkill flag from NMManger
WiMAX support was dropped in commit 721e917cb6.
Also, remove support for the WiMAX rfkill flag and only preserve the
D-Bus property for backward compatibility.
2015-08-13 10:06:42 +02:00
Dan Winship
1cf35cb26b core: final gdbus porting
Port remaining bits to gdbus and remove stray dbus-glib references

Drop the dbus-glib version check from configure, since nothing depends
on new dbus-glib any more.

Move nm-dbus-glib-types.h and nm-gvaluearray-compat.h from include/ to
libnm-util/ since they are now only used by libnm-util and libnm-glib.
2015-08-10 09:41:26 -04:00
Dan Winship
284e15a877 core: make NMManager singleton more like others
Rename nm_manager_new() to nm_manager_setup(), and change the local
@singleton variable to @singleton_instance. (Also, add a local @self
variable inside nm_manager_setup().)

Also, make NMManager own NMSettings rather than having them both owned
by main().
2015-08-10 09:41:26 -04:00
Dan Winship
b7911bae51 core: better order the code at startup
NM was calling nm_bus_manager_start_service() to claim its bus name
before it exported any of its objects, but this didn't matter under
dbus-glib, because no client connections would be accepted until the
main loop was started later on, by which point we would have exported
everything.

But with gdbus, method calls are initially received in the gdbus
worker thread, which means that clients would be able to connect right
away and then be told that the expected interfaces don't exist.

So move the nm_bus_manager_start_service() call to occur after
creating NMSettings and NMManager (and, indirectly, NMAgentManager).
This requires splitting out the slow parts of nm_settings_new() into a
new nm_settings_start(), so that we can create and export it first,
and then read the connections, etc afterward. (Likewise, there were
still a few potentially-slow bits in nm_manager_new() which are now
moved into nm_manager_start().)
2015-08-10 09:41:26 -04:00
Dan Winship
1c11c5cff1 core: fix NMManager in private-bus-only case
NMManager was failing to initialize if there was only a private bus,
despite the fact that this is exactly the use case that the private
bus was added for.

The only other potentially-failing code in nm_manager_new() was adding
prop_filter to the D-Bus connection, but this can't really fail, so
just assert that it doesn't. And now, nm_manager_new() always
succeeds, so update the caller for that.
2015-08-10 09:41:25 -04:00
Dan Winship
22e1a97e12 all: drop includes to <glib/gi18n.h> for "nm-default.h"
The localization headers are now included via "nm-default.h".

Also fixes several places, where we wrongly included <glib/gi18n-lib.h>
instead of <glib/gi18n.h>. For example under "clients/" directory.
2015-08-05 15:35:51 +02:00
Thomas Haller
19c3ea948a all: make use of new header file "nm-default.h" 2015-08-05 15:32:40 +02:00
Thomas Haller
2cf274c03e core: order destruction of singleton instances
Previously, the order of destructing singleton instances
was undefined. Now, have singleton instances register their
destruction via nm_singleton_instance_register().

Objects that are registered later, will be destructed earlier. IOW,
they will be destroyed in reverse order of construction.

This is only a crude method to get the lifetime of singleton instances
right by default. Having singletons ref other singletons to keep them
alive gives more control over the lifetimes of singletons. This change
of having a defined order of destruction does not conflict with taking
references to singletons (and thus extending their lifetime).

Note that previously, NMPlatform was not registered for destruction.
We don't change that yet and intenionally leak a reference.
2015-08-05 15:23:57 +02:00
Dan Winship
02370be7f3 core: rename NMDBusManager to NMBusManager
Our gdbus generated types use the same names as their corresponding
"real" types, but with "NM" changed to "NMDBus".

Unfortunately, that means that introspection/nmdbus-manager.c (the
generated type for src/nm-manager.c) uses the same type name as the
entirely unrelated src/nm-dbus-manager.c.

Fix this by removing the "d" from src/nm-dbus-manager.c. (We could
rename the generated type instead, but then it becomes inconsistent
with all the other generated types, and we're already using it as
"NMDBusManager" in libnm/nm-manager.c.)
2015-07-24 13:25:48 -04:00
Dan Winship
3452ee2a0e all: rename nm-glib-compat.h to nm-glib.h, use everywhere
Rather than randomly including one or more of <glib.h>,
<glib-object.h>, and <gio/gio.h> everywhere (and forgetting to include
"nm-glib-compat.h" most of the time), rename nm-glib-compat.h to
nm-glib.h, include <gio/gio.h> from there, and then change all .c
files in NM to include "nm-glib.h" rather than including the glib
headers directly.

(Public headers files still have to include the real glib headers,
since nm-glib.h isn't installed...)

Also, remove glib includes from header files that are already
including a base object header file (which must itself already include
the glib headers).
2015-07-24 13:25:47 -04:00
Thomas Haller
96a7f3a3ba logging: make use of journal configurable 2015-07-14 15:55:14 +02:00
Thomas Haller
9020cd1aac logging: remove nm_logging_syslog_closelog()
Remove nm_logging_syslog_closelog(). The reasons are:

  - closelog() is optional according to the manual.

  - we called nm_logging_syslog_closelog() at the end of the
    main() function. But we have destructors running afterwards,
    so we were closing the log before logging the last line.
    Apparently that had no bad consequences either, so why was
    closelog() even useful?
    Also, it's hard to determine when we log the last line and
    only closelog() afterwards.

  - closelog() does not revert what openlog() did, this is ugly.
2015-07-14 15:52:50 +02:00
Thomas Haller
09ba572174 config: move debug command line option to NMConfig
Whether NM runs in debug mode is also interesting to other
components outside of "main.c". Expose global_opt.debug
via a new nm_config_get_is_debug() function.

Actually, we should move parsing of all command line options
to NMConfig, as NMConfig is the central instance to provide
such information.
2015-07-14 15:52:50 +02:00
Thomas Haller
904e961464 all: remove #if GLIB_CHECK_VERSION conditionals around g_type_init()
g_type_init() is now provided by nm-glib-compat.h as nm_g_type_init().
2015-07-12 13:56:52 +02:00
Thomas Haller
40c57fa7f1 config: add write support to atomic-sections
We already support setting configuration values, either:
 (1) set any internal section, i.e. groups starting with [.intern*].
     Those values don't ever interfere with that the user can
     configure.
 (2) set individual properties that overwrite user configuration.
     When doing that, we record the value from user configuration
     and on load, we reject our internal overwrite if the user
     configuration changed in the meantime.
     This is done by storing the values with ".set." and ".was." prefixes.

Now add support for "atomic sections". In this case, certain groups
can be marked as "atomic". When writing to such sections, we overwrite
the entire user-provided setting.
We also record the values from user configuration, and reject our
internal value if we notice modifications. This basically extends
(2) from individual properties to the entire section.
2015-07-02 16:01:20 +02:00
Thomas Haller
b506c29fe1 config: log configuration at startup and on reload 2015-07-02 15:50:04 +02:00
Thomas Haller
27bd7dc938 config: change examples for command line arguments to system default 2015-07-02 15:50:03 +02:00
Thomas Haller
caed15e082 config: pass signals to nm_config_reload()
Also react on SIGUSR1 and SIGUSR2, beside SIGHUP.
Only for SIGHUP actually reload the configuration from
disc. For the other signals only emit a config-changed
signal.
2015-06-25 22:02:18 +02:00
Thomas Haller
c1a945b95d platform: signal missing firmware in nm_platform_set_up()
Don't use nm_platform_get_error() anymore.
2015-06-17 11:44:16 +02:00
Jiří Klimeš
94a393e9ed all: fix a compiler warning about function declarations
warning: function declaration isn’t a prototype [-Wstrict-prototypes]

In C function() and function(void) are two different prototypes (as opposed to
C++).
function()     accepts an arbitrary number of arguments
function(void) accepts zero arguments
2015-06-10 10:01:49 +02:00
Lubomir Rintel
36f7669a4c core: don't assume the loopback interface is called "lo"
I did a "ip link set lo name yolo" and now my NetworkManager triggers an
assertion failure. :( Nevertheless, the loopback interface is always ifindex=1.
2015-06-01 17:30:24 +00:00
Beniamino Galvani
c029502912 ipv4ll: use internal implementation 2015-05-11 10:48:48 +02:00
Thomas Haller
c6529a9d74 platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.

While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.

With this change, NMPlatform instances can be used individually, not
only as a singleton instance.

Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.

Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.

Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.

This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-21 17:51:34 +02:00
Thomas Haller
d8e1d9b469 core/logging: downgrade some <info> loggings to <debug>
These logging statements are compile time dependent and
add little informational value.
2015-04-18 21:41:40 +02:00
Thomas Haller
10cde91f10 core: add "fatal-warnings" option to NM_DEBUG
NM already understands the command line argument --g-fatal-warnings
which causes setting of g_log_set_always_fatal().

Also interpret the "fatal-warnings" token in NM_DEBUG environment
variable and in main.debug configuration setting.

Usage hint: either set

  $ export NM_DEBUG=RLIMIT_CORE,fatal-warnings

or add the following section to NetworkManager.conf

    [main]
    debug=RLIMIT_CORE,fatal-warnings

https://mail.gnome.org/archives/networkmanager-list/2015-March/msg00093.html
2015-04-01 10:58:28 +02:00
Thomas Haller
21562052ec main: (order) early start D-Bus service
systemd considers the startup time of NetworkManager until the D-Bus
service is claimed. By doing that earlier, this time is significantly
reduced.
This has the advantage, that services that are ordered to start
after NetworkManager can start earlier. Most notably, 'network.target'
orders itself After=NetworkManager.service and many services are ordered
After=network.target.

  $ systemd-analyze blame | grep NetworkManager.service
2015-03-20 11:43:30 +01:00
Thomas Haller
7fe0f349ce main: (order) move run_from_build_dir check before setting up logging
Or: move setup of nm-logging immediately after it is really needed:
before setup of config.
2015-03-20 11:43:30 +01:00
Thomas Haller
49cfe64874 main: (order) earlier create rundir
Create the rundir earlier and before setting up nm-logging.
nm_main_utils_ensure_rundir() errors out with fprintf(stderr)
and does not need nm-logging.
2015-03-20 11:43:30 +01:00
Thomas Haller
f64c79afda main: (order) log "is starting" message immediately after setting up logging 2015-03-20 11:43:30 +01:00
Thomas Haller
7be9024c82 main: (order) parse state file later and use nm-logging
Parse the state file a bit later after daemonizing and setting up
logging. That way, we can use nm-logging.
2015-03-20 11:43:30 +01:00
Thomas Haller
af2b44cb43 main: (order) check pidfile earlier for running NM
We should check for conflicting process (pidfile)
early on and error out.
2015-03-20 11:43:30 +01:00
Thomas Haller
95786a4e4e main: (order) move root user check after help/version option
With this change, `NetworkManager --help` and `NetworkManager --version`
work for non-root user.
2015-03-20 11:43:30 +01:00
Thomas Haller
3696c675fe main: (order) early call _init_nm_debug()
_init_nm_debug() only depends on DEBUG config setting.
Let's call it first after parsing configuration.
2015-03-20 11:43:30 +01:00
Thomas Haller
c50622c845 main: (order) set g_log_set_always_fatal() early on
After parsing the cmd line options, we already can setup fatal glog
level.
2015-03-20 11:43:30 +01:00
Thomas Haller
0587dbe96c main: (order) call g_type_init() very early in main()
g_type_init() is independent of all NetworkManager
functionality. Just get it done early on.
2015-03-20 11:43:30 +01:00
Thomas Haller
12ad2c7fe7 main: refactor nm_main_utils_check_pidfile() to exit directly on failure
And rename the function to nm_main_utils_ensure_not_running_pidfile()
to match the other _ensure_ functions that exit(1).

Also no longer pass @name to nm_main_utils_ensure_not_running_pidfile()
and use g_get_prgname() instead.
nm_main_utils_ensure_not_running_pidfile() checks that the running
process has the same program name, so this changes behavior if the
user renamed the binary. Before, we would check whether the running
process is named 'NetworkManager' ('nm-iface-helper'). Now we check
whether the process has the same name as the current process.
This means, that if you rename the binary to 'NetworkManager2' we
would now only detect a conflicting 'NetworkManager2'. Before we would
only detect conflicting 'NetworkManager' binaries.
2015-03-20 11:43:30 +01:00
Thomas Haller
29718fcaa4 main: split out nm_main_utils_ensure_rundir ()
Also, don't use nm_log_err() as nm-logging is not yet setup.
2015-03-20 11:43:30 +01:00