2008-11-03 04:13:42 +00:00
|
|
|
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
2006-02-27 04:31:52 +00:00
|
|
|
/* NetworkManager -- Network link manager
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
2008-06-26 18:31:52 +00:00
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2006-02-27 04:31:52 +00:00
|
|
|
*
|
2012-10-31 17:19:38 +01:00
|
|
|
* Copyright (C) 2006 - 2012 Red Hat, Inc.
|
2008-11-03 04:13:42 +00:00
|
|
|
* Copyright (C) 2006 - 2008 Novell, Inc.
|
2006-02-27 04:31:52 +00:00
|
|
|
*/
|
|
|
|
|
|
2016-02-19 14:57:48 +01:00
|
|
|
#include "nm-default.h"
|
2011-03-14 01:00:56 -05:00
|
|
|
|
2018-10-12 17:07:25 +02:00
|
|
|
#include "nm-logging.h"
|
|
|
|
|
|
2009-08-21 12:16:17 -05:00
|
|
|
#include <dlfcn.h>
|
2006-02-27 04:31:52 +00:00
|
|
|
#include <syslog.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include <sys/wait.h>
|
|
|
|
|
#include <sys/stat.h>
|
2010-04-06 15:23:08 -07:00
|
|
|
#include <strings.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
2015-07-08 16:21:21 +02:00
|
|
|
#if SYSTEMD_JOURNAL
|
|
|
|
|
#define SD_JOURNAL_SUPPRESS_LOCATION
|
|
|
|
|
#include <systemd/sd-journal.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2018-10-12 17:07:25 +02:00
|
|
|
#include "nm-utils/nm-time-utils.h"
|
2014-10-16 16:47:30 -04:00
|
|
|
#include "nm-errors.h"
|
2006-02-27 04:31:52 +00:00
|
|
|
|
2019-01-15 17:54:51 +01:00
|
|
|
/*****************************************************************************/
|
2013-06-14 14:51:04 -04:00
|
|
|
|
2019-01-15 17:54:51 +01:00
|
|
|
/* We have more then 32 logging domains. Assert that it compiles to a 64 bit sized enum */
|
|
|
|
|
G_STATIC_ASSERT (sizeof (NMLogDomain) >= sizeof (guint64));
|
|
|
|
|
|
|
|
|
|
/* Combined domains */
|
|
|
|
|
#define LOGD_ALL_STRING "ALL"
|
|
|
|
|
#define LOGD_DEFAULT_STRING "DEFAULT"
|
|
|
|
|
#define LOGD_DHCP_STRING "DHCP"
|
|
|
|
|
#define LOGD_IP_STRING "IP"
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2010-04-06 15:23:08 -07:00
|
|
|
|
2019-01-15 17:49:52 +01:00
|
|
|
typedef enum {
|
|
|
|
|
LOG_BACKEND_GLIB,
|
|
|
|
|
LOG_BACKEND_SYSLOG,
|
|
|
|
|
LOG_BACKEND_JOURNAL,
|
|
|
|
|
} LogBackend;
|
|
|
|
|
|
2019-01-15 17:54:51 +01:00
|
|
|
typedef struct {
|
|
|
|
|
NMLogDomain num;
|
|
|
|
|
const char *name;
|
|
|
|
|
} LogDesc;
|
|
|
|
|
|
2015-07-09 13:55:51 +02:00
|
|
|
typedef struct {
|
|
|
|
|
const char *name;
|
|
|
|
|
const char *level_str;
|
2016-05-24 19:46:33 +02:00
|
|
|
|
|
|
|
|
/* nm-logging uses syslog internally. Note that the three most-verbose syslog levels
|
|
|
|
|
* are LOG_DEBUG, LOG_INFO and LOG_NOTICE. Journal already highlights LOG_NOTICE
|
|
|
|
|
* as special.
|
|
|
|
|
*
|
|
|
|
|
* On the other hand, we have three levels LOGL_TRACE, LOGL_DEBUG and LOGL_INFO,
|
|
|
|
|
* which are regular messages not to be highlighted. For that reason, we must map
|
|
|
|
|
* LOGL_TRACE and LOGL_DEBUG both to syslog level LOG_DEBUG. */
|
2015-07-09 13:55:51 +02:00
|
|
|
int syslog_level;
|
2016-05-24 19:46:33 +02:00
|
|
|
|
2015-07-09 13:55:51 +02:00
|
|
|
GLogLevelFlags g_log_level;
|
|
|
|
|
} LogLevelDesc;
|
|
|
|
|
|
2019-01-15 17:54:51 +01:00
|
|
|
typedef struct {
|
2015-10-07 11:07:09 +02:00
|
|
|
NMLogLevel log_level;
|
2016-05-23 12:02:31 +02:00
|
|
|
bool uses_syslog:1;
|
2016-10-05 15:52:55 +02:00
|
|
|
bool syslog_identifier_initialized:1;
|
2017-03-01 13:34:32 +01:00
|
|
|
bool debug_stderr:1;
|
2016-10-05 15:25:08 +02:00
|
|
|
const char *prefix;
|
2016-10-05 15:52:55 +02:00
|
|
|
const char *syslog_identifier;
|
2019-01-15 17:49:52 +01:00
|
|
|
|
|
|
|
|
/* before we setup syslog (during start), the backend defaults to GLIB, meaning:
|
|
|
|
|
* we use g_log() for all logging. At that point, the application is not yet supposed
|
|
|
|
|
* to do any logging and doing so indicates a bug.
|
|
|
|
|
*
|
|
|
|
|
* Afterwards, the backend is either SYSLOG or JOURNAL. From that point, also
|
|
|
|
|
* g_log() is redirected to this backend via a logging handler. */
|
|
|
|
|
LogBackend log_backend;
|
|
|
|
|
|
2015-10-07 11:07:09 +02:00
|
|
|
char *logging_domains_to_string;
|
2019-01-15 17:54:51 +01:00
|
|
|
} Global;
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
static Global global = {
|
2016-05-19 18:57:18 +02:00
|
|
|
/* nm_logging_setup ("INFO", LOGD_DEFAULT_STRING, NULL, NULL); */
|
2015-10-07 11:07:09 +02:00
|
|
|
.log_level = LOGL_INFO,
|
|
|
|
|
.log_backend = LOG_BACKEND_GLIB,
|
2016-10-05 15:52:55 +02:00
|
|
|
.syslog_identifier = "SYSLOG_IDENTIFIER="G_LOG_DOMAIN,
|
2016-10-05 15:25:08 +02:00
|
|
|
.prefix = "",
|
2019-01-15 16:58:15 +01:00
|
|
|
};
|
|
|
|
|
|
2019-01-15 17:54:51 +01:00
|
|
|
NMLogDomain _nm_logging_enabled_state[_LOGL_N_REAL] = {
|
|
|
|
|
/* nm_logging_setup ("INFO", LOGD_DEFAULT_STRING, NULL, NULL);
|
|
|
|
|
*
|
|
|
|
|
* Note: LOGD_VPN_PLUGIN is special and must be disabled for
|
|
|
|
|
* DEBUG and TRACE levels. */
|
|
|
|
|
[LOGL_INFO] = LOGD_DEFAULT,
|
|
|
|
|
[LOGL_WARN] = LOGD_DEFAULT,
|
|
|
|
|
[LOGL_ERR] = LOGD_DEFAULT,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2019-01-15 16:58:15 +01:00
|
|
|
static const LogLevelDesc level_desc[_LOGL_N] = {
|
|
|
|
|
[LOGL_TRACE] = { "TRACE", "<trace>", LOG_DEBUG, G_LOG_LEVEL_DEBUG, },
|
|
|
|
|
[LOGL_DEBUG] = { "DEBUG", "<debug>", LOG_DEBUG, G_LOG_LEVEL_DEBUG, },
|
|
|
|
|
[LOGL_INFO] = { "INFO", "<info>", LOG_INFO, G_LOG_LEVEL_INFO, },
|
|
|
|
|
[LOGL_WARN] = { "WARN", "<warn>", LOG_WARNING, G_LOG_LEVEL_MESSAGE, },
|
|
|
|
|
[LOGL_ERR] = { "ERR", "<error>", LOG_ERR, G_LOG_LEVEL_MESSAGE, },
|
|
|
|
|
[_LOGL_OFF] = { "OFF", NULL, 0, 0, },
|
|
|
|
|
[_LOGL_KEEP] = { "KEEP", NULL, 0, 0, },
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static const LogDesc domain_desc[] = {
|
|
|
|
|
{ LOGD_PLATFORM, "PLATFORM" },
|
|
|
|
|
{ LOGD_RFKILL, "RFKILL" },
|
|
|
|
|
{ LOGD_ETHER, "ETHER" },
|
|
|
|
|
{ LOGD_WIFI, "WIFI" },
|
|
|
|
|
{ LOGD_BT, "BT" },
|
|
|
|
|
{ LOGD_MB, "MB" },
|
|
|
|
|
{ LOGD_DHCP4, "DHCP4" },
|
|
|
|
|
{ LOGD_DHCP6, "DHCP6" },
|
|
|
|
|
{ LOGD_PPP, "PPP" },
|
|
|
|
|
{ LOGD_WIFI_SCAN, "WIFI_SCAN" },
|
|
|
|
|
{ LOGD_IP4, "IP4" },
|
|
|
|
|
{ LOGD_IP6, "IP6" },
|
|
|
|
|
{ LOGD_AUTOIP4, "AUTOIP4" },
|
|
|
|
|
{ LOGD_DNS, "DNS" },
|
|
|
|
|
{ LOGD_VPN, "VPN" },
|
|
|
|
|
{ LOGD_SHARING, "SHARING" },
|
|
|
|
|
{ LOGD_SUPPLICANT,"SUPPLICANT" },
|
|
|
|
|
{ LOGD_AGENTS, "AGENTS" },
|
|
|
|
|
{ LOGD_SETTINGS, "SETTINGS" },
|
|
|
|
|
{ LOGD_SUSPEND, "SUSPEND" },
|
|
|
|
|
{ LOGD_CORE, "CORE" },
|
|
|
|
|
{ LOGD_DEVICE, "DEVICE" },
|
|
|
|
|
{ LOGD_OLPC, "OLPC" },
|
|
|
|
|
{ LOGD_INFINIBAND,"INFINIBAND" },
|
|
|
|
|
{ LOGD_FIREWALL, "FIREWALL" },
|
|
|
|
|
{ LOGD_ADSL, "ADSL" },
|
|
|
|
|
{ LOGD_BOND, "BOND" },
|
|
|
|
|
{ LOGD_VLAN, "VLAN" },
|
|
|
|
|
{ LOGD_BRIDGE, "BRIDGE" },
|
|
|
|
|
{ LOGD_DBUS_PROPS,"DBUS_PROPS" },
|
|
|
|
|
{ LOGD_TEAM, "TEAM" },
|
|
|
|
|
{ LOGD_CONCHECK, "CONCHECK" },
|
|
|
|
|
{ LOGD_DCB, "DCB" },
|
|
|
|
|
{ LOGD_DISPATCH, "DISPATCH" },
|
|
|
|
|
{ LOGD_AUDIT, "AUDIT" },
|
|
|
|
|
{ LOGD_SYSTEMD, "SYSTEMD" },
|
|
|
|
|
{ LOGD_VPN_PLUGIN,"VPN_PLUGIN" },
|
|
|
|
|
{ LOGD_PROXY, "PROXY" },
|
|
|
|
|
{ 0 },
|
2010-04-06 15:23:08 -07:00
|
|
|
};
|
|
|
|
|
|
2016-10-02 18:22:50 +02:00
|
|
|
/*****************************************************************************/
|
2010-04-08 08:56:17 -07:00
|
|
|
|
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 12:36:29 +02:00
|
|
|
static char *_domains_to_string (gboolean include_level_override);
|
|
|
|
|
|
2016-10-02 18:22:50 +02:00
|
|
|
/*****************************************************************************/
|
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 12:36:29 +02:00
|
|
|
|
2016-10-05 15:52:55 +02:00
|
|
|
static gboolean
|
|
|
|
|
_syslog_identifier_valid_domain (const char *domain)
|
|
|
|
|
{
|
|
|
|
|
char c;
|
|
|
|
|
|
|
|
|
|
if (!domain || !domain[0])
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
/* we pass the syslog identifier as format string. No funny stuff. */
|
|
|
|
|
|
|
|
|
|
for (; (c = domain[0]); domain++) {
|
|
|
|
|
if ( (c >= 'a' && c <= 'z')
|
|
|
|
|
|| (c >= 'A' && c <= 'Z')
|
|
|
|
|
|| (c >= '0' && c <= '9')
|
|
|
|
|
|| NM_IN_SET (c, '-', '_'))
|
|
|
|
|
continue;
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2019-01-15 17:54:51 +01:00
|
|
|
_syslog_identifier_assert (const Global *gl)
|
2016-10-05 15:52:55 +02:00
|
|
|
{
|
|
|
|
|
g_assert (gl);
|
|
|
|
|
g_assert (gl->syslog_identifier);
|
|
|
|
|
g_assert (g_str_has_prefix (gl->syslog_identifier, "SYSLOG_IDENTIFIER="));
|
|
|
|
|
g_assert (_syslog_identifier_valid_domain (&gl->syslog_identifier[NM_STRLEN ("SYSLOG_IDENTIFIER=")]));
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const char *
|
2019-01-15 17:54:51 +01:00
|
|
|
syslog_identifier_domain (const Global *gl)
|
2016-10-05 15:52:55 +02:00
|
|
|
{
|
|
|
|
|
nm_assert (_syslog_identifier_assert (gl));
|
|
|
|
|
return &gl->syslog_identifier[NM_STRLEN ("SYSLOG_IDENTIFIER=")];
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-11 10:42:22 +02:00
|
|
|
#if SYSTEMD_JOURNAL
|
2016-10-05 15:52:55 +02:00
|
|
|
static const char *
|
2019-01-15 17:54:51 +01:00
|
|
|
syslog_identifier_full (const Global *gl)
|
2016-10-05 15:52:55 +02:00
|
|
|
{
|
|
|
|
|
nm_assert (_syslog_identifier_assert (gl));
|
|
|
|
|
return &gl->syslog_identifier[0];
|
|
|
|
|
}
|
2016-10-11 10:42:22 +02:00
|
|
|
#endif
|
2016-10-05 15:52:55 +02:00
|
|
|
|
|
|
|
|
void
|
|
|
|
|
nm_logging_set_syslog_identifier (const char *domain)
|
|
|
|
|
{
|
|
|
|
|
if (global.log_backend != LOG_BACKEND_GLIB)
|
|
|
|
|
g_return_if_reached ();
|
|
|
|
|
|
|
|
|
|
if (!_syslog_identifier_valid_domain (domain))
|
|
|
|
|
g_return_if_reached ();
|
|
|
|
|
|
|
|
|
|
if (global.syslog_identifier_initialized)
|
|
|
|
|
g_return_if_reached ();
|
|
|
|
|
|
|
|
|
|
global.syslog_identifier_initialized = TRUE;
|
|
|
|
|
global.syslog_identifier = g_strdup_printf ("SYSLOG_IDENTIFIER=%s", domain);
|
|
|
|
|
nm_assert (_syslog_identifier_assert (&global));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2013-10-01 11:40:22 -04:00
|
|
|
static gboolean
|
|
|
|
|
match_log_level (const char *level,
|
2014-10-30 12:44:36 +01:00
|
|
|
NMLogLevel *out_level,
|
2013-10-01 11:40:22 -04:00
|
|
|
GError **error)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
2019-01-15 16:58:15 +01:00
|
|
|
for (i = 0; i < G_N_ELEMENTS (level_desc); i++) {
|
|
|
|
|
if (!g_ascii_strcasecmp (level_desc[i].name, level)) {
|
2013-10-01 11:40:22 -04:00
|
|
|
*out_level = i;
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-16 16:47:30 -04:00
|
|
|
g_set_error (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_UNKNOWN_LOG_LEVEL,
|
2013-10-01 11:40:22 -04:00
|
|
|
_("Unknown log level '%s'"), level);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-06 15:23:08 -07:00
|
|
|
gboolean
|
2013-11-26 11:33:42 -05:00
|
|
|
nm_logging_setup (const char *level,
|
|
|
|
|
const char *domains,
|
|
|
|
|
char **bad_domains,
|
|
|
|
|
GError **error)
|
2010-04-06 15:23:08 -07:00
|
|
|
{
|
2013-11-26 11:33:42 -05:00
|
|
|
GString *unrecognized = NULL;
|
2016-05-19 19:01:58 +02:00
|
|
|
NMLogDomain new_logging[G_N_ELEMENTS (_nm_logging_enabled_state)];
|
2015-10-07 11:07:09 +02:00
|
|
|
NMLogLevel new_log_level = global.log_level;
|
logging: fix "nmcli gen log level FOO"
The change to per-domain log levels means that when setting just the
level, we need to re-set the log level for each domain (since it's the
"logging" bit array that actually determines what gets logged).
nm_logging_setup() was dealing correctly with domains=NULL, but not
domains="" (which is what happens when it is invoked with only a level
via D-Bus), so doing "nmcli gen log level DEBUG" would change the
"default" log level, but leave all of the domains still at their
previous level:
danw@laptop:NetworkManager> nmcli g log
LEVEL DOMAINS
INFO PLATFORM,RFKILL,ETHER,WIFI,BT,MB,DHCP4,DHCP6,PPP,IP4,IP6...
danw@laptop:NetworkManager> nmcli g log level DEBUG
danw@laptop:NetworkManager> nmcli g log
LEVEL DOMAINS
DEBUG PLATFORM:INFO,RFKILL:INFO,ETHER:INFO,WIFI:INFO,BT:INFO...
2014-01-21 09:54:50 -05:00
|
|
|
char **tmp, **iter;
|
2013-10-01 11:40:22 -04:00
|
|
|
int i;
|
2015-10-06 19:48:35 +02:00
|
|
|
gboolean had_platform_debug;
|
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 12:36:29 +02:00
|
|
|
gs_free char *domains_free = NULL;
|
2010-04-06 15:23:08 -07:00
|
|
|
|
2014-02-12 11:05:02 +01:00
|
|
|
g_return_val_if_fail (!bad_domains || !*bad_domains, FALSE);
|
|
|
|
|
g_return_val_if_fail (!error || !*error, FALSE);
|
|
|
|
|
|
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 12:36:29 +02:00
|
|
|
/* domains */
|
2016-05-19 18:57:18 +02:00
|
|
|
if (!domains || !*domains)
|
|
|
|
|
domains = (domains_free = _domains_to_string (FALSE));
|
2014-04-05 09:38:59 -04:00
|
|
|
|
2015-08-01 14:15:44 +02:00
|
|
|
for (i = 0; i < G_N_ELEMENTS (new_logging); i++)
|
2013-10-01 11:40:22 -04:00
|
|
|
new_logging[i] = 0;
|
2010-04-06 15:23:08 -07:00
|
|
|
|
2013-10-01 11:40:22 -04:00
|
|
|
/* levels */
|
logging: fix "nmcli gen log level FOO"
The change to per-domain log levels means that when setting just the
level, we need to re-set the log level for each domain (since it's the
"logging" bit array that actually determines what gets logged).
nm_logging_setup() was dealing correctly with domains=NULL, but not
domains="" (which is what happens when it is invoked with only a level
via D-Bus), so doing "nmcli gen log level DEBUG" would change the
"default" log level, but leave all of the domains still at their
previous level:
danw@laptop:NetworkManager> nmcli g log
LEVEL DOMAINS
INFO PLATFORM,RFKILL,ETHER,WIFI,BT,MB,DHCP4,DHCP6,PPP,IP4,IP6...
danw@laptop:NetworkManager> nmcli g log level DEBUG
danw@laptop:NetworkManager> nmcli g log
LEVEL DOMAINS
DEBUG PLATFORM:INFO,RFKILL:INFO,ETHER:INFO,WIFI:INFO,BT:INFO...
2014-01-21 09:54:50 -05:00
|
|
|
if (level && *level) {
|
2013-10-01 11:40:22 -04:00
|
|
|
if (!match_log_level (level, &new_log_level, error))
|
2010-04-06 15:53:37 -07:00
|
|
|
return FALSE;
|
2015-10-07 10:45:28 +02:00
|
|
|
if (new_log_level == _LOGL_KEEP) {
|
2015-10-07 11:07:09 +02:00
|
|
|
new_log_level = global.log_level;
|
2015-10-07 10:45:28 +02:00
|
|
|
for (i = 0; i < G_N_ELEMENTS (new_logging); i++)
|
2016-05-19 19:01:58 +02:00
|
|
|
new_logging[i] = _nm_logging_enabled_state[i];
|
2015-10-07 10:45:28 +02:00
|
|
|
}
|
2010-04-06 15:23:08 -07:00
|
|
|
}
|
|
|
|
|
|
logging: fix "nmcli gen log level FOO"
The change to per-domain log levels means that when setting just the
level, we need to re-set the log level for each domain (since it's the
"logging" bit array that actually determines what gets logged).
nm_logging_setup() was dealing correctly with domains=NULL, but not
domains="" (which is what happens when it is invoked with only a level
via D-Bus), so doing "nmcli gen log level DEBUG" would change the
"default" log level, but leave all of the domains still at their
previous level:
danw@laptop:NetworkManager> nmcli g log
LEVEL DOMAINS
INFO PLATFORM,RFKILL,ETHER,WIFI,BT,MB,DHCP4,DHCP6,PPP,IP4,IP6...
danw@laptop:NetworkManager> nmcli g log level DEBUG
danw@laptop:NetworkManager> nmcli g log
LEVEL DOMAINS
DEBUG PLATFORM:INFO,RFKILL:INFO,ETHER:INFO,WIFI:INFO,BT:INFO...
2014-01-21 09:54:50 -05:00
|
|
|
tmp = g_strsplit_set (domains, ", ", 0);
|
|
|
|
|
for (iter = tmp; iter && *iter; iter++) {
|
|
|
|
|
const LogDesc *diter;
|
2014-10-30 12:44:36 +01:00
|
|
|
NMLogLevel domain_log_level;
|
|
|
|
|
NMLogDomain bits;
|
logging: fix "nmcli gen log level FOO"
The change to per-domain log levels means that when setting just the
level, we need to re-set the log level for each domain (since it's the
"logging" bit array that actually determines what gets logged).
nm_logging_setup() was dealing correctly with domains=NULL, but not
domains="" (which is what happens when it is invoked with only a level
via D-Bus), so doing "nmcli gen log level DEBUG" would change the
"default" log level, but leave all of the domains still at their
previous level:
danw@laptop:NetworkManager> nmcli g log
LEVEL DOMAINS
INFO PLATFORM,RFKILL,ETHER,WIFI,BT,MB,DHCP4,DHCP6,PPP,IP4,IP6...
danw@laptop:NetworkManager> nmcli g log level DEBUG
danw@laptop:NetworkManager> nmcli g log
LEVEL DOMAINS
DEBUG PLATFORM:INFO,RFKILL:INFO,ETHER:INFO,WIFI:INFO,BT:INFO...
2014-01-21 09:54:50 -05:00
|
|
|
char *p;
|
|
|
|
|
|
2016-06-16 22:30:41 +02:00
|
|
|
/* LOGD_VPN_PLUGIN is protected, that is, when setting ALL or DEFAULT,
|
|
|
|
|
* it does not enable the verbose levels DEBUG and TRACE, because that
|
|
|
|
|
* may expose sensitive data. */
|
|
|
|
|
NMLogDomain protect = LOGD_NONE;
|
|
|
|
|
|
logging: fix "nmcli gen log level FOO"
The change to per-domain log levels means that when setting just the
level, we need to re-set the log level for each domain (since it's the
"logging" bit array that actually determines what gets logged).
nm_logging_setup() was dealing correctly with domains=NULL, but not
domains="" (which is what happens when it is invoked with only a level
via D-Bus), so doing "nmcli gen log level DEBUG" would change the
"default" log level, but leave all of the domains still at their
previous level:
danw@laptop:NetworkManager> nmcli g log
LEVEL DOMAINS
INFO PLATFORM,RFKILL,ETHER,WIFI,BT,MB,DHCP4,DHCP6,PPP,IP4,IP6...
danw@laptop:NetworkManager> nmcli g log level DEBUG
danw@laptop:NetworkManager> nmcli g log
LEVEL DOMAINS
DEBUG PLATFORM:INFO,RFKILL:INFO,ETHER:INFO,WIFI:INFO,BT:INFO...
2014-01-21 09:54:50 -05:00
|
|
|
if (!strlen (*iter))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
p = strchr (*iter, ':');
|
|
|
|
|
if (p) {
|
|
|
|
|
*p = '\0';
|
|
|
|
|
if (!match_log_level (p + 1, &domain_log_level, error)) {
|
|
|
|
|
g_strfreev (tmp);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
} else
|
|
|
|
|
domain_log_level = new_log_level;
|
|
|
|
|
|
|
|
|
|
bits = 0;
|
|
|
|
|
|
2016-10-06 21:40:18 +02:00
|
|
|
if (domains_free) {
|
|
|
|
|
/* The caller didn't provide any domains to set (`nmcli general logging level DEBUG`).
|
|
|
|
|
* We reset all domains that were previously set, but we still want to protect
|
|
|
|
|
* VPN_PLUGIN domain. */
|
|
|
|
|
protect = LOGD_VPN_PLUGIN;
|
|
|
|
|
}
|
|
|
|
|
|
logging: fix "nmcli gen log level FOO"
The change to per-domain log levels means that when setting just the
level, we need to re-set the log level for each domain (since it's the
"logging" bit array that actually determines what gets logged).
nm_logging_setup() was dealing correctly with domains=NULL, but not
domains="" (which is what happens when it is invoked with only a level
via D-Bus), so doing "nmcli gen log level DEBUG" would change the
"default" log level, but leave all of the domains still at their
previous level:
danw@laptop:NetworkManager> nmcli g log
LEVEL DOMAINS
INFO PLATFORM,RFKILL,ETHER,WIFI,BT,MB,DHCP4,DHCP6,PPP,IP4,IP6...
danw@laptop:NetworkManager> nmcli g log level DEBUG
danw@laptop:NetworkManager> nmcli g log
LEVEL DOMAINS
DEBUG PLATFORM:INFO,RFKILL:INFO,ETHER:INFO,WIFI:INFO,BT:INFO...
2014-01-21 09:54:50 -05:00
|
|
|
/* Check for combined domains */
|
2016-06-16 22:30:41 +02:00
|
|
|
if (!g_ascii_strcasecmp (*iter, LOGD_ALL_STRING)) {
|
logging: fix "nmcli gen log level FOO"
The change to per-domain log levels means that when setting just the
level, we need to re-set the log level for each domain (since it's the
"logging" bit array that actually determines what gets logged).
nm_logging_setup() was dealing correctly with domains=NULL, but not
domains="" (which is what happens when it is invoked with only a level
via D-Bus), so doing "nmcli gen log level DEBUG" would change the
"default" log level, but leave all of the domains still at their
previous level:
danw@laptop:NetworkManager> nmcli g log
LEVEL DOMAINS
INFO PLATFORM,RFKILL,ETHER,WIFI,BT,MB,DHCP4,DHCP6,PPP,IP4,IP6...
danw@laptop:NetworkManager> nmcli g log level DEBUG
danw@laptop:NetworkManager> nmcli g log
LEVEL DOMAINS
DEBUG PLATFORM:INFO,RFKILL:INFO,ETHER:INFO,WIFI:INFO,BT:INFO...
2014-01-21 09:54:50 -05:00
|
|
|
bits = LOGD_ALL;
|
2016-06-16 22:30:41 +02:00
|
|
|
protect = LOGD_VPN_PLUGIN;
|
|
|
|
|
} else if (!g_ascii_strcasecmp (*iter, LOGD_DEFAULT_STRING)) {
|
logging: fix "nmcli gen log level FOO"
The change to per-domain log levels means that when setting just the
level, we need to re-set the log level for each domain (since it's the
"logging" bit array that actually determines what gets logged).
nm_logging_setup() was dealing correctly with domains=NULL, but not
domains="" (which is what happens when it is invoked with only a level
via D-Bus), so doing "nmcli gen log level DEBUG" would change the
"default" log level, but leave all of the domains still at their
previous level:
danw@laptop:NetworkManager> nmcli g log
LEVEL DOMAINS
INFO PLATFORM,RFKILL,ETHER,WIFI,BT,MB,DHCP4,DHCP6,PPP,IP4,IP6...
danw@laptop:NetworkManager> nmcli g log level DEBUG
danw@laptop:NetworkManager> nmcli g log
LEVEL DOMAINS
DEBUG PLATFORM:INFO,RFKILL:INFO,ETHER:INFO,WIFI:INFO,BT:INFO...
2014-01-21 09:54:50 -05:00
|
|
|
bits = LOGD_DEFAULT;
|
2016-06-16 22:30:41 +02:00
|
|
|
protect = LOGD_VPN_PLUGIN;
|
|
|
|
|
} else if (!g_ascii_strcasecmp (*iter, LOGD_DHCP_STRING))
|
logging: fix "nmcli gen log level FOO"
The change to per-domain log levels means that when setting just the
level, we need to re-set the log level for each domain (since it's the
"logging" bit array that actually determines what gets logged).
nm_logging_setup() was dealing correctly with domains=NULL, but not
domains="" (which is what happens when it is invoked with only a level
via D-Bus), so doing "nmcli gen log level DEBUG" would change the
"default" log level, but leave all of the domains still at their
previous level:
danw@laptop:NetworkManager> nmcli g log
LEVEL DOMAINS
INFO PLATFORM,RFKILL,ETHER,WIFI,BT,MB,DHCP4,DHCP6,PPP,IP4,IP6...
danw@laptop:NetworkManager> nmcli g log level DEBUG
danw@laptop:NetworkManager> nmcli g log
LEVEL DOMAINS
DEBUG PLATFORM:INFO,RFKILL:INFO,ETHER:INFO,WIFI:INFO,BT:INFO...
2014-01-21 09:54:50 -05:00
|
|
|
bits = LOGD_DHCP;
|
|
|
|
|
else if (!g_ascii_strcasecmp (*iter, LOGD_IP_STRING))
|
|
|
|
|
bits = LOGD_IP;
|
|
|
|
|
|
|
|
|
|
/* Check for compatibility domains */
|
|
|
|
|
else if (!g_ascii_strcasecmp (*iter, "HW"))
|
|
|
|
|
bits = LOGD_PLATFORM;
|
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-13 17:07:00 -04:00
|
|
|
else if (!g_ascii_strcasecmp (*iter, "WIMAX"))
|
|
|
|
|
continue;
|
logging: fix "nmcli gen log level FOO"
The change to per-domain log levels means that when setting just the
level, we need to re-set the log level for each domain (since it's the
"logging" bit array that actually determines what gets logged).
nm_logging_setup() was dealing correctly with domains=NULL, but not
domains="" (which is what happens when it is invoked with only a level
via D-Bus), so doing "nmcli gen log level DEBUG" would change the
"default" log level, but leave all of the domains still at their
previous level:
danw@laptop:NetworkManager> nmcli g log
LEVEL DOMAINS
INFO PLATFORM,RFKILL,ETHER,WIFI,BT,MB,DHCP4,DHCP6,PPP,IP4,IP6...
danw@laptop:NetworkManager> nmcli g log level DEBUG
danw@laptop:NetworkManager> nmcli g log
LEVEL DOMAINS
DEBUG PLATFORM:INFO,RFKILL:INFO,ETHER:INFO,WIFI:INFO,BT:INFO...
2014-01-21 09:54:50 -05:00
|
|
|
|
|
|
|
|
else {
|
2019-01-15 16:58:15 +01:00
|
|
|
for (diter = &domain_desc[0]; diter->name; diter++) {
|
logging: fix "nmcli gen log level FOO"
The change to per-domain log levels means that when setting just the
level, we need to re-set the log level for each domain (since it's the
"logging" bit array that actually determines what gets logged).
nm_logging_setup() was dealing correctly with domains=NULL, but not
domains="" (which is what happens when it is invoked with only a level
via D-Bus), so doing "nmcli gen log level DEBUG" would change the
"default" log level, but leave all of the domains still at their
previous level:
danw@laptop:NetworkManager> nmcli g log
LEVEL DOMAINS
INFO PLATFORM,RFKILL,ETHER,WIFI,BT,MB,DHCP4,DHCP6,PPP,IP4,IP6...
danw@laptop:NetworkManager> nmcli g log level DEBUG
danw@laptop:NetworkManager> nmcli g log
LEVEL DOMAINS
DEBUG PLATFORM:INFO,RFKILL:INFO,ETHER:INFO,WIFI:INFO,BT:INFO...
2014-01-21 09:54:50 -05:00
|
|
|
if (!g_ascii_strcasecmp (diter->name, *iter)) {
|
|
|
|
|
bits = diter->num;
|
|
|
|
|
break;
|
2013-11-26 11:33:42 -05:00
|
|
|
}
|
logging: fix "nmcli gen log level FOO"
The change to per-domain log levels means that when setting just the
level, we need to re-set the log level for each domain (since it's the
"logging" bit array that actually determines what gets logged).
nm_logging_setup() was dealing correctly with domains=NULL, but not
domains="" (which is what happens when it is invoked with only a level
via D-Bus), so doing "nmcli gen log level DEBUG" would change the
"default" log level, but leave all of the domains still at their
previous level:
danw@laptop:NetworkManager> nmcli g log
LEVEL DOMAINS
INFO PLATFORM,RFKILL,ETHER,WIFI,BT,MB,DHCP4,DHCP6,PPP,IP4,IP6...
danw@laptop:NetworkManager> nmcli g log level DEBUG
danw@laptop:NetworkManager> nmcli g log
LEVEL DOMAINS
DEBUG PLATFORM:INFO,RFKILL:INFO,ETHER:INFO,WIFI:INFO,BT:INFO...
2014-01-21 09:54:50 -05:00
|
|
|
}
|
2013-11-26 11:33:42 -05:00
|
|
|
|
2015-08-01 14:35:51 +02:00
|
|
|
if (!bits) {
|
|
|
|
|
if (!bad_domains) {
|
|
|
|
|
g_set_error (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_UNKNOWN_LOG_DOMAIN,
|
|
|
|
|
_("Unknown log domain '%s'"), *iter);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2013-10-01 11:40:22 -04:00
|
|
|
|
2015-08-01 14:35:51 +02:00
|
|
|
if (unrecognized)
|
|
|
|
|
g_string_append (unrecognized, ", ");
|
|
|
|
|
else
|
|
|
|
|
unrecognized = g_string_new (NULL);
|
|
|
|
|
g_string_append (unrecognized, *iter);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2010-04-06 15:23:08 -07:00
|
|
|
}
|
2013-10-01 11:40:22 -04:00
|
|
|
|
2015-10-07 10:45:28 +02:00
|
|
|
if (domain_log_level == _LOGL_KEEP) {
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (new_logging); i++)
|
2016-05-19 19:01:58 +02:00
|
|
|
new_logging[i] = (new_logging[i] & ~bits) | (_nm_logging_enabled_state[i] & bits);
|
2015-10-07 10:45:28 +02:00
|
|
|
} else {
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (new_logging); i++) {
|
|
|
|
|
if (i < domain_log_level)
|
|
|
|
|
new_logging[i] &= ~bits;
|
2016-06-16 22:30:41 +02:00
|
|
|
else {
|
2015-10-07 10:45:28 +02:00
|
|
|
new_logging[i] |= bits;
|
2016-10-06 21:40:18 +02:00
|
|
|
if ( (protect & bits)
|
2016-06-16 22:30:41 +02:00
|
|
|
&& i < LOGL_INFO)
|
|
|
|
|
new_logging[i] &= ~protect;
|
|
|
|
|
}
|
2015-10-07 10:45:28 +02:00
|
|
|
}
|
2015-08-01 14:12:34 +02:00
|
|
|
}
|
logging: fix "nmcli gen log level FOO"
The change to per-domain log levels means that when setting just the
level, we need to re-set the log level for each domain (since it's the
"logging" bit array that actually determines what gets logged).
nm_logging_setup() was dealing correctly with domains=NULL, but not
domains="" (which is what happens when it is invoked with only a level
via D-Bus), so doing "nmcli gen log level DEBUG" would change the
"default" log level, but leave all of the domains still at their
previous level:
danw@laptop:NetworkManager> nmcli g log
LEVEL DOMAINS
INFO PLATFORM,RFKILL,ETHER,WIFI,BT,MB,DHCP4,DHCP6,PPP,IP4,IP6...
danw@laptop:NetworkManager> nmcli g log level DEBUG
danw@laptop:NetworkManager> nmcli g log
LEVEL DOMAINS
DEBUG PLATFORM:INFO,RFKILL:INFO,ETHER:INFO,WIFI:INFO,BT:INFO...
2014-01-21 09:54:50 -05:00
|
|
|
}
|
|
|
|
|
g_strfreev (tmp);
|
2013-10-01 11:40:22 -04:00
|
|
|
|
2015-10-07 11:07:09 +02:00
|
|
|
g_clear_pointer (&global.logging_domains_to_string, g_free);
|
2014-02-12 11:30:29 +01:00
|
|
|
|
2015-10-06 19:48:35 +02:00
|
|
|
had_platform_debug = nm_logging_enabled (LOGL_DEBUG, LOGD_PLATFORM);
|
|
|
|
|
|
2015-10-07 11:07:09 +02:00
|
|
|
global.log_level = new_log_level;
|
2015-08-01 14:15:44 +02:00
|
|
|
for (i = 0; i < G_N_ELEMENTS (new_logging); i++)
|
2016-05-19 19:01:58 +02:00
|
|
|
_nm_logging_enabled_state[i] = new_logging[i];
|
2013-10-01 11:40:22 -04:00
|
|
|
|
2015-10-06 19:48:35 +02:00
|
|
|
if ( had_platform_debug
|
|
|
|
|
&& !nm_logging_enabled (LOGL_DEBUG, LOGD_PLATFORM)) {
|
|
|
|
|
/* when debug logging is enabled, platform will cache all access to
|
|
|
|
|
* sysctl. When the user disables debug-logging, we want to clear that
|
|
|
|
|
* cache right away. */
|
2016-03-01 10:17:44 +01:00
|
|
|
_nm_logging_clear_platform_logging_cache ();
|
2015-10-06 19:48:35 +02:00
|
|
|
}
|
|
|
|
|
|
2013-11-26 11:33:42 -05:00
|
|
|
if (unrecognized)
|
|
|
|
|
*bad_domains = g_string_free (unrecognized, FALSE);
|
|
|
|
|
|
2010-04-06 15:23:08 -07:00
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-12 11:17:26 +01:00
|
|
|
const char *
|
2010-05-04 12:06:00 -07:00
|
|
|
nm_logging_level_to_string (void)
|
|
|
|
|
{
|
2019-01-15 16:58:15 +01:00
|
|
|
return level_desc[global.log_level].name;
|
2010-05-04 12:06:00 -07:00
|
|
|
}
|
|
|
|
|
|
2013-03-11 12:23:57 -04:00
|
|
|
const char *
|
|
|
|
|
nm_logging_all_levels_to_string (void)
|
|
|
|
|
{
|
|
|
|
|
static GString *str;
|
|
|
|
|
|
|
|
|
|
if (G_UNLIKELY (!str)) {
|
2013-10-01 11:40:22 -04:00
|
|
|
int i;
|
2013-03-11 12:23:57 -04:00
|
|
|
|
|
|
|
|
str = g_string_new (NULL);
|
2019-01-15 16:58:15 +01:00
|
|
|
for (i = 0; i < G_N_ELEMENTS (level_desc); i++) {
|
2013-03-11 12:23:57 -04:00
|
|
|
if (str->len)
|
|
|
|
|
g_string_append_c (str, ',');
|
2019-01-15 16:58:15 +01:00
|
|
|
g_string_append (str, level_desc[i].name);
|
2013-03-11 12:23:57 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return str->str;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-12 11:30:29 +01:00
|
|
|
const char *
|
2010-05-04 12:06:00 -07:00
|
|
|
nm_logging_domains_to_string (void)
|
|
|
|
|
{
|
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 12:36:29 +02:00
|
|
|
if (G_UNLIKELY (!global.logging_domains_to_string))
|
|
|
|
|
global.logging_domains_to_string = _domains_to_string (TRUE);
|
2013-10-01 11:40:22 -04:00
|
|
|
|
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 12:36:29 +02:00
|
|
|
return global.logging_domains_to_string;
|
|
|
|
|
}
|
2010-05-04 12:06:00 -07:00
|
|
|
|
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 12:36:29 +02:00
|
|
|
static char *
|
|
|
|
|
_domains_to_string (gboolean include_level_override)
|
|
|
|
|
{
|
|
|
|
|
const LogDesc *diter;
|
|
|
|
|
GString *str;
|
|
|
|
|
int i;
|
2013-10-01 11:40:22 -04:00
|
|
|
|
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 12:36:29 +02:00
|
|
|
/* We don't just return g_strdup (global.log_domains) because we want to expand
|
|
|
|
|
* "DEFAULT" and "ALL".
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
str = g_string_sized_new (75);
|
2019-01-15 16:58:15 +01:00
|
|
|
for (diter = &domain_desc[0]; diter->name; diter++) {
|
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 12:36:29 +02:00
|
|
|
/* If it's set for any lower level, it will also be set for LOGL_ERR */
|
2016-05-19 19:01:58 +02:00
|
|
|
if (!(diter->num & _nm_logging_enabled_state[LOGL_ERR]))
|
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 12:36:29 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (str->len)
|
|
|
|
|
g_string_append_c (str, ',');
|
|
|
|
|
g_string_append (str, diter->name);
|
2013-10-01 11:40:22 -04:00
|
|
|
|
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 12:36:29 +02:00
|
|
|
if (!include_level_override)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
/* Check if it's logging at a lower level than the default. */
|
|
|
|
|
for (i = 0; i < global.log_level; i++) {
|
2016-05-19 19:01:58 +02:00
|
|
|
if (diter->num & _nm_logging_enabled_state[i]) {
|
2019-01-15 16:58:15 +01:00
|
|
|
g_string_append_printf (str, ":%s", level_desc[i].name);
|
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 12:36:29 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* Check if it's logging at a higher level than the default. */
|
2016-05-19 19:01:58 +02:00
|
|
|
if (!(diter->num & _nm_logging_enabled_state[global.log_level])) {
|
|
|
|
|
for (i = global.log_level + 1; i < G_N_ELEMENTS (_nm_logging_enabled_state); i++) {
|
|
|
|
|
if (diter->num & _nm_logging_enabled_state[i]) {
|
2019-01-15 16:58:15 +01:00
|
|
|
g_string_append_printf (str, ":%s", level_desc[i].name);
|
2013-10-01 11:40:22 -04:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-05-04 12:06:00 -07:00
|
|
|
}
|
|
|
|
|
}
|
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 12:36:29 +02:00
|
|
|
return g_string_free (str, FALSE);
|
2010-05-04 12:06:00 -07:00
|
|
|
}
|
|
|
|
|
|
2013-03-11 12:23:57 -04:00
|
|
|
const char *
|
|
|
|
|
nm_logging_all_domains_to_string (void)
|
|
|
|
|
{
|
|
|
|
|
static GString *str;
|
|
|
|
|
|
|
|
|
|
if (G_UNLIKELY (!str)) {
|
|
|
|
|
const LogDesc *diter;
|
|
|
|
|
|
2013-07-27 12:43:53 +02:00
|
|
|
str = g_string_new (LOGD_DEFAULT_STRING);
|
2019-01-15 16:58:15 +01:00
|
|
|
for (diter = &domain_desc[0]; diter->name; diter++) {
|
2013-03-11 12:23:57 -04:00
|
|
|
g_string_append_c (str, ',');
|
|
|
|
|
g_string_append (str, diter->name);
|
|
|
|
|
if (diter->num == LOGD_DHCP6)
|
2013-07-27 12:43:53 +02:00
|
|
|
g_string_append (str, "," LOGD_DHCP_STRING);
|
2013-03-11 12:23:57 -04:00
|
|
|
else if (diter->num == LOGD_IP6)
|
2013-07-27 12:43:53 +02:00
|
|
|
g_string_append (str, "," LOGD_IP_STRING);
|
2013-03-11 12:23:57 -04:00
|
|
|
}
|
2013-07-27 12:43:53 +02:00
|
|
|
g_string_append (str, "," LOGD_ALL_STRING);
|
2013-03-11 12:23:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return str->str;
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-23 10:56:27 +02:00
|
|
|
/**
|
|
|
|
|
* nm_logging_get_level:
|
|
|
|
|
* @domain: find the lowest enabled logging level for the
|
|
|
|
|
* given domain. If this is a set of multiple
|
|
|
|
|
* domains, the most verbose level will be returned.
|
|
|
|
|
*
|
|
|
|
|
* Returns: the lowest (most verbose) logging level for the
|
|
|
|
|
* give @domain, or %_LOGL_OFF if it is disabled.
|
|
|
|
|
**/
|
|
|
|
|
NMLogLevel
|
|
|
|
|
nm_logging_get_level (NMLogDomain domain)
|
|
|
|
|
{
|
|
|
|
|
NMLogLevel sl = _LOGL_OFF;
|
|
|
|
|
|
|
|
|
|
G_STATIC_ASSERT (LOGL_TRACE == 0);
|
|
|
|
|
while ( sl > LOGL_TRACE
|
|
|
|
|
&& nm_logging_enabled (sl - 1, domain))
|
|
|
|
|
sl--;
|
|
|
|
|
return sl;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-28 15:31:23 +01:00
|
|
|
gboolean
|
|
|
|
|
_nm_log_enabled (NMLogLevel level,
|
|
|
|
|
NMLogDomain domain)
|
|
|
|
|
{
|
|
|
|
|
return nm_logging_enabled (level, domain);
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-08 16:21:21 +02:00
|
|
|
#if SYSTEMD_JOURNAL
|
|
|
|
|
static void
|
2016-10-06 16:55:12 +02:00
|
|
|
_iovec_set (struct iovec *iov, const void *str, gsize len)
|
2015-07-08 16:21:21 +02:00
|
|
|
{
|
2016-10-06 16:55:12 +02:00
|
|
|
iov->iov_base = (void *) str;
|
|
|
|
|
iov->iov_len = len;
|
2015-07-08 16:21:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2016-10-06 16:55:12 +02:00
|
|
|
_iovec_set_string (struct iovec *iov, const char *str)
|
2015-07-08 16:21:21 +02:00
|
|
|
{
|
2016-10-06 16:55:12 +02:00
|
|
|
_iovec_set (iov, str, strlen (str));
|
2015-07-08 16:21:21 +02:00
|
|
|
}
|
2016-10-05 15:52:55 +02:00
|
|
|
|
2016-10-06 16:55:12 +02:00
|
|
|
_nm_printf (3, 4)
|
2016-10-05 15:52:55 +02:00
|
|
|
static void
|
2016-10-06 16:55:12 +02:00
|
|
|
_iovec_set_format (struct iovec *iov, gpointer *iov_free, const char *format, ...)
|
2016-10-05 15:52:55 +02:00
|
|
|
{
|
2016-10-06 16:55:12 +02:00
|
|
|
va_list ap;
|
|
|
|
|
char *str;
|
|
|
|
|
|
|
|
|
|
va_start (ap, format);
|
|
|
|
|
str = g_strdup_vprintf (format, ap);
|
|
|
|
|
va_end (ap);
|
|
|
|
|
|
|
|
|
|
_iovec_set_string (iov, str);
|
|
|
|
|
*iov_free = str;
|
2016-10-05 15:52:55 +02:00
|
|
|
}
|
|
|
|
|
|
2016-10-06 16:55:12 +02:00
|
|
|
#define _iovec_set_format_a(iov, reserve_extra, format, ...) \
|
|
|
|
|
G_STMT_START { \
|
|
|
|
|
const gsize _size = (reserve_extra) + (NM_STRLEN (format) + 3); \
|
|
|
|
|
char *const _buf = g_alloca (_size); \
|
|
|
|
|
int _len; \
|
|
|
|
|
\
|
2019-01-10 12:00:34 +01:00
|
|
|
G_STATIC_ASSERT_EXPR ((reserve_extra) + (NM_STRLEN (format) + 3) <= 96); \
|
|
|
|
|
\
|
2016-10-06 16:55:12 +02:00
|
|
|
_len = g_snprintf (_buf, _size, ""format"", ##__VA_ARGS__);\
|
|
|
|
|
\
|
|
|
|
|
nm_assert (_len >= 0); \
|
2019-01-10 12:00:34 +01:00
|
|
|
nm_assert (_len < _size); \
|
2016-10-06 16:55:12 +02:00
|
|
|
nm_assert (_len == strlen (_buf)); \
|
|
|
|
|
\
|
|
|
|
|
_iovec_set ((iov), _buf, _len); \
|
|
|
|
|
} G_STMT_END
|
2019-01-10 12:00:34 +01:00
|
|
|
|
|
|
|
|
#define _iovec_set_format_str_a(iov, max_str_len, format, str_arg) \
|
|
|
|
|
G_STMT_START { \
|
|
|
|
|
const char *_str_arg = (str_arg); \
|
|
|
|
|
\
|
|
|
|
|
nm_assert (_str_arg && strlen (_str_arg) < (max_str_len)); \
|
|
|
|
|
_iovec_set_format_a ((iov), (max_str_len), format, str_arg); \
|
|
|
|
|
} G_STMT_END
|
|
|
|
|
|
2015-07-08 16:21:21 +02:00
|
|
|
#endif
|
|
|
|
|
|
2011-03-19 12:42:29 -05:00
|
|
|
void
|
2015-04-22 11:06:49 +02:00
|
|
|
_nm_log_impl (const char *file,
|
|
|
|
|
guint line,
|
|
|
|
|
const char *func,
|
|
|
|
|
NMLogLevel level,
|
|
|
|
|
NMLogDomain domain,
|
|
|
|
|
int error,
|
2017-03-01 10:20:01 +00:00
|
|
|
const char *ifname,
|
|
|
|
|
const char *conn_uuid,
|
2015-04-22 11:06:49 +02:00
|
|
|
const char *fmt,
|
|
|
|
|
...)
|
2010-04-06 15:23:08 -07:00
|
|
|
{
|
|
|
|
|
va_list args;
|
|
|
|
|
char *msg;
|
|
|
|
|
GTimeVal tv;
|
2016-12-11 22:33:19 +01:00
|
|
|
int errno_saved;
|
2010-04-06 15:23:08 -07:00
|
|
|
|
2016-05-19 19:01:58 +02:00
|
|
|
if ((guint) level >= G_N_ELEMENTS (_nm_logging_enabled_state))
|
2015-07-08 16:21:21 +02:00
|
|
|
g_return_if_reached ();
|
2013-10-01 11:40:22 -04:00
|
|
|
|
2016-05-19 19:01:58 +02:00
|
|
|
if (!(_nm_logging_enabled_state[level] & domain))
|
2010-04-06 15:23:08 -07:00
|
|
|
return;
|
|
|
|
|
|
2016-12-11 22:33:19 +01:00
|
|
|
errno_saved = errno;
|
|
|
|
|
|
2014-12-05 00:54:30 +01:00
|
|
|
/* Make sure that %m maps to the specified error */
|
2015-09-23 16:03:41 +02:00
|
|
|
if (error != 0) {
|
|
|
|
|
if (error < 0)
|
|
|
|
|
error = -error;
|
2014-12-05 00:54:30 +01:00
|
|
|
errno = error;
|
2015-09-23 16:03:41 +02:00
|
|
|
}
|
2014-12-05 00:54:30 +01:00
|
|
|
|
2010-04-06 15:23:08 -07:00
|
|
|
va_start (args, fmt);
|
|
|
|
|
msg = g_strdup_vprintf (fmt, args);
|
|
|
|
|
va_end (args);
|
|
|
|
|
|
2016-10-06 15:55:01 +02:00
|
|
|
#define MESSAGE_FMT "%s%-7s [%ld.%04ld] %s"
|
|
|
|
|
#define MESSAGE_ARG(global, tv, msg) \
|
|
|
|
|
(global).prefix, \
|
2019-01-15 16:58:15 +01:00
|
|
|
level_desc[level].level_str, \
|
2016-10-06 15:55:01 +02:00
|
|
|
(tv).tv_sec, \
|
|
|
|
|
((tv).tv_usec / 100), \
|
|
|
|
|
(msg)
|
|
|
|
|
|
2016-08-19 12:06:23 +02:00
|
|
|
g_get_current_time (&tv);
|
2016-02-13 16:27:11 +01:00
|
|
|
|
2017-03-01 13:34:32 +01:00
|
|
|
if (global.debug_stderr)
|
|
|
|
|
g_printerr (MESSAGE_FMT"\n", MESSAGE_ARG (global, tv, msg));
|
|
|
|
|
|
2015-10-07 11:07:09 +02:00
|
|
|
switch (global.log_backend) {
|
2015-07-08 16:21:21 +02:00
|
|
|
#if SYSTEMD_JOURNAL
|
|
|
|
|
case LOG_BACKEND_JOURNAL:
|
|
|
|
|
{
|
|
|
|
|
gint64 now, boottime;
|
|
|
|
|
#define _NUM_MAX_FIELDS_SYSLOG_FACILITY 10
|
2016-10-06 16:55:12 +02:00
|
|
|
struct iovec iov_data[12 + _NUM_MAX_FIELDS_SYSLOG_FACILITY];
|
|
|
|
|
struct iovec *iov = iov_data;
|
2017-03-01 10:20:01 +00:00
|
|
|
gpointer iov_free_data[5];
|
2016-10-06 16:55:12 +02:00
|
|
|
gpointer *iov_free = iov_free_data;
|
|
|
|
|
nm_auto_free_gstring GString *s_domain_all = NULL;
|
2015-07-08 16:21:21 +02:00
|
|
|
|
|
|
|
|
now = nm_utils_get_monotonic_timestamp_ns ();
|
|
|
|
|
boottime = nm_utils_monotonic_timestamp_as_boottime (now, 1);
|
|
|
|
|
|
2019-01-15 16:58:15 +01:00
|
|
|
_iovec_set_format_a (iov++, 30, "PRIORITY=%d", level_desc[level].syslog_level);
|
2016-10-06 16:55:12 +02:00
|
|
|
_iovec_set_format (iov++, iov_free++, "MESSAGE="MESSAGE_FMT, MESSAGE_ARG (global, tv, msg));
|
|
|
|
|
_iovec_set_string (iov++, syslog_identifier_full (&global));
|
|
|
|
|
_iovec_set_format_a (iov++, 30, "SYSLOG_PID=%ld", (long) getpid ());
|
2015-07-08 16:21:21 +02:00
|
|
|
{
|
|
|
|
|
const LogDesc *diter;
|
|
|
|
|
int i_domain = _NUM_MAX_FIELDS_SYSLOG_FACILITY;
|
|
|
|
|
const char *s_domain_1 = NULL;
|
|
|
|
|
NMLogDomain dom_all = domain;
|
2016-05-19 19:01:58 +02:00
|
|
|
NMLogDomain dom = dom_all & _nm_logging_enabled_state[level];
|
2015-07-08 16:21:21 +02:00
|
|
|
|
2019-01-15 16:58:15 +01:00
|
|
|
for (diter = &domain_desc[0]; diter->name; diter++) {
|
2017-12-11 16:38:42 +01:00
|
|
|
if (!NM_FLAGS_ANY (dom_all, diter->num))
|
2015-07-08 16:21:21 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
/* construct a list of all domains (not only the enabled ones).
|
|
|
|
|
* Note that in by far most cases, there is only one domain present.
|
|
|
|
|
* Hence, save the construction of the GString. */
|
|
|
|
|
dom_all &= ~diter->num;
|
|
|
|
|
if (!s_domain_1)
|
|
|
|
|
s_domain_1 = diter->name;
|
|
|
|
|
else {
|
2016-10-06 16:55:12 +02:00
|
|
|
if (!s_domain_all) {
|
|
|
|
|
s_domain_all = g_string_new ("NM_LOG_DOMAINS=");
|
|
|
|
|
g_string_append (s_domain_all, s_domain_1);
|
|
|
|
|
}
|
2015-07-08 16:21:21 +02:00
|
|
|
g_string_append_c (s_domain_all, ',');
|
|
|
|
|
g_string_append (s_domain_all, diter->name);
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-11 16:38:42 +01:00
|
|
|
if (NM_FLAGS_ANY (dom, diter->num)) {
|
2015-07-08 16:21:21 +02:00
|
|
|
if (i_domain > 0) {
|
|
|
|
|
/* SYSLOG_FACILITY is specified multiple times for each domain that is actually enabled. */
|
2019-01-10 12:00:34 +01:00
|
|
|
_iovec_set_format_str_a (iov++, 30, "SYSLOG_FACILITY=%s", diter->name);
|
2015-07-08 16:21:21 +02:00
|
|
|
i_domain--;
|
|
|
|
|
}
|
|
|
|
|
dom &= ~diter->num;
|
|
|
|
|
}
|
|
|
|
|
if (!dom && !dom_all)
|
|
|
|
|
break;
|
|
|
|
|
}
|
2016-10-06 16:55:12 +02:00
|
|
|
if (s_domain_all)
|
|
|
|
|
_iovec_set (iov++, s_domain_all->str, s_domain_all->len);
|
|
|
|
|
else
|
2019-01-10 12:00:34 +01:00
|
|
|
_iovec_set_format_str_a (iov++, 30, "NM_LOG_DOMAINS=%s", s_domain_1);
|
2015-07-08 16:21:21 +02:00
|
|
|
}
|
2019-01-15 16:58:15 +01:00
|
|
|
_iovec_set_format_str_a (iov++, 15, "NM_LOG_LEVEL=%s", level_desc[level].name);
|
2016-07-05 18:43:49 +02:00
|
|
|
if (func)
|
2016-10-06 16:55:12 +02:00
|
|
|
_iovec_set_format (iov++, iov_free++, "CODE_FUNC=%s", func);
|
|
|
|
|
_iovec_set_format (iov++, iov_free++, "CODE_FILE=%s", file ?: "");
|
|
|
|
|
_iovec_set_format_a (iov++, 20, "CODE_LINE=%u", line);
|
|
|
|
|
_iovec_set_format_a (iov++, 60, "TIMESTAMP_MONOTONIC=%lld.%06lld", (long long) (now / NM_UTILS_NS_PER_SECOND), (long long) ((now % NM_UTILS_NS_PER_SECOND) / 1000));
|
|
|
|
|
_iovec_set_format_a (iov++, 60, "TIMESTAMP_BOOTTIME=%lld.%06lld", (long long) (boottime / NM_UTILS_NS_PER_SECOND), (long long) ((boottime % NM_UTILS_NS_PER_SECOND) / 1000));
|
2015-07-08 16:21:21 +02:00
|
|
|
if (error != 0)
|
2016-10-06 16:55:12 +02:00
|
|
|
_iovec_set_format_a (iov++, 30, "ERRNO=%d", error);
|
2017-03-01 10:20:01 +00:00
|
|
|
if (ifname)
|
|
|
|
|
_iovec_set_format (iov++, iov_free++, "NM_DEVICE=%s", ifname);
|
|
|
|
|
if (conn_uuid)
|
|
|
|
|
_iovec_set_format (iov++, iov_free++, "NM_CONNECTION=%s", conn_uuid);
|
2015-07-08 16:21:21 +02:00
|
|
|
|
2016-10-06 16:55:12 +02:00
|
|
|
nm_assert (iov <= &iov_data[G_N_ELEMENTS (iov_data)]);
|
|
|
|
|
nm_assert (iov_free <= &iov_free_data[G_N_ELEMENTS (iov_free_data)]);
|
2015-07-08 16:21:21 +02:00
|
|
|
|
2016-10-06 16:55:12 +02:00
|
|
|
sd_journal_sendv (iov_data, iov - iov_data);
|
2015-07-08 16:21:21 +02:00
|
|
|
|
2016-10-06 16:55:12 +02:00
|
|
|
for (; --iov_free >= iov_free_data; )
|
|
|
|
|
g_free (*iov_free);
|
2015-07-08 16:21:21 +02:00
|
|
|
}
|
2015-07-08 17:13:59 +02:00
|
|
|
break;
|
2015-07-08 16:21:21 +02:00
|
|
|
#endif
|
2016-10-06 15:55:01 +02:00
|
|
|
case LOG_BACKEND_SYSLOG:
|
2019-01-15 16:58:15 +01:00
|
|
|
syslog (level_desc[level].syslog_level,
|
2016-10-06 15:55:01 +02:00
|
|
|
MESSAGE_FMT, MESSAGE_ARG (global, tv, msg));
|
|
|
|
|
break;
|
2015-07-08 17:13:59 +02:00
|
|
|
default:
|
2019-01-15 16:58:15 +01:00
|
|
|
g_log (syslog_identifier_domain (&global), level_desc[level].g_log_level,
|
2016-10-06 15:55:01 +02:00
|
|
|
MESSAGE_FMT, MESSAGE_ARG (global, tv, msg));
|
2015-07-08 16:21:21 +02:00
|
|
|
break;
|
2015-07-08 17:13:59 +02:00
|
|
|
}
|
2013-06-14 14:51:04 -04:00
|
|
|
|
2010-04-06 15:23:08 -07:00
|
|
|
g_free (msg);
|
2016-12-11 22:33:19 +01:00
|
|
|
|
|
|
|
|
errno = errno_saved;
|
2010-04-06 15:23:08 -07:00
|
|
|
}
|
|
|
|
|
|
2016-10-02 18:22:50 +02:00
|
|
|
/*****************************************************************************/
|
2010-04-06 15:23:08 -07:00
|
|
|
|
2018-10-12 17:16:34 +02:00
|
|
|
void
|
|
|
|
|
_nm_utils_monotonic_timestamp_initialized (const struct timespec *tp,
|
2018-11-25 17:45:11 +01:00
|
|
|
gint64 offset_sec,
|
|
|
|
|
gboolean is_boottime)
|
2018-10-12 17:16:34 +02:00
|
|
|
{
|
|
|
|
|
if (nm_logging_enabled (LOGL_DEBUG, LOGD_CORE)) {
|
|
|
|
|
time_t now = time (NULL);
|
|
|
|
|
struct tm tm;
|
|
|
|
|
char s[255];
|
|
|
|
|
|
|
|
|
|
strftime (s, sizeof (s), "%Y-%m-%d %H:%M:%S", localtime_r (&now, &tm));
|
|
|
|
|
nm_log_dbg (LOGD_CORE, "monotonic timestamp started counting 1.%09ld seconds ago with "
|
|
|
|
|
"an offset of %lld.0 seconds to %s (local time is %s)",
|
|
|
|
|
tp->tv_nsec,
|
|
|
|
|
(long long) -offset_sec,
|
|
|
|
|
is_boottime ? "CLOCK_BOOTTIME" : "CLOCK_MONOTONIC", s);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2006-02-27 04:31:52 +00:00
|
|
|
static void
|
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 07:40:19 +02:00
|
|
|
nm_log_handler (const char *log_domain,
|
2010-04-06 15:23:08 -07:00
|
|
|
GLogLevelFlags level,
|
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 07:40:19 +02:00
|
|
|
const char *message,
|
2010-04-06 15:23:08 -07:00
|
|
|
gpointer ignored)
|
2006-02-27 04:31:52 +00:00
|
|
|
{
|
2015-07-08 16:21:21 +02:00
|
|
|
int syslog_priority;
|
2006-02-27 04:31:52 +00:00
|
|
|
|
2014-04-24 20:01:13 +02:00
|
|
|
switch (level & G_LOG_LEVEL_MASK) {
|
2010-04-06 15:23:08 -07:00
|
|
|
case G_LOG_LEVEL_ERROR:
|
|
|
|
|
syslog_priority = LOG_CRIT;
|
|
|
|
|
break;
|
|
|
|
|
case G_LOG_LEVEL_CRITICAL:
|
|
|
|
|
syslog_priority = LOG_ERR;
|
|
|
|
|
break;
|
|
|
|
|
case G_LOG_LEVEL_WARNING:
|
|
|
|
|
syslog_priority = LOG_WARNING;
|
|
|
|
|
break;
|
|
|
|
|
case G_LOG_LEVEL_MESSAGE:
|
|
|
|
|
syslog_priority = LOG_NOTICE;
|
|
|
|
|
break;
|
|
|
|
|
case G_LOG_LEVEL_DEBUG:
|
|
|
|
|
syslog_priority = LOG_DEBUG;
|
|
|
|
|
break;
|
|
|
|
|
case G_LOG_LEVEL_INFO:
|
|
|
|
|
default:
|
|
|
|
|
syslog_priority = LOG_INFO;
|
|
|
|
|
break;
|
2006-02-27 04:31:52 +00:00
|
|
|
}
|
|
|
|
|
|
2018-02-06 14:47:48 +01:00
|
|
|
if (global.debug_stderr)
|
|
|
|
|
g_printerr ("%s%s\n", global.prefix, message ?: "");
|
|
|
|
|
|
2015-10-07 11:07:09 +02:00
|
|
|
switch (global.log_backend) {
|
2015-07-08 16:21:21 +02:00
|
|
|
#if SYSTEMD_JOURNAL
|
|
|
|
|
case LOG_BACKEND_JOURNAL:
|
|
|
|
|
{
|
|
|
|
|
gint64 now, boottime;
|
|
|
|
|
|
|
|
|
|
now = nm_utils_get_monotonic_timestamp_ns ();
|
|
|
|
|
boottime = nm_utils_monotonic_timestamp_as_boottime (now, 1);
|
|
|
|
|
|
|
|
|
|
sd_journal_send ("PRIORITY=%d", syslog_priority,
|
2016-10-05 15:25:08 +02:00
|
|
|
"MESSAGE=%s%s", global.prefix, message ?: "",
|
2016-10-05 15:52:55 +02:00
|
|
|
syslog_identifier_full (&global),
|
2015-07-08 16:21:21 +02:00
|
|
|
"SYSLOG_PID=%ld", (long) getpid (),
|
|
|
|
|
"SYSLOG_FACILITY=GLIB",
|
2016-03-08 17:41:31 +01:00
|
|
|
"GLIB_DOMAIN=%s", log_domain ?: "",
|
2015-07-08 16:21:21 +02:00
|
|
|
"GLIB_LEVEL=%d", (int) (level & G_LOG_LEVEL_MASK),
|
|
|
|
|
"TIMESTAMP_MONOTONIC=%lld.%06lld", (long long) (now / NM_UTILS_NS_PER_SECOND), (long long) ((now % NM_UTILS_NS_PER_SECOND) / 1000),
|
|
|
|
|
"TIMESTAMP_BOOTTIME=%lld.%06lld", (long long) (boottime / NM_UTILS_NS_PER_SECOND), (long long) ((boottime % NM_UTILS_NS_PER_SECOND) / 1000),
|
|
|
|
|
NULL);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
#endif
|
|
|
|
|
default:
|
2016-10-05 15:25:08 +02:00
|
|
|
syslog (syslog_priority, "%s%s", global.prefix, message ?: "");
|
2015-07-08 16:21:21 +02:00
|
|
|
break;
|
|
|
|
|
}
|
2006-02-27 04:31:52 +00:00
|
|
|
}
|
|
|
|
|
|
2016-05-23 12:02:31 +02:00
|
|
|
gboolean
|
|
|
|
|
nm_logging_syslog_enabled (void)
|
|
|
|
|
{
|
|
|
|
|
return global.uses_syslog;
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-05 15:25:08 +02:00
|
|
|
void
|
|
|
|
|
nm_logging_set_prefix (const char *format, ...)
|
|
|
|
|
{
|
|
|
|
|
char *prefix;
|
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
|
|
/* prefix can only be set once, to a non-empty string. Also, after
|
|
|
|
|
* nm_logging_syslog_openlog() the prefix cannot be set either. */
|
|
|
|
|
if (global.log_backend != LOG_BACKEND_GLIB)
|
|
|
|
|
g_return_if_reached ();
|
|
|
|
|
if (global.prefix[0])
|
|
|
|
|
g_return_if_reached ();
|
|
|
|
|
|
|
|
|
|
va_start (ap, format);
|
|
|
|
|
prefix = g_strdup_vprintf (format, ap);
|
|
|
|
|
va_end (ap);
|
|
|
|
|
|
|
|
|
|
if (!prefix || !prefix[0])
|
|
|
|
|
g_return_if_reached ();
|
|
|
|
|
|
|
|
|
|
/* we pass the allocated string on and never free it. */
|
|
|
|
|
global.prefix = prefix;
|
|
|
|
|
}
|
|
|
|
|
|
2006-02-27 04:31:52 +00:00
|
|
|
void
|
2017-03-01 13:34:32 +01:00
|
|
|
nm_logging_syslog_openlog (const char *logging_backend, gboolean debug)
|
2006-02-27 04:31:52 +00:00
|
|
|
{
|
2018-06-21 08:59:23 +02:00
|
|
|
gboolean fetch_monotonic_timestamp = FALSE;
|
2018-06-21 09:21:57 +02:00
|
|
|
gboolean obsolete_debug_backend = FALSE;
|
|
|
|
|
|
|
|
|
|
nm_assert (NM_IN_STRSET (""NM_CONFIG_DEFAULT_LOGGING_BACKEND,
|
|
|
|
|
NM_LOG_CONFIG_BACKEND_JOURNAL,
|
|
|
|
|
NM_LOG_CONFIG_BACKEND_SYSLOG));
|
2018-06-21 08:59:23 +02:00
|
|
|
|
2015-10-07 11:07:09 +02:00
|
|
|
if (global.log_backend != LOG_BACKEND_GLIB)
|
2015-07-08 17:01:15 +02:00
|
|
|
g_return_if_reached ();
|
2015-07-08 17:13:59 +02:00
|
|
|
|
2015-07-08 21:44:01 +02:00
|
|
|
if (!logging_backend)
|
2016-11-25 14:17:30 +01:00
|
|
|
logging_backend = ""NM_CONFIG_DEFAULT_LOGGING_BACKEND;
|
2015-07-08 21:44:01 +02:00
|
|
|
|
2018-06-21 09:21:57 +02:00
|
|
|
if (nm_streq (logging_backend, NM_LOG_CONFIG_BACKEND_DEBUG)) {
|
|
|
|
|
/* "debug" was wrongly documented as a valid logging backend. It makes no sense however,
|
|
|
|
|
* because printing to stderr only makes sense when not demonizing. Whether to daemonize
|
|
|
|
|
* is only controlled via command line arguments (--no-daemon, --debug) and not via the
|
|
|
|
|
* logging backend from configuration.
|
|
|
|
|
*
|
|
|
|
|
* Fall back to the default. */
|
|
|
|
|
logging_backend = ""NM_CONFIG_DEFAULT_LOGGING_BACKEND;
|
|
|
|
|
obsolete_debug_backend = TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-08 16:21:21 +02:00
|
|
|
#if SYSTEMD_JOURNAL
|
2018-06-21 09:21:57 +02:00
|
|
|
if (!nm_streq (logging_backend, NM_LOG_CONFIG_BACKEND_SYSLOG)) {
|
2016-02-13 16:27:11 +01:00
|
|
|
global.log_backend = LOG_BACKEND_JOURNAL;
|
2016-05-23 12:02:31 +02:00
|
|
|
global.uses_syslog = TRUE;
|
2017-03-01 13:34:32 +01:00
|
|
|
global.debug_stderr = debug;
|
2018-06-21 08:59:23 +02:00
|
|
|
fetch_monotonic_timestamp = TRUE;
|
2017-03-01 13:34:32 +01:00
|
|
|
} else
|
2015-07-08 16:21:21 +02:00
|
|
|
#endif
|
2017-03-01 13:34:32 +01:00
|
|
|
{
|
2015-10-07 11:07:09 +02:00
|
|
|
global.log_backend = LOG_BACKEND_SYSLOG;
|
2016-05-23 12:02:31 +02:00
|
|
|
global.uses_syslog = TRUE;
|
2017-03-01 13:34:32 +01:00
|
|
|
global.debug_stderr = debug;
|
2016-10-05 15:52:55 +02:00
|
|
|
openlog (syslog_identifier_domain (&global), LOG_PID, LOG_DAEMON);
|
2015-07-08 16:21:21 +02:00
|
|
|
}
|
2013-06-14 14:51:04 -04:00
|
|
|
|
2016-10-05 15:52:55 +02:00
|
|
|
g_log_set_handler (syslog_identifier_domain (&global),
|
2015-07-08 17:01:15 +02:00
|
|
|
G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION,
|
|
|
|
|
nm_log_handler,
|
|
|
|
|
NULL);
|
2006-02-27 04:31:52 +00:00
|
|
|
|
2018-06-21 08:59:23 +02:00
|
|
|
if (fetch_monotonic_timestamp) {
|
|
|
|
|
/* ensure we read a monotonic timestamp. Reading the timestamp the first
|
|
|
|
|
* time causes a logging message. We don't want to do that during _nm_log_impl. */
|
|
|
|
|
nm_utils_get_monotonic_timestamp_ns ();
|
|
|
|
|
}
|
2018-06-21 09:21:57 +02:00
|
|
|
|
|
|
|
|
if (obsolete_debug_backend)
|
|
|
|
|
nm_log_dbg (LOGD_CORE, "config: ignore deprecated logging backend 'debug', fallback to '%s'", logging_backend);
|
|
|
|
|
|
|
|
|
|
if (nm_streq (logging_backend, NM_LOG_CONFIG_BACKEND_SYSLOG)) {
|
|
|
|
|
/* good */
|
|
|
|
|
} else if (nm_streq (logging_backend, NM_LOG_CONFIG_BACKEND_JOURNAL)) {
|
|
|
|
|
#if !SYSTEMD_JOURNAL
|
|
|
|
|
nm_log_warn (LOGD_CORE, "config: logging backend 'journal' is not available, fallback to 'syslog'");
|
|
|
|
|
#endif
|
|
|
|
|
} else {
|
|
|
|
|
nm_log_warn (LOGD_CORE, "config: invalid logging backend '%s', fallback to '%s'",
|
|
|
|
|
logging_backend,
|
|
|
|
|
#if SYSTEMD_JOURNAL
|
|
|
|
|
NM_LOG_CONFIG_BACKEND_JOURNAL
|
|
|
|
|
#else
|
|
|
|
|
NM_LOG_CONFIG_BACKEND_SYSLOG
|
|
|
|
|
#endif
|
|
|
|
|
);
|
|
|
|
|
}
|
2018-06-21 08:59:23 +02:00
|
|
|
}
|