Commit graph

79 commits

Author SHA1 Message Date
Thomas Haller
acbdc30f90 logging: print debug messages with syslog level LOG_DEBUG 2016-05-24 21:53:27 +02:00
Thomas Haller
7f3ea16533 logging: add new logging domain LOGD_VPN_PLUGIN
This logging domain will be used to enable debugging of the VPN plugins.

However, the plugins might expose sensitive data in this mode, so exclude
the new domain from "LOGD_ALL".
2016-05-24 19:39:30 +02:00
Thomas Haller
a0130e4128 logging: add nm_logging_syslog_enabled() function
We want to know, whether running in debug-mode (logging to stdout)
or whether we log to syslog.
2016-05-24 19:39:30 +02:00
Thomas Haller
13101f8444 logging: add nm_logging_get_level() function 2016-05-24 19:39:25 +02:00
Thomas Haller
4ed1784ce4 logging: make nm_logging_enabled() inline function
Basically every logging statement is wrapped by a nm_logging_enabled()
to evaluate the function call of the logging lazy.

Make the function a candidate for inlining, it safes some space. On
a default build it goes for me from 2580584 to 2560104 bytes (20k).

   $ ./autogen.sh && make && strip ./src/NetworkManager
2016-05-20 12:50:52 +02:00
Thomas Haller
a9ef2f9c50 logging: move static variable with logging state to file-scope 2016-05-20 12:50:52 +02:00
Thomas Haller
1a070f6a44 logging: remove assertion in nm_logging_enabled() from production builds
We really expect this assertion not to be violated.

As we want for nm_logging_enabled() to become smaller and inline,
remove the runtime assertion from regular builds.

Live fast and dangerous.
2016-05-20 12:50:36 +02:00
Thomas Haller
553b04148a logging: drop explicit initialization of nm-logging
Instead of calling _ensure_initialized() at various places
to ensure that we setup logging before any logging commands
are executed, initialize the logging fields in the global variable.

This removes code from nm_logging_enabled(), which we want to
become a static inline function.
2016-05-20 12:41:47 +02:00
Thomas Haller
c75c51d505 logging: add new logging domain "SYSTEMD" for internal systemd logging 2016-03-17 15:00:48 +01:00
Thomas Haller
b49322b568 logging: use non-fatal logging level for glib backend
In our usage of glib logging, every g_critical()/g_return*()/g_warning()
is considered a bug. They must not occur in a regular program run,
so that we can run NetworkManager with G_DEBUG=fatal-warnings.

On the other hand, all nm_log() statements (even with severity <error>)
are valid conditions that can occur at runtime.

As a consequence, when nm-logging uses glib as backend, we must not use
G_LOG_LEVEL_WARNING level. Otherwise

  $ /usr/sbin/NetworkManager --debug --g-fatal-warnings

will dump core on the message

  "<warn> glib-version: cannot handle SIGUSR1 and SIGUSR2 signals. Consider upgrading glib to 2.36.0 or newer"

Thereby, downgrade the glib level for "<info>" to G_LOG_LEVEL_INFO.
2016-03-10 11:30:55 +01:00
Thomas Haller
b36d721525 all: drop str_if_set() in favor of the "?:" operator
str_if_set() was added to replace the non-standard gcc extension "?:".
However, "?:" is supported by clang as well and we already use it at
several places.

Also, str_if_set() did not follow our naming scheme and renaming to
nm_str_if_set() would be ugly. So just drop it.
2016-03-08 17:57:20 +01:00
Thomas Haller
4fb8cf35f4 logging: print timestamp only with msec precision 2016-03-01 15:22:59 +01:00
Thomas Haller
24582b65e1 logging: change logging format to drop "[file:line] func():" part
Choose a new logging format.

- the logging format must not be configurable and it must be the
  same for all backends. It is neat that journal supports additional
  fields, but an average user still posts the output of plain
  journalctl, without "--output verbose" (which would also be hard
  to read).
  Also, we get used to a certain logging format, so having different
  formats is confusing. If one format is better then another, it should
  be used for all backends: syslog, journal and debug.
  The only question is, what is the best format.

