[systemd-commits] src/load-fragment.c src/manager.c src/snapshot.c src/systemctl.c src/unit.c src/unit.h src/unit-name.c src/unit-name.h

Lennart Poettering lennart at kemper.freedesktop.org
Thu Oct 7 18:09:31 PDT 2010


 src/load-fragment.c |    2 +-
 src/manager.c       |    2 +-
 src/snapshot.c      |    2 +-
 src/systemctl.c     |   10 ++--------
 src/unit-name.c     |    6 +++---
 src/unit-name.h     |    2 +-
 src/unit.c          |    6 +++---
 src/unit.h          |    2 +-
 8 files changed, 13 insertions(+), 19 deletions(-)

New commits:
commit b9c0d4415b8cd6135321185b6febfdd1366a477c
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Oct 8 03:09:25 2010 +0200

    systemctl: fix 'systemctl enable getty at .service'

diff --git a/src/load-fragment.c b/src/load-fragment.c
index 54b1af0..740c11c 100644
--- a/src/load-fragment.c
+++ b/src/load-fragment.c
@@ -1431,7 +1431,7 @@ static int open_follow(char **filename, FILE **_f, Set *names, char **_final) {
                  * unit name. */
                 name = file_name_from_path(*filename);
 
-                if (unit_name_is_valid(name)) {
+                if (unit_name_is_valid(name, false)) {
                         if (!(id = set_get(names, name))) {
 
                                 if (!(id = strdup(name)))
diff --git a/src/manager.c b/src/manager.c
index 26a631e..7e9075a 100644
--- a/src/manager.c
+++ b/src/manager.c
@@ -1641,7 +1641,7 @@ int manager_load_unit_prepare(Manager *m, const char *name, const char *path, DB
         if (!name)
                 name = file_name_from_path(path);
 
-        if (!unit_name_is_valid(name)) {
+        if (!unit_name_is_valid(name, false)) {
                 dbus_set_error(e, BUS_ERROR_INVALID_NAME, "Unit name %s is not valid.", name);
                 return -EINVAL;
         }
diff --git a/src/snapshot.c b/src/snapshot.c
index f58d46e..a23f2db 100644
--- a/src/snapshot.c
+++ b/src/snapshot.c
@@ -186,7 +186,7 @@ int snapshot_create(Manager *m, const char *name, bool cleanup, DBusError *e, Sn
         assert(_s);
 
         if (name) {
-                if (!unit_name_is_valid(name)) {
+                if (!unit_name_is_valid(name, false)) {
                         dbus_set_error(e, BUS_ERROR_INVALID_NAME, "Unit name %s is not valid.", name);
                         return -EINVAL;
                 }
diff --git a/src/systemctl.c b/src/systemctl.c
index 4beec0f..c8384ff 100644
--- a/src/systemctl.c
+++ b/src/systemctl.c
@@ -3247,7 +3247,7 @@ static int install_info_add(const char *name) {
 
         assert(will_install);
 
-        if (!unit_name_is_valid_no_type(name)) {
+        if (!unit_name_is_valid_no_type(name, true)) {
                 log_warning("Unit name %s is not a valid unit name.", name);
                 return -EINVAL;
         }
@@ -3633,12 +3633,6 @@ static int install_info_symlink_alias(const char *verb, InstallInfo *i, const ch
 
         STRV_FOREACH(s, i->aliases) {
 
-                if (!unit_name_is_valid_no_type(*s)) {
-                        log_error("Invalid name %s.", *s);
-                        r = -EINVAL;
-                        goto finish;
-                }
-
                 free(alias_path);
                 if (!(alias_path = path_make_absolute(*s, config_path))) {
                         log_error("Out of memory");
@@ -3670,7 +3664,7 @@ static int install_info_symlink_wants(const char *verb, InstallInfo *i, const ch
         assert(config_path);
 
         STRV_FOREACH(s, i->wanted_by) {
-                if (!unit_name_is_valid_no_type(*s)) {
+                if (!unit_name_is_valid_no_type(*s, true)) {
                         log_error("Invalid name %s.", *s);
                         r = -EINVAL;
                         goto finish;
diff --git a/src/unit-name.c b/src/unit-name.c
index 0e86b55..cd6e3ce 100644
--- a/src/unit-name.c
+++ b/src/unit-name.c
@@ -32,7 +32,7 @@
         "ABCDEFGHIJKLMNOPQRSTUVWXYZ"            \
         ":-_.\\"
 
-bool unit_name_is_valid_no_type(const char *n) {
+bool unit_name_is_valid_no_type(const char *n, bool template_ok) {
         const char *e, *i, *at;
 
         /* Valid formats:
@@ -63,7 +63,7 @@ bool unit_name_is_valid_no_type(const char *n) {
                 if (at == n)
                         return false;
 
-                if (at[1] == '.')
+                if (!template_ok && at+1 == e)
                         return false;
         }
 
@@ -150,7 +150,7 @@ char *unit_name_change_suffix(const char *n, const char *suffix) {
         size_t a, b;
 
         assert(n);
-        assert(unit_name_is_valid_no_type(n));
+        assert(unit_name_is_valid_no_type(n, true));
         assert(suffix);
 
         assert_se(e = strrchr(n, '.'));
diff --git a/src/unit-name.h b/src/unit-name.h
index a752f3a..db1a79e 100644
--- a/src/unit-name.h
+++ b/src/unit-name.h
@@ -30,7 +30,7 @@ int unit_name_to_instance(const char *n, char **instance);
 char* unit_name_to_prefix(const char *n);
 char* unit_name_to_prefix_and_instance(const char *n);
 
-bool unit_name_is_valid_no_type(const char *n);
+bool unit_name_is_valid_no_type(const char *n, bool template_ok);
 bool unit_prefix_is_valid(const char *p);
 bool unit_instance_is_valid(const char *i);
 
diff --git a/src/unit.c b/src/unit.c
index d2652ba..d45fe91 100644
--- a/src/unit.c
+++ b/src/unit.c
@@ -103,7 +103,7 @@ int unit_add_name(Unit *u, const char *text) {
         if (!s)
                 return -ENOMEM;
 
-        if (!unit_name_is_valid(s)) {
+        if (!unit_name_is_valid(s, false)) {
                 r = -EINVAL;
                 goto fail;
         }
@@ -2222,14 +2222,14 @@ UnitType unit_name_to_type(const char *n) {
         return _UNIT_TYPE_INVALID;
 }
 
-bool unit_name_is_valid(const char *n) {
+bool unit_name_is_valid(const char *n, bool template_ok) {
         UnitType t;
 
         t = unit_name_to_type(n);
         if (t < 0 || t >= _UNIT_TYPE_MAX)
                 return false;
 
-        return unit_name_is_valid_no_type(n);
+        return unit_name_is_valid_no_type(n, template_ok);
 }
 
 static const char* const unit_load_state_table[_UNIT_LOAD_STATE_MAX] = {
diff --git a/src/unit.h b/src/unit.h
index a020bd8..aa818d4 100644
--- a/src/unit.h
+++ b/src/unit.h
@@ -505,7 +505,7 @@ bool unit_pending_active(Unit *u);
 int unit_add_default_target_dependency(Unit *u, Unit *target);
 
 UnitType unit_name_to_type(const char *n);
-bool unit_name_is_valid(const char *n);
+bool unit_name_is_valid(const char *n, bool template_ok);
 
 const char *unit_load_state_to_string(UnitLoadState i);
 UnitLoadState unit_load_state_from_string(const char *s);


More information about the systemd-commits mailing list