Commit graph

251 commits

Author SHA1 Message Date
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
Thomas Haller
5775df9a6d main: refactor early setup in main()
Move call to nm_main_utils_early_setup() to a separate function.
Also move the @options array away from the main function, saving
a few bytes on the stack.
Now only do_early_setup() modifies the @global_opt structure.
2015-03-20 11:43:29 +01:00
Thomas Haller
1fc5aba42a main: move option variables to static variable
Move the variables to a static struct so that we can factor
out some of the initialization code.

Also it's nice to have all options placed together in one struct so
that is is obvious which static variables are part of the command line
options, and which have other use.
2015-03-20 11:43:29 +01:00
Thomas Haller
5e962bef87 main: don't unref config instance at end of main()
config is a singleton implemented using NM_DEFINE_SINGLETON_DESTRUCTOR().
No need to unref it manually.
2015-03-20 11:43:29 +01:00
Thomas Haller
ee4543bd6e main/trivial: change order of arguments for nm_main_utils_early_setup()
Change the order of the argv and argc argument to match
the main() function.
2015-03-20 11:43:29 +01:00
Dan Williams
a5891299b9 core: quit if manager startup completed before starting the mainloop 2015-03-11 09:17:01 -05:00
Thomas Haller
56f5fba723 config: move main_file and description to NMConfigData
Every reload might change the main_file and description.
Move those properties to NMConfigData.
2015-02-03 13:01:53 +01:00
Thomas Haller
3714a6c7bd config/trivial: rename variables for configuration file
The name "nm_conf_path" and cli.config_path" were not consistent.
Rename them both to "config_main_file".
2015-02-03 13:01:53 +01:00
Thomas Haller
82cfd5ad47 config: add support for reloading of configuration
No actual reloading is yet implemented. Later we will decide
on specific configuration parameters where we support reloading.
They must be then implemented one-by-one.

Some configuration parameters can be set via command line.
If a parameter is set from command line, the original value
from command line will still be preserved after reloading.
2015-02-03 13:01:53 +01:00
Thomas Haller
d62022e28a config: add handler for SIGHUP and a reload-configuration stub 2015-02-03 13:01:53 +01:00
Thomas Haller
1ff5154369 config: add nm_config_setup() to initialize config singleton
Make nm_config_new() usable without accessing static/singleton data.

nm_config_setup() is now used to initialize the singleton.
Still, you must not call nm_config_get() before calling
nm_config_setup() or after freeing the provided singleton
instance.
2015-02-03 13:01:53 +01:00
Dan Winship
c5b3e93792 core: use GUnixSignalWatchSource to simplify signal handling
Replace the pthread_sigwait()-based signal handling with
g_unix_signal_add()-based handling, and get rid of all the
now-unnecessary calls to nm_unblock_posix_signals() when spawning
subprocesses.

As a bonus, this also fixes the "^C in gdb kills NM too" bug.
2015-01-19 11:29:13 -05:00
Thomas Haller
1208c0dd13 dbus: destroy singleton instance of NMDBusManager on exit
Don't have the singleton instance of NMDBusManager owned by
the main function. Instead use NM_DEFINE_SINGLETON_DESTRUCTOR()
which also logs what's happening.
2015-01-12 12:10:03 +01:00
Thomas Haller
d45c1b84f4 core: declare nm_supplicant_manager_get() using NM_DEFINE_SINGLETON_GETTER() 2015-01-12 12:10:03 +01:00
Thomas Haller
22409e0481 core: declare nm_firewall_manager_get() using NM_DEFINE_SINGLETON_GETTER() 2015-01-12 12:10:03 +01:00
Thomas Haller
e2739cfc1b core: declare nm_vpn_manager_get() using NM_DEFINE_SINGLETON_GETTER() 2015-01-12 12:10:03 +01:00
Thomas Haller
fc575d6783 core: declare nm_dhcp_manager_get() using NM_DEFINE_SINGLETON_GETTER() 2015-01-12 12:10:03 +01:00
Thomas Haller
e439637ada core: declare nm_dns_manager_get() using NM_DEFINE_SINGLETON_GETTER() 2015-01-12 12:10:02 +01:00
Pavel Šimerda
eb2eda4408 main: don't initialize the session monitor
The session monitor will be initialized as soon as it's needed.

