Merge pull request #15955 from anitazha/nullorempty
core: check null_or_empty_path for masked units instead of /dev/null
This commit is contained in:
+24
-11
@@ -1236,8 +1236,7 @@ static int unit_file_load(
|
||||
"%s: unit type %s cannot be templated, ignoring.", path, unit_type_to_string(type));
|
||||
|
||||
if (!(flags & SEARCH_LOAD)) {
|
||||
r = lstat(path, &st);
|
||||
if (r < 0)
|
||||
if (lstat(path, &st) < 0)
|
||||
return -errno;
|
||||
|
||||
if (null_or_empty(&st))
|
||||
@@ -1324,26 +1323,40 @@ static int unit_file_load_or_readlink(
|
||||
const char *path,
|
||||
const char *root_dir,
|
||||
SearchFlags flags) {
|
||||
|
||||
_cleanup_free_ char *target = NULL;
|
||||
_cleanup_free_ char *resolved = NULL;
|
||||
struct stat st;
|
||||
int r;
|
||||
|
||||
r = unit_file_load(c, info, path, root_dir, flags);
|
||||
if (r != -ELOOP || (flags & SEARCH_DROPIN))
|
||||
return r;
|
||||
|
||||
/* This is a symlink, let's read it. */
|
||||
|
||||
r = readlink_malloc(path, &target);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (path_equal(target, "/dev/null"))
|
||||
r = chase_symlinks(path, root_dir, CHASE_WARN | CHASE_NONEXISTENT, &resolved, NULL);
|
||||
if (r >= 0 &&
|
||||
root_dir &&
|
||||
path_equal_ptr(path_startswith(resolved, root_dir), "dev/null"))
|
||||
/* When looking under root_dir, we can't expect /dev/ to be mounted,
|
||||
* so let's see if the path is a (possibly dangling) symlink to /dev/null. */
|
||||
info->type = UNIT_FILE_TYPE_MASKED;
|
||||
|
||||
else if (r > 0 &&
|
||||
stat(resolved, &st) >= 0 &&
|
||||
null_or_empty(&st))
|
||||
|
||||
info->type = UNIT_FILE_TYPE_MASKED;
|
||||
|
||||
else {
|
||||
_cleanup_free_ char *target = NULL;
|
||||
const char *bn;
|
||||
UnitType a, b;
|
||||
|
||||
/* This is a symlink, let's read it. We read the link again, because last time
|
||||
* we followed the link until resolution, and here we need to do one step. */
|
||||
|
||||
r = readlink_malloc(path, &target);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
bn = basename(target);
|
||||
|
||||
if (unit_name_is_valid(info->name, UNIT_NAME_PLAIN)) {
|
||||
|
||||
Reference in New Issue
Block a user