Commit graph

131 commits

Author SHA1 Message Date
Lubomir Rintel
24028a2246 all: SPDX header conversion
$ find * -type f |xargs perl contrib/scripts/spdx.pl
  $ git rm contrib/scripts/spdx.pl
2019-09-10 11:19:56 +02:00
Thomas Haller
c0e075c902 all: drop emacs file variables from source files
We no longer add these. If you use Emacs, configure it yourself.

Also, due to our "smart-tab" usage the editor anyway does a subpar
job handling our tabs. However, on the upside every user can choose
whatever tab-width he/she prefers. If "smart-tabs" are used properly
(like we do), every tab-width will work.

No manual changes, just ran commands:

    F=($(git grep -l -e '-\*-'))
    sed '1 { /\/\* *-\*-  *[mM]ode.*\*\/$/d }'     -i "${F[@]}"
    sed '1,4 { /^\(#\|--\|dnl\) *-\*- [mM]ode/d }' -i "${F[@]}"

Check remaining lines with:

    git grep -e '-\*-'

The ultimate purpose of this is to cleanup our files and eventually use
SPDX license identifiers. For that, first get rid of the boilerplate lines.
2019-06-11 10:04:00 +02:00
Thomas Haller
f8cbf06a77 logging: use stack allocated string buffer to constuct NM_LOG_DOMAINS field
NM_LOG_DOMAINS is a comma-separated list of the selected logging domains.

As the number of all logging domains is fixed at compile-time, the maximum
length of the buffer is known.

  $ git grep $'^\t{ LOGD_' | sed 's/.*"\(.*\)" .*/\1/' | xargs | sed 's/  */,/g' | sed 's/^/NM_LOG_DOMAINS=/'
  NM_LOG_DOMAINS=PLATFORM,RFKILL,ETHER,WIFI,BT,MB,DHCP4,DHCP6,PPP,WIFI_SCAN,IP4,IP6,AUTOIP4,DNS,VPN,SHARING,SUPPLICANT,AGENTS,SETTINGS,SUSPEND,CORE,DEVICE,OLPC,INFINIBAND,FIREWALL,ADSL,BOND,VLAN,BRIDGE,DBUS_PROPS,TEAM,CONCHECK,DCB,DISPATCH,AUDIT,SYSTEMD,VPN_PLUGIN,PROXY

Note that the static buffer "_all_logging_domains_to_str" is known
to be large enough to contain these domain names (it's even longer,
as it also contains "ALL", "IP", and "DHCP" alises). We can use that
to define the array of suitable size.
2019-05-17 21:12:38 +02:00
Thomas Haller
9cddb9f8bd logging: use static buffer in nm_logging_all_domains_to_string()
Don't create a heap allocated GString to hold the static
result of nm_logging_all_domains_to_string().

Instead, use a static buffer of the exactly required size.

The main reason to do this, is to get the exact size of
"_all_logging_domains_to_str" buffer. This is the upper
boundary for the size of a string buffer to hold all domain
names.
We will need that boundary in the next commit. The attractive
thing here is that we will have a unit-test failure if this
boundery no longer matches (--with-more-asserts). That means,
this boundary is guarded by unit tests and we don't accidentally
get it wrong when the domains change.

Also, take care to initialize the buffer in a thread-safe manner.
It's easy enough to get right, so there is no excuse for having
non-thread-safe code in logging.
2019-05-17 21:12:38 +02:00
Thomas Haller
cc2553e871 logging: don't misuse SYSLOG_FACILITY field in journal
Syslog's "facility" is a well defined thing and must be
one of a few well-known numbers. Don't re-use it for our
own purposes.

Fixes: 1b808d3b25 ('logging: add native systemd-journald support to nm-logging')