Acked-By: Thomas Haller <thaller@redhat.com>
2015-01-05 18:39:41 +01:00
Dan Winship
543416e5f6 libnm-core: add _nm_utils_is_manager_process
Add a variable indicating whether the process is the NetworkManager
daemon.
2014-11-15 09:48:42 -05:00
Dan Winship
3bfb163a74 all: consistently include config.h
config.h should be included from every .c file, and it should be
included before any other include. Fix that.

(As a side effect of how I did this, this also changes us to
consistently use "config.h" rather than <config.h>. To the extent that
it matters [which is not much], quotes are more correct anyway, since
we're talking about a file in our own build tree, not a system
include.)
2014-11-13 17:18:42 -05:00
Dan Williams
5149fd120d iface-helper: add nm-iface-helper for dynamic configure-then-quit support
When quitting, the Manager asks each device to spawn the interface helper,
which persists and manages dynamic address on the interface after NetworkManager
is gone.  If the dynamic address cannot be maintaned, the helper quits and
the interface's address may be removed when their lifetime runs out.

To keep the helper as simple as possible, NetworkManager passes most of the
configuration on the command-line, including some properties of the device's
current state, which are necessary for the helper to maintain DHCP leases
or IPv6 SLAAC addresses.
2014-11-07 12:18:33 -06:00
Dan Williams
a01e2ff91d core: add option to quit when startup is complete (rh #863515) (rh #1083683)
Cloud setups often have a never-changing setup and since every cycle counts,
they don't really want a management process running in the background after
network setup is complete.  Since it's likely a VM, it's not like links
are going to go up/down very often.

Add a new "configure-quit=true/false" config option which, when set to true,
will quit NetworkManager after startup and initial configuration is complete.
2014-11-07 12:18:33 -06:00
Dan Williams
ee25503636 core: split signal/pidfile/option handling into separate source file
We'll use this from more than one spot.
2014-11-07 12:18:32 -06:00
Thomas Haller
20085b9da8 core: ignore SIGPIPE
Ignoring SIGPIPE signal, otherwise it causes problems.

For example, running `NetworkManager --debug 2>&1 | tee log.txt` in a
terminal and killing it with CTRL+C (SIGINT), will abruplty terminate
NetworkManager without clean shutdown.
Note, that with this patch and above example, NetworkManager will both
receive SIGINT and SIGPIPE. Since we now ignore SIGPIPE, NetworkManager
will shut down cleanly. Any logging output after killing `tee` is of
lost however.

Also, there might be other cases where NM reads/writes to a pipe/socket
and unexpectedly received SIGPIPE. For example nm-dns-manager.c
spawns netconfig (run_netconfig()) and writes the configuration
to its stdin. If netconfig dies, the write might fail with EPIPE.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-10-27 20:42:37 +01:00
Thomas Haller
eabe7d856c auth: rework polkit autorization to use DBUS interface directly
This makes NetworkManager independent of <polkit/polkit.h>
development headers and libpolkit-gobject-1.so library.
Instead communicate directly with polkit using its DBUS
interface.

PolicyKit support is now always compiled in. You can control
polkit authorization with the configuration option
  [main]
  auth-polkit=yes|no

If the configure option is omitted, a build time default
value is used. This default value can be set with the
configure option --enable-polkit.

This commit adds a new class NMAuthManager that reimplements the
relevant DBUS client parts. It takes source code from the polkit
library.

https://bugzilla.gnome.org/show_bug.cgi?id=734146

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-09-29 13:51:11 +02:00
Dan Winship
3ddce74803 libnm: rename NetworkManager.h and NetworkManagerVPN.h
"NetworkManager.h"'s name (and non-standard capitalization) suggest
that it's some sort of high-level super-important header, but it's
really just low-level D-Bus stuff. Rename it to "nm-dbus-interface.h"
and likewise "NetworkManagerVPN.h" to "nm-vpn-dbus-interface.h"
2014-08-01 14:34:40 -04:00
Dan Winship
3ac0f52878 libnm, core, cli, tui: fix the capitalization of various types
GLib/Gtk have mostly settled on the convention that two-letter
acronyms in type names remain all-caps (eg, "IO"), but longer acronyms
become initial-caps-only (eg, "Tcp").

NM was inconsistent, with most long acronyms using initial caps only
(Adsl, Cdma, Dcb, Gsm, Olpc, Vlan), but others using all caps (DHCP,
PPP, PPPOE, VPN). Fix libnm and src/ to use initial-caps only for all
three-or-more-letter-long acronyms (and update nmcli and nmtui for the
libnm changes).
2014-08-01 14:34:06 -04:00
Dan Winship
b28f6526c2 core: fill in nm-types.h, clean out other headers
Clean up some of the cross-includes between headers (which made it so
that, eg, if you included NetworkManagerUtils.h in a test program, you
would need to build the test with -I$(top_srcdir)/src/platform, and if
you included nm-device.h you'd need $(POLKIT_CFLAGS)) by moving all
GObject struct definitions for src/ and src/settings/ into nm-types.h
(which already existed to solve the NMDevice/NMActRequest circular
references).

Update various .c files to explicitly include the headers they used to
get implicitly, and remove some now-unnecessary -I options from
Makefiles.
2014-07-23 10:56:26 -04:00
Thomas Haller
7a5af89f0b core: #include gsystem-local-alloc.h instead of libgsystem.h
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-07-15 22:47:43 +02:00
Dan Williams
5150cb88c2 dispatcher: only dispatch if scripts exist
If there are no dispatcher scripts, don't bother dispatching any
events.  This saves some time configuring networking if the event
would have no effect anyway.
2014-06-06 13:43:45 -05:00
Jiří Klimeš
98ae6e06d2 all: g_type_init() has been deprecated in GLib 2.35.0
g_type_init() deprecation:
https://bugzilla.gnome.org/show_bug.cgi?id=686161
2014-05-27 16:58:21 +02:00
Dan Williams
b732240026 core: remove the HostnameProvider interface
It's only used to keep the DHCPManager up-to-date with hostname changes,
and that can be accomplished in much less code by just having NMManager
set a hostname on the DHCPManager itself.
2014-05-09 15:33:32 -05:00
Dan Williams
d336a78a0e core: don't ref/unref the DHCP manager
It's a singleton anyway, so no need to ref/unref it.  Just use it.
2014-05-09 15:33:32 -05:00
Dan Williams
429023b24e policy: remove old /etc/hosts cleaning code (bgo #729689)
NetworkManager stopped touching /etc/hosts in late 2010 before the
NetworkManager 0.8.1 release.  The code in nm-policy-hosts.c's only
purpose is to remove any of the entries that NetworkManager added long
ago.

I think we're at the point where people have already upgraded to
NetworkManager 0.8.1 or later and thus this code would be a NOP.  The
only risk is that some stale /etc/hosts entries will be left if you
upgrade from NM 0.8 or lower to anything higher than that.

FWIW, Ubuntu Lucid (10.04) ships NM 0.8.0 and SLES11 ships NM 0.7.0, so
if users of these distros upgraded to a later NetworkManager they might
run into the stale entries issue if we remove this code from NM.  But
given how old these distros are, it seems unlikely that users will do a
direct upgrade to something 4+ years newer...

https://bugzilla.gnome.org/show_bug.cgi?id=729689
2014-05-08 15:09:59 -05:00
Thomas Haller
4a22cefc6c core: add configuration main.debug and interpret environment variable NM_DEBUG
Interpret the configuration option main.debug and the
environment variable NM_DEBUG as a comma separated list
of debugging options (parsed with g_parse_debug_string()).

Currently only the option "RLIMIT_CORE" is supported, to set
the core dump size to unlimited.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-05-02 11:08:14 +02:00
Dan Williams
fe6b86a078 core: don't ref the Manager singleton
The OLPC mesh code did rely on nm_manager_get() referencing the
singleton when returning it, but all other callers of nm_manager_get()
did not.  Thus the manager's refcount would always increase and
almost never decrease.  Fix the refcounting so that the manager
always has only one ref, and it's lifetime is controlled by
main() and nothing else.
2014-03-03 09:32:40 -06:00
Thomas Haller
d3a2219cee replace snprintf by g_snprintf
Use the glib wrapper for snprintf.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-02-24 21:35:33 +01:00
Guido Günther
0e8901fbd1 core: report which option is unknown
So far NetworkManager didn't tell which option it didn't know about:

  Invalid option.  Please use --help to see a list of valid options.

Now it is a bit more informative:

  Unknown option --asdf.  Please use --help to see a list of valid options.

The "Unknown option" string is marked as translatable in glib so i18n
doesn't suffer.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-02-15 11:50:07 +01:00