1
0
mirror of https://github.com/systemd/systemd synced 2026-04-12 18:14:51 +02:00

Compare commits

...

7 Commits

Author SHA1 Message Date
Yu Watanabe
d5f8fd5b00 network: dhcp6: do not request address if UseAddress=no
Fixes #22068.
2022-01-11 17:05:12 +00:00
Luca Boccassi
1d18a466c4
Merge pull request #22086 from keszybz/nss-no-proc-cmdline
Avoid looking at /prcc/cmdline from nss modules
2022-01-11 15:29:24 +00:00
Luca Boccassi
07b0de6584
Merge pull request #22082 from keszybz/no-update-if-nothing-to-update
bootctl: skip update if sd-boot wasn't installed
2022-01-11 15:28:35 +00:00
Zbigniew Jędrzejewski-Szmek
a7d15a2465 nss: only read logging config from environment variables
log_parse_environment() uses should_parse_proc_cmdline() to determine whether
it should parse settings from the kernel command line. But the checks that
should_parse_proc_cmdline() apply to the whole process, and we could get a positive
answer also when log_parse_environment() was called from one of the nss modules.
In case of nss-modules, we don't want to look at the kernel command line.

log_parse_environment_variables() that only looks at the environment variables
is split out and used in the nss modules.

Fixes #22020.
2022-01-11 13:39:52 +01:00
Zbigniew Jędrzejewski-Szmek
56a5f4969b nss: drop dummy setup_logging() helpers
log_parse_environment() stopped being a macro in 9fdee66f2d9.
As reported by @bauen1 in https://github.com/systemd/systemd/issues/22020,
the comment was out of date.
2022-01-11 13:39:52 +01:00
Zbigniew Jędrzejewski-Szmek
49927ad813 bootctl: do not update sd-boot if it wasn't installed in the first place
Fixes https://bugzilla.redhat.com/show_bug.cgi?id=2038289.
2022-01-11 10:57:36 +01:00
Zbigniew Jędrzejewski-Szmek
d9f048b5d1 bootctl: split out the check whether sd-boot is installed 2022-01-11 10:56:29 +01:00
7 changed files with 70 additions and 47 deletions

View File

@ -1189,14 +1189,9 @@ static bool should_parse_proc_cmdline(void) {
return getpid_cached() == p; return getpid_cached() == p;
} }
void log_parse_environment(void) { void log_parse_environment_variables(void) {
const char *e; const char *e;
/* Do not call from library code. */
if (should_parse_proc_cmdline())
(void) proc_cmdline_parse(parse_proc_cmdline_item, NULL, PROC_CMDLINE_STRIP_RD_PREFIX);
e = getenv("SYSTEMD_LOG_TARGET"); e = getenv("SYSTEMD_LOG_TARGET");
if (e && log_set_target_from_string(e) < 0) if (e && log_set_target_from_string(e) < 0)
log_warning("Failed to parse log target '%s'. Ignoring.", e); log_warning("Failed to parse log target '%s'. Ignoring.", e);
@ -1222,6 +1217,15 @@ void log_parse_environment(void) {
log_warning("Failed to parse log tid '%s'. Ignoring.", e); log_warning("Failed to parse log tid '%s'. Ignoring.", e);
} }
void log_parse_environment(void) {
/* Do not call from library code. */
if (should_parse_proc_cmdline())
(void) proc_cmdline_parse(parse_proc_cmdline_item, NULL, PROC_CMDLINE_STRIP_RD_PREFIX);
log_parse_environment_variables();
}
LogTarget log_get_target(void) { LogTarget log_get_target(void) {
return log_target; return log_target;
} }

View File

@ -82,6 +82,7 @@ int log_open(void);
void log_close(void); void log_close(void);
void log_forget_fds(void); void log_forget_fds(void);
void log_parse_environment_variables(void);
void log_parse_environment(void); void log_parse_environment(void);
int log_dispatch_internal( int log_dispatch_internal(

View File

@ -1382,6 +1382,39 @@ static void print_yes_no_line(bool first, bool good, const char *name) {
name); name);
} }
static int are_we_installed(void) {
int r;
r = acquire_esp(/* privileged_mode= */ false, /* graceful= */ false, NULL, NULL, NULL, NULL);
if (r < 0)
return r;
/* Tests whether systemd-boot is installed. It's not obvious what to use as check here: we could
* check EFI variables, we could check what binary /EFI/BOOT/BOOT*.EFI points to, or whether the
* loader entries directory exists. Here we opted to check whether /EFI/systemd/ is non-empty, which
* should be a suitable and very minimal check for a number of reasons:
*
* The check is architecture independent (i.e. we check if any systemd-boot loader is installed,
* not a specific one.)
*
* It doesn't assume we are the only boot loader (i.e doesn't check if we own the main
* /EFI/BOOT/BOOT*.EFI fallback binary.
*
* It specifically checks for systemd-boot, not for other boot loaders (which a check for
* /boot/loader/entries would do). */
_cleanup_free_ char *p = path_join(arg_esp_path, "/EFI/systemd/");
if (!p)
return log_oom();
log_debug("Checking whether %s contains any files…", p);
r = dir_is_empty(p);
if (r < 0 && r != -ENOENT)
return log_error_errno(r, "Failed to check whether %s contains any files: %m", p);
return r == 0;
}
static int verb_status(int argc, char *argv[], void *userdata) { static int verb_status(int argc, char *argv[], void *userdata) {
sd_id128_t esp_uuid = SD_ID128_NULL, xbootldr_uuid = SD_ID128_NULL; sd_id128_t esp_uuid = SD_ID128_NULL, xbootldr_uuid = SD_ID128_NULL;
int r, k; int r, k;
@ -1758,6 +1791,17 @@ static int verb_install(int argc, char *argv[], void *userdata) {
if (r < 0) if (r < 0)
return r; return r;
if (!install) {
/* If we are updating, don't do anything if sd-boot wasn't actually installed. */
r = are_we_installed();
if (r < 0)
return r;
if (r == 0) {
log_debug("Skipping update because sd-boot is not installed in the ESP.");
return 0;
}
}
r = acquire_xbootldr(/* unprivileged_mode= */ false, NULL); r = acquire_xbootldr(/* unprivileged_mode= */ false, NULL);
if (r < 0) if (r < 0)
return r; return r;
@ -1880,41 +1924,19 @@ static int verb_remove(int argc, char *argv[], void *userdata) {
} }
static int verb_is_installed(int argc, char *argv[], void *userdata) { static int verb_is_installed(int argc, char *argv[], void *userdata) {
_cleanup_free_ char *p = NULL;
int r; int r;
r = acquire_esp(/* privileged_mode= */ false, /* graceful= */ false, NULL, NULL, NULL, NULL); r = are_we_installed();
if (r < 0) if (r < 0)
return r; return r;
/* Tests whether systemd-boot is installed. It's not obvious what to use as check here: we could if (r > 0) {
* check EFI variables, we could check what binary /EFI/BOOT/BOOT*.EFI points to, or whether the puts("yes");
* loader entries directory exists. Here we opted to check whether /EFI/systemd/ is non-empty, which return EXIT_SUCCESS;
* should be a suitable and very minimal check for a number of reasons: } else {
*
* The check is architecture independent (i.e. we check if any systemd-boot loader is installed, not a
* specific one.)
*
* It doesn't assume we are the only boot loader (i.e doesn't check if we own the main
* /EFI/BOOT/BOOT*.EFI fallback binary.
*
* It specifically checks for systemd-boot, not for other boot loaders (which a check for
* /boot/loader/entries would do). */
p = path_join(arg_esp_path, "/EFI/systemd/");
if (!p)
return log_oom();
r = dir_is_empty(p);
if (r > 0 || r == -ENOENT) {
puts("no"); puts("no");
return EXIT_FAILURE; return EXIT_FAILURE;
} }
if (r < 0)
return log_error_errno(r, "Failed to detect whether systemd-boot is installed: %m");
puts("yes");
return EXIT_SUCCESS;
} }
static int parse_timeout(const char *arg1, char16_t **ret_timeout, size_t *ret_timeout_size) { static int parse_timeout(const char *arg1, char16_t **ret_timeout, size_t *ret_timeout_size) {

View File

@ -646,9 +646,15 @@ static int dhcp6_configure(Link *link) {
r = sd_dhcp6_client_set_prefix_delegation(client, link->network->dhcp6_use_pd_prefix); r = sd_dhcp6_client_set_prefix_delegation(client, link->network->dhcp6_use_pd_prefix);
if (r < 0) if (r < 0)
return log_link_debug_errno(link, r, "DHCPv6 CLIENT: Failed to %s prefix delegation: %m", return log_link_debug_errno(link, r, "DHCPv6 CLIENT: Failed to %s requesting prefixes to be delegated: %m",
enable_disable(link->network->dhcp6_use_pd_prefix)); enable_disable(link->network->dhcp6_use_pd_prefix));
/* Even if UseAddress=no, we need to request IA_NA, as the dhcp6 client may be started in managed mode. */
r = sd_dhcp6_client_set_address_request(client, link->network->dhcp6_use_pd_prefix ? link->network->dhcp6_use_address : true);
if (r < 0)
return log_link_debug_errno(link, r, "DHCPv6 CLIENT: Failed to %s requesting address: %m",
enable_disable(link->network->dhcp6_use_address));
if (link->network->dhcp6_pd_prefix_length > 0) { if (link->network->dhcp6_pd_prefix_length > 0) {
r = sd_dhcp6_client_set_prefix_delegation_hint(client, r = sd_dhcp6_client_set_prefix_delegation_hint(client,
link->network->dhcp6_pd_prefix_length, link->network->dhcp6_pd_prefix_length,

View File

@ -22,14 +22,9 @@
#include "signal-util.h" #include "signal-util.h"
#include "string-util.h" #include "string-util.h"
static void setup_logging(void) {
/* We need a dummy function because log_parse_environment is a macro. */
log_parse_environment();
}
static void setup_logging_once(void) { static void setup_logging_once(void) {
static pthread_once_t once = PTHREAD_ONCE_INIT; static pthread_once_t once = PTHREAD_ONCE_INIT;
assert_se(pthread_once(&once, setup_logging) == 0); assert_se(pthread_once(&once, log_parse_environment_variables) == 0);
} }
#define NSS_ENTRYPOINT_BEGIN \ #define NSS_ENTRYPOINT_BEGIN \

View File

@ -22,7 +22,7 @@
static JsonDispatchFlags json_dispatch_flags = 0; static JsonDispatchFlags json_dispatch_flags = 0;
static void setup_logging(void) { static void setup_logging(void) {
log_parse_environment(); log_parse_environment_variables();
if (DEBUG_LOGGING) if (DEBUG_LOGGING)
json_dispatch_flags = JSON_LOG; json_dispatch_flags = JSON_LOG;

View File

@ -116,14 +116,9 @@ static GetentData getsgent_data = {
.mutex = PTHREAD_MUTEX_INITIALIZER, .mutex = PTHREAD_MUTEX_INITIALIZER,
}; };
static void setup_logging(void) {
/* We need a dummy function because log_parse_environment is a macro. */
log_parse_environment();
}
static void setup_logging_once(void) { static void setup_logging_once(void) {
static pthread_once_t once = PTHREAD_ONCE_INIT; static pthread_once_t once = PTHREAD_ONCE_INIT;
assert_se(pthread_once(&once, setup_logging) == 0); assert_se(pthread_once(&once, log_parse_environment_variables) == 0);
} }
#define NSS_ENTRYPOINT_BEGIN \ #define NSS_ENTRYPOINT_BEGIN \