systemctl: make systemctl is-enabled work for templated units

Patch resolves the problem that 'systemctl is-enabled' does
not work for templated units.

Without this patch, systemctl is-enabled something@abc.service
returned "No such file or directory", because it first checked
if /usr/lib/systemd/system/something@abc.service, etc. exists.
If systemctl is-enabled is called for templated units, this
check should be omitted and it should search for symlinks in
the .wants dirs right away.

This patch fixes the broken behaviour and resolves
  https://bugs.freedesktop.org/show_bug.cgi?id=55318.

[zj: fixed the patch to still check for broken symlinks and
     masked instances. Also removed untrue assumptions from
     the patch description.]
This commit is contained in:
Michael Tremer
2013-05-21 09:23:51 -04:00
committed by Zbigniew Jędrzejewski-Szmek
parent 9e9c3abcfa
commit 67820a0cbd
+19 -14
View File
@@ -1609,24 +1609,29 @@ UnitFileState unit_file_get_state(
if (!path)
return -ENOMEM;
/*
* Search for a unit file in our default paths, to
* be sure, that there are no broken symlinks.
*/
if (lstat(path, &st) < 0) {
r = -errno;
if (errno == ENOENT)
if (errno != ENOENT)
return r;
if (!unit_name_is_instance(name))
continue;
} else {
if (!S_ISREG(st.st_mode) && !S_ISLNK(st.st_mode))
return -ENOENT;
return -errno;
}
if (!S_ISREG(st.st_mode) && !S_ISLNK(st.st_mode))
return -ENOENT;
r = null_or_empty_path(path);
if (r < 0 && r != -ENOENT)
return r;
else if (r > 0) {
state = path_startswith(*i, "/run") ?
UNIT_FILE_MASKED_RUNTIME : UNIT_FILE_MASKED;
return state;
r = null_or_empty_path(path);
if (r < 0 && r != -ENOENT)
return r;
else if (r > 0) {
state = path_startswith(*i, "/run") ?
UNIT_FILE_MASKED_RUNTIME : UNIT_FILE_MASKED;
return state;
}
}
r = find_symlinks_in_scope(scope, root_dir, name, &state);