Try path without sbin even if compiled with split-bin=true

I'm working on the transition to merged sbin in Fedora. While the transition is
happening (and probably for a while after), we need to compile systemd with
split-bin=true to support systems upgraded from previous versions. But when the
system has been upgraded and already has /usr/sbin that is a symlink, be nice
and give $PATH without sbin.

We check for both /usr/sbin and /usr/local/sbin. If either exists and is not a
symlink to ./bin, we retain previous behaviour. This means that if both are
converted, we get the same behaviour as split-bin=false, and otherwise we
get the same behaviour as before.

sd-path uses the same logic. This is not a hot path, so I got rid of the nulstr
macros that duplicated the logic.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2024-04-22 09:53:24 +02:00
parent 18d2641236
commit 0f36a4c897
6 changed files with 69 additions and 33 deletions
+4 -5
View File
@@ -331,7 +331,7 @@ TEST(environment_gathering) {
assert_se(chmod(name3, 0755) == 0);
/* When booting in containers or without initrd there might not be any PATH in the environment and if
* there is no PATH /bin/sh built-in PATH may leak and override systemd's DEFAULT_PATH which is not
* there is no PATH /bin/sh built-in PATH may leak and override systemd's default path which is not
* good. Force our own PATH in environment, to prevent expansion of sh built-in $PATH */
old = getenv("PATH");
r = setenv("PATH", "no-sh-built-in-path", 1);
@@ -351,10 +351,9 @@ TEST(environment_gathering) {
ASSERT_STREQ(strv_env_get(env, "C"), "001");
ASSERT_STREQ(strv_env_get(env, "PATH"), "no-sh-built-in-path:/no/such/file");
/* now retest with "default" path passed in, as created by
* manager_default_environment */
/* Now retest with some "default" path passed. */
env = strv_free(env);
env = strv_new("PATH=" DEFAULT_PATH);
env = strv_new("PATH=" DEFAULT_PATH_WITHOUT_SBIN);
assert_se(env);
r = execute_directories(dirs, DEFAULT_TIMEOUT_USEC, gather_environment, args, NULL, env, EXEC_DIR_PARALLEL | EXEC_DIR_IGNORE_ERRORS);
@@ -366,7 +365,7 @@ TEST(environment_gathering) {
ASSERT_STREQ(strv_env_get(env, "A"), "22:23:24");
ASSERT_STREQ(strv_env_get(env, "B"), "12");
ASSERT_STREQ(strv_env_get(env, "C"), "001");
ASSERT_STREQ(strv_env_get(env, "PATH"), DEFAULT_PATH ":/no/such/file");
ASSERT_STREQ(strv_env_get(env, "PATH"), DEFAULT_PATH_WITHOUT_SBIN ":/no/such/file");
/* reset environ PATH */
assert_se(set_unset_env("PATH", old, true) == 0);
+2 -2
View File
@@ -18,8 +18,8 @@
#include "tmpfile-util.h"
TEST(print_paths) {
log_info("DEFAULT_PATH=%s", DEFAULT_PATH);
log_info("DEFAULT_USER_PATH=%s", DEFAULT_USER_PATH);
log_info("default system PATH: %s", default_PATH());
log_info("default user PATH: %s", default_user_PATH());
}
TEST(path) {