https://bugzilla.redhat.com/show_bug.cgi?id=1709741
2019-05-17 21:12:38 +02:00
Thomas Haller
467ac96dd1 logging: use char pointer for iov_free in _nm_log_impl() 2019-05-17 21:09:20 +02:00
Thomas Haller
138c187376 logging: fix stack overflow in logging for iov_data array
This overflow could only happen when we would try to log a message
with "NM_DEVICE=", "NM_CONNECTION=", and more than 8 logging domains
(_NUM_MAX_FIELDS_SYSLOG_FACILITY - 2).

The latter is never the case. While we sometimes log messages with
more than one logging domain, there are no logging statements that
use most as 8 different logging domains. So, this overflow is not
actually reachable from current code (I think).

Fixes: ed552c732c ('logging: log device and connection along with the message'):
2019-05-17 21:08:34 +02:00
Thomas Haller
8decdf2225 shared: add nm_log_level_from_syslog() helper to convert from syslog levels 2019-05-07 16:41:21 +02:00
Thomas Haller
d984b2ce4a shared: move most of "shared/nm-utils" to "shared/nm-glib-aux"
From the files under "shared/nm-utils" we build an internal library
that provides glib-based helper utilities.

Move the files of that basic library to a new subdirectory
"shared/nm-glib-aux" and rename the helper library "libnm-core-base.la"
to "libnm-glib-aux.la".

Reasons:

 - the name "utils" is overused in our code-base. Everything's an
   "utils". Give this thing a more distinct name.

 - there were additional files under "shared/nm-utils", which are not
   part of this internal library "libnm-utils-base.la". All the files
   that are part of this library should be together in the same
   directory, but files that are not, should not be there.

 - the new name should better convey what this library is and what is isn't:
   it's a set of utilities and helper functions that extend glib with
   funcitonality that we commonly need.

There are still some files left under "shared/nm-utils". They have less
a unifying propose to be in their own directory, so I leave them there
for now. But at least they are separate from "shared/nm-glib-aux",
which has a very clear purpose.

(cherry picked from commit 80db06f768)
2019-04-18 19:57:27 +02:00
Thomas Haller
3e0366a3ff all: replace g_strsplit_set() by nm_utils_strsplit_set*() 2019-04-10 15:05:57 +02:00
Lubomir Rintel
4251f4e476 all: codespell fixes
Codespel run with the same arguments as described in
commit 58510ed566 ('docs: misc. typos pt2').

(cherry picked from commit bf0c4e6ac2)
2019-03-11 12:03:46 +01:00
Thomas Haller
047998f80a all: cache errno in local variable before using it 2019-02-12 08:50:28 +01:00
Thomas Haller
a3370af3a8 all: drop unnecessary includes of <errno.h> and <string.h>
"nm-macros-interal.h" already includes <errno.h> and <string.h>.
No need to include it everywhere else too.
2019-02-12 08:50:28 +01:00
Thomas Haller
fcfd4f4ff2 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-02-05 08:18:08 +01:00
Thomas Haller
834c092b51 logging: avoid accessing global data from helper functions
We need to see where we modify/access global data. Instead of letting
helper functions access global data, pass it as arguments.
2019-02-05 08:18:08 +01:00
Thomas Haller
729feb0a93 logging: refactor and merge early logging initialization
Instead of having two functions nm_logging_set_syslog_identifier()
and nm_logging_set_prefix(), merge them.

They must both be called at earliest point and together. No point
in giving them the appearance that they could be called any time.
2019-02-05 08:18:08 +01:00
Thomas Haller
83338428d9 logging: move global "logging_domains_to_string" variable
This variable has other requirements for multi-threaded access (it will
only be accessible from the main-thread). Move it to a separate global
variable to make that clearer.
2019-02-05 08:18:08 +01:00
Thomas Haller
5e2202f41f logging: refactor globals in "nm-logging.c" to see where global gets modified
The distinction between only reading static data and modifying it,
is important when making nm-logging thread-safe.

This change should make it easier to find the places where we modify
data.
2019-02-05 08:18:08 +01:00
Thomas Haller
db2d6a1808 logging: cleanup type definition and global variables
First define types, then declare global variables.