- the timestamp: I find it useful to see how much time between two
  events passed. The timestamp printed by syslog doesn't have sufficient
  granularity, and the internal journal fields are not readily available.
  We used to print the timestamps for <error>, <debug> and <trace>,
  but ommited them for <info> and <warn> levels. We now print them for
  all levels, which has a uniform alignment.

- the location: the "[file:line] func():" part is mostly redundant
  and results in wide lines. It also causes a misalignment of the
  logging lines, or -- as I recently added alignment of the location --
  it results in awkward whitespace and truncation.
  But the location is really just necessary because our logging messages
  are bad:
    "<debug> [1456397604.038226] (9) 11-dhclient succeeded"
  The solution to this is not
    "<debug> [1456397604.038226] [nm-dispatcher.c:358] dispatcher_results_process(): (9) 11-dhclient succeeded"
  but a properly worded message:
    "<debug> [1456397604.038226] dispatcher: request #9, script 11-dhclient succeeded"

- logging-message: we need to write better logging messages.
  I like some form of "tags" that are easy to grep:
    "platform: signal: link changed: 4: ..."
  Downside is, that this is not nice to read as a full sentence.
  So, especially for <info> and <warn> logging, more human readable
  messages are better.
  We should find a compromise, where the log message explains what
  happens, but is still concise and contains patterns that are easy
  to grep and identify visually.

