public inbox for development@lists.ipfire.org
 help / color / mirror / Atom feed
From: Michael Tremer <michael.tremer@ipfire.org>
To: development@lists.ipfire.org
Subject: Make systemctl is-enabled work for templated units
Date: Sun, 19 May 2013 15:45:48 +0200	[thread overview]
Message-ID: <1368971148.1836.45.camel@rice-oxley.tremer.info> (raw)

[-- Attachment #1: Type: text/plain, Size: 682 bytes --]

Hello guys,

in this mail, you will find a patch which resolves the problem, that
'systemctl is-enabled' does not work for templated units.

See also https://bugs.freedesktop.org/show_bug.cgi?id=55318 for
reference.

Without this patch, systemctl is-enabled something(a)abc.service
returned "No such file or directory", because it was checked
if /usr/lib/systemd/system/something(a)abc.service, etc. existed,
which is obviously not the case.

If systemctl is-enabled is called for templated units, this
check should be omitted and it should be searched for symlinks
in the /etc paths right away.

I would like to request that this is merged to the systemd git tree.

Best,
-Michael

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Make-systemctl-is-enabled-work-for-templated-units.patch --]
[-- Type: text/x-patch, Size: 2981 bytes --]

>From 633b5ecfdec9d588ad6f97a20c50089200632e24 Mon Sep 17 00:00:00 2001
From: Michael Tremer <michael.tremer@ipfire.org>
Date: Sun, 19 May 2013 15:28:49 +0200
Subject: [PATCH] Make systemctl is-enabled work for templated units.

Without this patch, systemctl is-enabled something@abc.service
returned "No such file or directory", because it was checked
if /usr/lib/systemd/system/something@abc.service, etc. existed,
which is obviously not the case.

If systemctl is-enabled is called for templated units, this
check should be omitted and it should be searched for symlinks
in the /etc paths right away.

This patch fixes the broken behaviour and resolves
  https://bugs.freedesktop.org/show_bug.cgi?id=55318.
---
 src/shared/install.c | 38 ++++++++++++++++++++++----------------
 1 file changed, 22 insertions(+), 16 deletions(-)

diff --git a/src/shared/install.c b/src/shared/install.c
index edf4d2a..a9e2d7b 100644
--- a/src/shared/install.c
+++ b/src/shared/install.c
@@ -1609,25 +1609,31 @@ UnitFileState unit_file_get_state(
                 if (!path)
                         return -ENOMEM;
 
-                if (lstat(path, &st) < 0) {
-                        r = -errno;
-                        if (errno == ENOENT)
-                                continue;
+                /*
+                 * Search for a unit file in our default paths, to
+                 * be sure, that there are no broken symlinks.
+                 */
+                if (!unit_name_is_instance(name)) {
+                        if (lstat(path, &st) < 0) {
+                                r = -errno;
+                                if (errno == ENOENT)
+                                        continue;
 
-                        return -errno;
-                }
+                                return -errno;
+                        }
 
-                if (!S_ISREG(st.st_mode) && !S_ISLNK(st.st_mode))
-                        return -ENOENT;
+                        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);
                 if (r < 0)
-- 
1.8.1


             reply	other threads:[~2013-05-19 13:45 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-19 13:45 Michael Tremer [this message]
2013-05-21 13:30 ` [systemd-devel] " Zbigniew Jędrzejewski-Szmek
2013-05-21 13:47   ` Michael Tremer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1368971148.1836.45.camel@rice-oxley.tremer.info \
    --to=michael.tremer@ipfire.org \
    --cc=development@lists.ipfire.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox