Blob Blame History Raw
From 3e59dbfced8ba0e6258ee5ed6c6a3d895b0fd2b5 Mon Sep 17 00:00:00 2001
From: Lennart Poettering <lennart@poettering.net>
Date: Mon, 16 Jun 2014 17:01:26 +0200
Subject: [PATCH] unit-name: fix detection of unit templates/instances

We need to check for the last dot, not the first one in a unit name, for
the suffix. Correct that.

(cherry picked from commit 6ef9eeed61a291cc42b7d911f5cf5a4deca742a3)
---
 src/shared/unit-name.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/src/shared/unit-name.c b/src/shared/unit-name.c
index 6c167b43..d0e71f24 100644
--- a/src/shared/unit-name.c
+++ b/src/shared/unit-name.c
@@ -332,7 +332,7 @@ char *unit_name_path_unescape(const char *f) {
 }
 
 bool unit_name_is_template(const char *n) {
-        const char *p;
+        const char *p, *e;
 
         assert(n);
 
@@ -340,11 +340,15 @@ bool unit_name_is_template(const char *n) {
         if (!p)
                 return false;
 
-        return p[1] == '.';
+        e = strrchr(p+1, '.');
+        if (!e)
+                return false;
+
+        return e == p + 1;
 }
 
 bool unit_name_is_instance(const char *n) {
-        const char *p;
+        const char *p, *e;
 
         assert(n);
 
@@ -352,7 +356,11 @@ bool unit_name_is_instance(const char *n) {
         if (!p)
                 return false;
 
-        return p[1] != '.';
+        e = strrchr(p+1, '.');
+        if (!e)
+                return false;
+
+        return e > p + 1;
 }
 
 char *unit_name_replace_instance(const char *f, const char *i) {