naccyde / rpms / systemd

Forked from rpms/systemd a year ago
Clone
84b277
From 14b393f9d9b7caffcd48557c6bd4eb63de4942ad Mon Sep 17 00:00:00 2001
84b277
From: Lennart Poettering <lennart@poettering.net>
84b277
Date: Mon, 16 Jun 2014 17:01:26 +0200
84b277
Subject: [PATCH] unit-name: fix detection of unit templates/instances
84b277
84b277
We need to check for the last dot, not the first one in a unit name, for
84b277
the suffix. Correct that.
84b277
84b277
(cherry-picked from 6ef9eeed61a291cc42b7d911f5cf5a4deca742a3)
84b277
84b277
Resolves: #1147524
84b277
---
84b277
 src/shared/unit-name.c | 16 ++++++++++++----
84b277
 1 file changed, 12 insertions(+), 4 deletions(-)
84b277
84b277
diff --git a/src/shared/unit-name.c b/src/shared/unit-name.c
84b277
index bc8094d..577f7e7 100644
84b277
--- a/src/shared/unit-name.c
84b277
+++ b/src/shared/unit-name.c
84b277
@@ -334,7 +334,7 @@ char *unit_name_path_unescape(const char *f) {
84b277
 }
84b277
 
84b277
 bool unit_name_is_template(const char *n) {
84b277
-        const char *p;
84b277
+        const char *p, *e;
84b277
 
84b277
         assert(n);
84b277
 
84b277
@@ -342,11 +342,15 @@ bool unit_name_is_template(const char *n) {
84b277
         if (!p)
84b277
                 return false;
84b277
 
84b277
-        return p[1] == '.';
84b277
+        e = strrchr(p+1, '.');
84b277
+        if (!e)
84b277
+                return false;
84b277
+
84b277
+        return e == p + 1;
84b277
 }
84b277
 
84b277
 bool unit_name_is_instance(const char *n) {
84b277
-        const char *p;
84b277
+        const char *p, *e;
84b277
 
84b277
         assert(n);
84b277
 
84b277
@@ -354,7 +358,11 @@ bool unit_name_is_instance(const char *n) {
84b277
         if (!p)
84b277
                 return false;
84b277
 
84b277
-        return p[1] != '.';
84b277
+        e = strrchr(p+1, '.');
84b277
+        if (!e)
84b277
+                return false;
84b277
+
84b277
+        return e > p + 1;
84b277
 }
84b277
 
84b277
 char *unit_name_replace_instance(const char *f, const char *i) {