| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
|
| 3 |
#include <pthread.h> |
| 4 |
#include <stdlib.h> |
| 5 |
|
| 6 |
#include "sd-json.h" |
| 7 |
|
| 8 |
#include "assert-util.h" |
| 9 |
#include "log.h" |
| 10 |
#include "log-assert-critical.h" |
| 11 |
#include "nss-util.h" |
| 12 |
|
| 13 |
sd_json_dispatch_flags_t nss_json_dispatch_flags = SD_JSON_ALLOW_EXTENSIONS; |
| 14 |
|
| 15 |
static void log_setup_nss_internal(void) { |
| 16 |
int r; |
| 17 |
|
| 18 |
log_set_assert_return_is_critical_from_env(); |
| 19 |
log_parse_environment_variables(); |
| 20 |
|
| 21 |
const char *e = getenv("SYSTEMD_NSS_LOG_LEVEL"); |
| 22 |
if (e) { |
| 23 |
/* NSS plugins are linked statically to all of our own libraries so this will only override |
| 24 |
* the log level for the NSS plugin, and not for the entire systemd binary, since each will |
| 25 |
* have their own log_level TLS variable. */ |
| 26 |
r = log_set_max_level_from_string(e); |
| 27 |
if (r < 0) |
| 28 |
log_warning_errno(r, "Failed to parse NSS log level '%s', ignoring: %m", e); |
| 29 |
} |
| 30 |
|
| 31 |
if (DEBUG_LOGGING) |
| 32 |
nss_json_dispatch_flags = SD_JSON_LOG; |
| 33 |
} |
| 34 |
|
| 35 |
void log_setup_nss(void) { |
| 36 |
static pthread_once_t once = PTHREAD_ONCE_INIT; |
| 37 |
assert_se(pthread_once(&once, log_setup_nss_internal) == 0); |
| 38 |
} |