Reorder the code.
2019-02-05 08:18:07 +01:00
Thomas Haller
eea11faf9a logging: split out enum type definition for LogBackend 2019-02-05 08:18:07 +01:00
Thomas Haller
8dcc3cd51a logging: split out @level_desc and @domain_desc variables from global data
@level_desc and @domain_desc are two immutable arrays with information
about logging levels and logging domains. Since they are immutable and
intialized from the start, they are pretty trival w.r.t. tread-safety and
general maintainability (code readability).

Refactor them to be separate variables.
2019-02-05 08:18:07 +01:00
Thomas Haller
ba1bf0390d logging: make _nm_logging_clear_platform_logging_cache() a regular function
Previously, _nm_logging_clear_platform_logging_cache was an extern variable,
and NMLinuxPlatform would set it to a function pointer at certain points.

That's unnecessary complex, also when trying to make nm-logging thread-safe,
it's just more global variables that need to be considered. Don't do it
that way, but just link in a regular function.
2019-02-05 08:18:07 +01:00
Thomas Haller
3263cab596 all: add static assertion for maximumg alloca() allocated buffer
Add a compile time check that the buffer that we allocate on the stack
is reasonably small.
2019-01-15 09:52:01 +01:00
Thomas Haller
ef53b47e7c shared,core: move logging enums to header "shared/nm-utils/nm-logging-fwd.h"
In core ("src/"), we use "nm-logging.h" for all logging. This dispatches
for logging to syslog, glog or systemd-journald.

If we want to log from a shared component under "shared/", we need to
use a common logging function. Add "nm-utils/nm-logging-fwd.h" for
forward declaring the used logging mechaism.

The shared library will still need to link with "src/nm-logging.c"
or an alternative implementation, depending on whether it is used
inside core or not.
2019-01-02 11:51:42 +01:00
Thomas Haller
32073288e8 shared: thread safe initialization of nm_utils_get_monotonic_timestamp*()
nm_utils_get_monotonic_timestamp*() inherrently use static data. Let's
initialize it in a thread safe manner.

nm_utils_get_monotonic_timestamp*() are a fundamental utility function
that should work correctly in all cases. Such a low level function should
be thread safe.
2018-11-28 16:13:04 +01:00
Thomas Haller
636516e708 logging: make nm-logging.c independent of other core components
"nm-logging.c" now no longer depends on anything particularly special
from NM core.
2018-10-18 12:16:55 +02:00
Thomas Haller
a6add8175a shared: move nm_utils_get_monotonic_timestamp*() to shared/nm-utils.
This is independent functionality that only depends on linux API
and glib.

Note how "nm-logging" uses this for getting the timestamps. This
makes "nm-logging.c" itself dependen on "src/nm-core-utils.c",
for little reason.
2018-10-18 12:16:55 +02:00
Thomas Haller
884ed15261 core: move logging of monotonic-timestamp to "nm-logging.c"
This makes monotonic-timestamp handling independent of "nm-logging.c".
2018-10-18 12:16:55 +02:00
Thomas Haller
e1c7a2b5d0 all: don't use gchar/gshort/gint/glong but C types
We commonly don't use the glib typedefs for char/short/int/long,
but their C types directly.

    $ git grep '\<g\(char\|short\|int\|long\|float\|double\)\>' | wc -l
    587
    $ git grep '\<\(char\|short\|int\|long\|float\|double\)\>' | wc -l
    21114

One could argue that using the glib typedefs is preferable in
public API (of our glib based libnm library) or where it clearly
is related to glib, like during

  g_object_set (obj, PROPERTY, (gint) value, NULL);

However, that argument does not seem strong, because in practice we don't
follow that argument today, and seldomly use the glib typedefs.
Also, the style guide for this would be hard to formalize, because
"using them where clearly related to a glib" is a very loose suggestion.

Also note that glib typedefs will always just be typedefs of the
underlying C types. There is no danger of glib changing the meaning
of these typedefs (because that would be a major API break of glib).