https://mail.gnome.org/archives/networkmanager-list/2016-February/msg00077.html
2016-03-01 15:20:57 +01:00
Thomas Haller
51e292885c systemd/tests: add test util for systemd
Most interestingly is also, whether we can link libsystemd.a without
having undefined references (which might be wrongly satisfied by an
externally loaded libsystem shared library.
2016-03-01 12:42:42 +01:00
Thomas Haller
adb56d137e core: split "nm-core-utils.h" out of "NetworkManagerUtils.h"
"NetworkManagerUtils.h" contains a bunch of helper tools for core
daemon ("src/").

Unfortunately, it has dependencies to other parts of core,
such as "nm-device.h" and "nm-platform.h". Split out a part
of tools that are independent so that they can be used without
dragging in other dependencies.

"nm-core-utils.h" should only use libnm-core, "nm-logging.h"
and shared.

"NetworkManagerUtils.h" should provide all "nm-core-utils.h" and
possibly other utilities that have larger dependencies.
2016-03-01 12:42:42 +01:00
Thomas Haller
e4a7502a2c logging: make logging independent of platform
"nm-logging.h" is a basic core module that should have few other
dependencies. Instead of letting nm-logging.c directly call a function
from "nm-linux-platform.c", let platform register a handler as needed.

This way, you can build a core library containing nm-logging but no
nm-platform.
2016-03-01 12:42:42 +01:00
Thomas Haller
1b8cc4b9c5 logging: always print the timestamp and align location
Change the logging format. For syslog, we will now always
print the timestamp (also for <info> and <warn> messages).
Also, when printing the file location, we will always
align it.

For journal logging, also enable the timestamp. While the timestamp
is already captured separately by journal, most of the time a user
will look at the syslog like output from journal, so we want the
timestamps there too.
2016-02-21 18:37:49 +01:00
Thomas Haller
c01d1b0513 logging: add LOG_FORMAT_FLAG_ALIGN_LOCATION flag 2016-02-21 18:37:49 +01:00
Thomas Haller
1905862e26 logging: add logging-format-flags
No functional change.
2016-02-21 18:37:49 +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
e663b88c59 all/trivial: rename STRLEN() macro to NM_STRLEN()
We should not have defines/macros in header files without a nm/NM
prefix. STRLEN() was one of the few offenders.

https://mail.gnome.org/archives/networkmanager-list/2016-February/msg00048.html
2016-02-14 11:34:42 +01:00
Thomas Haller
04ec21ccc2 logging: add new logging macros _LOGx_err() to log errno
Not yet used, only implemented for nm-linux-platform.c as a
show case.

Use it like:

  _LOGW_err (errno, "failed to popen()");
2016-02-05 11:10:38 +01:00
Thomas Haller
6b0cb77b88 logging: properly use current domains when setting logging
When setting the logging with omitting the domains, we would
use the previously set logging domains. That was wrong since
the addition of the 'KEEP' level:

 (1) $ nmcli g l level INFO domains DNS,CORE
     $ nmcli g l
     LEVEL  DOMAINS
     INFO   DNS,CORE

 (2) $ nmcli g l level KEEP domains PPP:TRACE
     $ nmcli g l
     LEVEL  DOMAINS
     INFO   PPP:TRACE,DNS,CORE

 (3) $ nmcli g l level ERR
     $ nmcli g l
     LEVEL  DOMAINS
     ERR    PPP:TRACE

with this change, command (3) effectively translates to:

    $ nmcli g l level ERR domains PPP,DNS,CORE
    $ nmcli g l
    LEVEL  DOMAINS
    ERR    PPP,DNS,CORE
2015-10-09 14:58:03 +02:00
Thomas Haller
da776dd0bc logging: refactor global variable to have them in a struct
"nm-logging.c" uses several global variables. As their name doesn't
indicate that they are global variables, this is quite confusing.

Pack them all into a struct @global, which effectively puts the
variables into a separate namespace.
2015-10-09 14:58:03 +02:00
Thomas Haller
2f6978efb7 logging/trivial: move code 2015-10-09 14:58:03 +02:00
Thomas Haller
98e34208bd platform: warn about growing sysctl logging cache and clear it
When debug-logging for platform is enabled, every access to sysctl
is cached (to log the last values).

This cache can grow quite large if the system has a large number of
interfaces (e.g. docker creating veth pairs for each container).

We already used to clear the cache, when we were about to access
sysctl *and* logging was disabled in the meantime.

Now, when logging setup changes, immediately clear the cache.
Having "nm-logging.c" call into platform code is a bit of a hack
and a better design would be to have logging code emit a signal to
which platform would subscribe. But that seems to involve much
more code (especially, as no other users care about such a signal
and because nm-logging is not a GObject).

Also, log a warning when the cache grows large to inform the user
about the cache and what he can do to clear it. The extra effort to
clear the cache when changing logging setup is done so that we do
what we tell the user: changing the logging level, will clear the
cache -- right away, not some time later when the next message is
logged.
2015-10-09 14:56:50 +02:00
Thomas Haller
fd87ce503c logging: add special logging level "KEEP"
Without this, the user cannot configure only certain logging domains
without touching them all.

E.g.

  # nmcli general logging level DEBUG domains PLATFORM

will disable all non-PLATFORM domains.
Well, the user can do:

  # nmcli general logging level INFO domains PLATFORM:DEBUG
  # nmcli general logging level DEBUG domains ALL:INFO,PLATFORM

but in this case all non-PLATFORM domains are reset explicitly.

Now the user can:

  # nmcli general logging level KEEP domains PLATFORM:DEBUG
  # nmcli general logging level DEBUG domains ALL:KEEP,PLATFORM

which will only change the platform domain.
2015-10-09 14:55:00 +02:00
Thomas Haller
d6370d09e6 logging: coerce negative error values to positive errno
Especially systemd, which makes use of the error argument for logging, likes
to represent errors as negative numbers. We hence must invert a negative error
code to get the real errno.
2015-09-23 16:09:43 +02: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
8a4ad96ec1 logging: remove dummy logging domain "NONE"
"NONE" was wrongly part of @domain_descs and thus advertised
via `NetworkManager --help`. But since its @num was set to
LOGD_NONE (zero), it was already rejected by nm_logging_setup().
2015-08-04 11:21:57 +02:00
Thomas Haller
4e26ef55c6 logging: minor refactoring in nm_logging_setup() 2015-08-04 11:21:57 +02:00
Thomas Haller
8c3f1812ea logging: support an "OFF" logging level
The only way to disable logging for a domain entirely is to
omit the domain from the "domains" list. For example:

  "level=INFO, domains=PLATFORM,..."

Now add an explicit level "OFF" to facilitate configuration like:

  "level=INFO, domains=ALL,WIFI_SCAN:OFF"

It also supports
  "level=OFF, domains=PLATFORM:INFO"
but this is for the most part equivalent to
  "level=INFO, domains=PLATFORM"
2015-08-04 11:21:57 +02:00
Thomas Haller
655b85bfea logging: replace using _LOGL_N by G_N_ELEMENTS()
At various places we used _LOGL_N to check the index
before accessing one of our static arrays. Instead use
G_N_ELEMENTS().
2015-08-04 11:21:56 +02:00
Thomas Haller
d3b91eb258 logging/trivial: rename LOGL_MAX to _LOGL_N
The name LOGL_MAX was misleading, because it is not
the "maximum" logging level, but the number of different
levels. Rename it.
2015-08-04 11:21:48 +02:00
Beniamino Galvani
41e7051165 logging: add AUDIT domain 2015-08-04 08:46:11 +02: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
81f3c36f23 logging: refactor level conversion from switch() to @level_desc lookup-array 2015-07-14 15:55:14 +02:00
Thomas Haller
f7581bbedc logging: add compile time default for logging.backend configuration 2015-07-14 15:55:14 +02:00
Thomas Haller
533a08359e logging: add "journal-syslog-style" logging backend to log the old format
This mode logs the same message line as we do for "syslog".
2015-07-14 15:55:14 +02:00
Thomas Haller
96a7f3a3ba logging: make use of journal configurable 2015-07-14 15:55:14 +02:00
Thomas Haller
1b808d3b25 logging: add native systemd-journald support to nm-logging 2015-07-14 15:55:14 +02:00
Thomas Haller
b1b26e8049 logging: factor our construction of logging message in _nm_log_impl() 2015-07-14 15:52:50 +02:00
Thomas Haller
831a5e32fb logging: refactor @syslog_opened variable to @log_backend 2015-07-14 15:52:50 +02:00
Thomas Haller
d0345ede26 logging: allow calling nm_logging_syslog_openlog() only once 2015-07-14 15:52:50 +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
211d241ab0 logging/trivial: rename _nm_log() to _nm_log_impl()
The actual logging implementation is not supposed to be called
directly, because there are macros that capture the call site
information __FILE__, __LINE__, and G_STRFUNC.

Rename the function to make clear that this is the actual
implementation.
2015-04-22 11:06:49 +02:00
Dan Winship
721e917cb6 wimax: drop WiMAX support (bgo #747846)
Even Fedora is no longer shipping the WiMAX SDK, so it's likely we'll
eventually accidentally break some of the code in src/devices/wimax/
(if we haven't already). Discussion on the list showed a consensus for
dropping support for WiMAX.

So, remove the SDK checks from configure.ac, remove the WiMAX device
plugin and associated manager support, and deprecate all the APIs.

For compatibility reasons, it is still possible to create and save
WiMAX connections, to toggle the software WiMAX rfkill state, and to
change the "WIMAX" log level, although none of these have any effect,
since no NMDeviceWimax will ever be created.

nmcli was only compiling in support for most WiMAX operations when NM
as a whole was built with WiMAX support, so that code has been removed
now as well. (It is still possible to use nmcli to create and edit
WiMAX connections, but those connections will never be activatable.)
2015-04-17 12:42:23 -04:00
Thomas Haller
5162426d41 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".
2015-03-02 14:22:09 +01:00
Thomas Haller
670eb57321 logging: assert that NMLogDomains compiles to a 64 bit enum
Enum types larger then the native 'int' type are undefined behavior
according to C standard. Assert that our compiler does the right thing.

  the expression that defines the value of an enumeration constant shall
  be an integer constant expression that has a value representable as an
  int
2015-01-26 16:30:27 +01:00