X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fshared%2Funit-name.c;h=86d6ce3df1583bb3fd67de6a6ccb3d9f0d4e73b3;hp=6c6d7f4f83cd8a7512d09977b24eab90ce00dba1;hb=0b59cf27e82f4f366ea5af1be288557d62bab385;hpb=0c124f8b2c93d2c7d6eefca3bdc59b28250fc077 diff --git a/src/shared/unit-name.c b/src/shared/unit-name.c index 6c6d7f4f8..86d6ce3df 100644 --- a/src/shared/unit-name.c +++ b/src/shared/unit-name.c @@ -21,7 +21,6 @@ #include #include -#include #include "path-util.h" #include "bus-label.h" @@ -100,7 +99,7 @@ bool unit_name_is_valid(const char *n, enum template_valid template_ok) { if (at == n) return false; - if (!template_ok == TEMPLATE_VALID && at+1 == e) + if (template_ok != TEMPLATE_VALID && at+1 == e) return false; } @@ -502,13 +501,18 @@ int unit_name_from_dbus_path(const char *path, char **name) { } /** - * Try to turn a string that might not be a unit name into a - * sensible unit name. + * Convert a string to a unit name. /dev/blah is converted to dev-blah.device, + * /blah/blah is converted to blah-blah.mount, anything else is left alone, + * except that @suffix is appended if a valid unit suffix is not present. + * + * If @allow_globs, globs characters are preserved. Otherwise they are escaped. */ -char *unit_name_mangle(const char *name, enum unit_name_mangle allow_globs) { +char *unit_name_mangle_with_suffix(const char *name, enum unit_name_mangle allow_globs, const char *suffix) { char *r, *t; assert(name); + assert(suffix); + assert(suffix[0] == '.'); if (is_device_path(name)) return unit_name_from_path(name, ".device"); @@ -516,38 +520,13 @@ char *unit_name_mangle(const char *name, enum unit_name_mangle allow_globs) { if (path_is_absolute(name)) return unit_name_from_path(name, ".mount"); - r = new(char, strlen(name) * 4 + strlen(".service") + 1); - if (!r) - return NULL; - - t = do_escape_mangle(name, allow_globs, r); - - if (unit_name_to_type(name) < 0) - strcpy(t, ".service"); - else - *t = 0; - - return r; -} - -/** - * Similar to unit_name_mangle(), but is called when we know - * that this is about a specific unit type. - */ -char *unit_name_mangle_with_suffix(const char *name, enum unit_name_mangle allow_globs, const char *suffix) { - char *r, *t; - - assert(name); - assert(suffix); - assert(suffix[0] == '.'); - r = new(char, strlen(name) * 4 + strlen(suffix) + 1); if (!r) return NULL; t = do_escape_mangle(name, allow_globs, r); - if (!endswith(name, suffix)) + if (unit_name_to_type(name) < 0) strcpy(t, suffix); else *t = 0;