A simple style guide is instead: don't use these typedefs.

No manual actions, I only ran the bash script:

  FILES=($(git ls-files '*.[hc]'))
  sed -i \
      -e 's/\<g\(char\|short\|int\|long\|float\|double\)\>\( [^ ]\)/\1\2/g' \
      -e 's/\<g\(char\|short\|int\|long\|float\|double\)\>  /\1   /g' \
      -e 's/\<g\(char\|short\|int\|long\|float\|double\)\>/\1/g' \
      "${FILES[@]}"
2018-07-11 12:02:06 +02:00
Thomas Haller
dbd48f260e logging: warn about invalid logging backends and drop "debug" backend
"debug" was documentation in `man NetworkManager.conf` as a valid
logging backend. However, it was completely ignored by
nm_logging_syslog_openlog().
In fact, it makes not sense. Passing debug = TRUE to
nm_logging_syslog_openlog(), means that all messages will be
printed to stderr in addition to syslog/journal. However, when
NetworkManager is daemonizing, stderr is closed.
Whether NetworkManager is daemonizing depends entirely on command
line options --no-daemon and --debug. Hence, the logging backend "debug"
from the configuration file either conflicts or is redundant.

Also, adjust logging backend description in `man NetworkManager.conf`.

Also, log a warning about invalid/unsupported logging backend.

(cherry picked from commit 2ccf6168dc)
2018-06-27 09:21:33 +02:00
Thomas Haller
a64b424da3 logging/trivial: add code comment about logging-backend
(cherry picked from commit 504ad2aeed)
2018-06-27 09:21:33 +02:00
Thomas Haller
1b83cab13b logging: move fetching monotonic timestamp to end of nm_logging_syslog_openlog()
It just makes more sense to first fully setup logging, and then fetching
the timestamp. In practice, the effect previously was very similar.

(cherry picked from commit 2912155584)
2018-06-27 09:21:33 +02:00
Thomas Haller
e6f15f26eb core/logging: with --debug also output glib messages in stderr
With --debug, we duplicate nm-log messages to stderr. Do the same
for glib messages and don't only send them to syslog/journal.
2018-02-07 13:41:52 +01:00
Thomas Haller
c696a226ea all: don't use NM_FLAGS_HAS() with non-constant argument
NM_FLAGS_HAS() uses a static-assert that the second argument is a
single flag (power of two). With a single flag, NM_FLAGS_HAS(),
NM_FLAGS_ANY() and NM_FLAGS_ALL() are all identical.

The second argument must be a compile time constant, and if that is
not the case, one must not use NM_FLAGS_HAS().

Use NM_FLAGS_ANY() in these cases.
2017-12-15 11:48:38 +01:00
Lubomir Rintel
ed552c732c logging: log device and connection along with the message 2017-03-24 12:42:09 +01:00
Lubomir Rintel
03a3fd9014 logging: respect choice of journal/syslog even with --debug
Previously, the daemon would just use syslog with LOG_PERROR when run with
--debug option, even when actually configured to log into the journal.
Let's respect the configuration, but preserve the logging to stderr.
2017-03-24 12:42:09 +01:00
Thomas Haller
215c50922d logging: preserve errno in logging functions
It would be nice that our logging functions are guaranteed to
preserve errno. We are currently not very consistent about handling
errno, let's improve on that.
2016-12-13 11:26:58 +01:00
Thomas Haller
afcfa7be2b config/trivial: unify name of compile time config defaults 2016-11-25 18:02:38 +01:00
Thomas Haller
64e02a0ac7 logging: protect VPN_PLUGIN logging domain
VPN_PLUGIN is special. With
  # nmcli general logging level TRACE domains ALL
the logging verbosity of VPN_PLUGIN domain should not be set higher then
info. The user has to explicitly set it via:
  # nmcli general logging level TRACE domains ALL,VPN_PLUGIN:TRACE

This was not the case for
  # nmcli general logging level TRACE

