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:
+29
-1
@@ -684,7 +684,7 @@ int find_executable_full(
|
||||
* binary. */
|
||||
p = getenv("PATH");
|
||||
if (!p)
|
||||
p = DEFAULT_PATH;
|
||||
p = default_PATH();
|
||||
|
||||
if (exec_search_path) {
|
||||
STRV_FOREACH(element, exec_search_path) {
|
||||
@@ -1441,3 +1441,31 @@ int path_glob_can_match(const char *pattern, const char *prefix, char **ret) {
|
||||
*ret = NULL;
|
||||
return false;
|
||||
}
|
||||
|
||||
const char* default_PATH(void) {
|
||||
#if HAVE_SPLIT_BIN
|
||||
static int split = -1;
|
||||
int r;
|
||||
|
||||
/* Check whether /usr/sbin is not a symlink and return the appropriate $PATH.
|
||||
* On error fall back to the safe value with both directories as configured… */
|
||||
|
||||
if (split < 0)
|
||||
STRV_FOREACH_PAIR(bin, sbin, STRV_MAKE("/usr/bin", "/usr/sbin",
|
||||
"/usr/local/bin", "/usr/local/sbin")) {
|
||||
r = inode_same(*bin, *sbin, AT_NO_AUTOMOUNT);
|
||||
if (r > 0 || r == -ENOENT)
|
||||
continue;
|
||||
if (r < 0)
|
||||
log_debug_errno(r, "Failed to compare \"%s\" and \"%s\", using compat $PATH: %m",
|
||||
*bin, *sbin);
|
||||
split = true;
|
||||
break;
|
||||
}
|
||||
if (split < 0)
|
||||
split = false;
|
||||
if (split)
|
||||
return DEFAULT_PATH_WITH_SBIN;
|
||||
#endif
|
||||
return DEFAULT_PATH_WITHOUT_SBIN;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user