Fix that.
2016-10-11 11:29:52 +02:00
Thomas Haller
f43b21b71d logging: avoid some heap allocations constructing journal logging data 2016-10-11 11:29:52 +02:00
Thomas Haller
7f478f86ca logging: avoid copy of logging message fo syslog and glib logging backend
As both syslog() and g_log() accept a format string, we should not
create fullmsg ahead. This saves an additional clone of the message.
2016-10-11 11:29:52 +02:00
Lubomir Rintel
1c0e9ae7d6 logging: fix a warning when built without journald
nm-logging.c:213:1: error: ‘syslog_identifier_full’ defined but not used [-Werror=unused-function]
 syslog_identifier_full (const struct Global *gl)
 ^

Fixes: fd12aa1b20
2016-10-11 10:42:22 +02:00
Thomas Haller
fd12aa1b20 logging: allow setting the syslog-identifier not to use G_LOG_DOMAIN
For nm-iface-helper we want to use a different syslog-identifier then
"NetworkManager".

Since we build "nm-logging.c" as part of libNetworkManagerBase.la,
it would be cumbersome to compile the logging part multiple times
with different -DG_LOG_DOMAIN settings.

Instead, allow configuring at runtime.
2016-10-06 13:31:34 +02:00
Thomas Haller
06b3b06a95 logging: support system-wide prefix
Will be used by nm-iface-helper.
2016-10-05 15:34:45 +02:00
Atul Anand
fd0b9ab583 src:(pacrunner-manager): Object for interaction with PacRunner
A new object NMPacRunnerManager has been added to manage and interact
PacRunner. It invokes both DBus methods on PacRunner DBus interface.
It stores the returned object path from CreateProxyConfiguration()
to feed as parameter to DestroyProxyCofiguration() when network goes down.
2016-10-04 11:44:13 +02:00
Thomas Haller
a83eb773ce all: modify line separator comments to be 80 chars wide
sed 's#^/\*\{5\}\*\+/$#/*****************************************************************************/#' $(git grep -l '\*\{5\}' | grep '\.[hc]$') -i
2016-10-03 12:01:15 +02:00
Thomas Haller
c1b4b99a3c logging: don't round subsecond part in logging timestamp
tv.tv_usec is guaranteed to have less then 6 digits, however rounding it up
we might reach 1000000 and thus the value becomes mis-aligned. To round
correctly, we would have to carry over a potential overflow to the seconds.
But that seems too much effort for little gain. Just truncate the value.
2016-09-08 00:21:21 +02:00
Thomas Haller
4023659ee1 logging: remove unused formatting options
Previously, we logged also the location (file:line func). nm-logging.c
supported format flags to control the timestamp, the location, and alignment
of the timestamp.

We want that all our logging backends log the same messages. That is,
both syslog and journal should have our ~default~ logging format, that
is with timestamp but without location.

Drop the unused code.

(cherry picked from commit cc828431b8)
2016-08-19 12:32:30 +02:00
Thomas Haller
3d30004710 build: cleanup src/Makefile.am
- reorder entries in src/Makefile.am so that general names
  are all at the beginning (AM_CPPFLAGS, sbin_PROGRAMS)
  and the names for a certain library/binary are grouped
  together
- have libNetworkManager.la reuse libNetworkManagerBase.la.
- let all components in src/Makefile.am use the same AM_CPPFLAGS,
  except libsystem-nm.la.
- move callouts/nm-dispatcher-api.h to shared/ directory. It
  is obviously not internal API to callouts, and callouts is
  not a library. Thus, the right place is shared/.
2016-08-11 11:54:18 +02:00
Thomas Haller
8583791eb3 logging: don't log the function name
The function name is no longer visible in the default
logging output. It is anyway only used together with
journal logging to set "CODE_FUNC".

Drop it. It allows to remove the strings from the binary,
which decreases the object size of a default build of NetworkManager
from 2437400 to 2412824 bytes (-24k, -1%).
2016-07-05 23:08:06 +02:00