summaryrefslogtreecommitdiffstats
path: root/src/basic/unit-name.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/basic/unit-name.c')
-rw-r--r--src/basic/unit-name.c45
1 files changed, 28 insertions, 17 deletions
diff --git a/src/basic/unit-name.c b/src/basic/unit-name.c
index 3b739c758a..8bf28ba749 100644
--- a/src/basic/unit-name.c
+++ b/src/basic/unit-name.c
@@ -389,15 +389,14 @@ int unit_name_unescape(const char *f, char **ret) {
int unit_name_path_escape(const char *f, char **ret) {
_cleanup_free_ char *p = NULL;
char *s;
+ int r;
assert(f);
assert(ret);
- p = strdup(f);
- if (!p)
- return -ENOMEM;
-
- path_simplify(p);
+ r = path_simplify_alloc(f, &p);
+ if (r < 0)
+ return r;
if (empty_or_root(p))
s = strdup("-");
@@ -701,9 +700,15 @@ static bool do_escape_mangle(const char *f, bool allow_globs, char *t) {
*
* If @allow_globs, globs characters are preserved. Otherwise, they are escaped.
*/
-int unit_name_mangle_with_suffix(const char *name, const char *operation, UnitNameMangle flags, const char *suffix, char **ret) {
+int unit_name_mangle_with_suffix(
+ const char *name,
+ const char *operation,
+ UnitNameMangle flags,
+ const char *suffix,
+ char **ret) {
+
_cleanup_free_ char *s = NULL;
- bool mangled, suggest_escape = true;
+ bool mangled, suggest_escape = true, warn = flags & UNIT_NAME_MANGLE_WARN;
int r;
assert(name);
@@ -724,22 +729,28 @@ int unit_name_mangle_with_suffix(const char *name, const char *operation, UnitNa
if (string_is_glob(name) && in_charset(name, VALID_CHARS_GLOB)) {
if (flags & UNIT_NAME_MANGLE_GLOB)
goto good;
- log_full(flags & UNIT_NAME_MANGLE_WARN ? LOG_NOTICE : LOG_DEBUG,
+ log_full(warn ? LOG_NOTICE : LOG_DEBUG,
"Glob pattern passed%s%s, but globs are not supported for this.",
operation ? " " : "", strempty(operation));
suggest_escape = false;
}
- if (is_device_path(name)) {
- r = unit_name_from_path(name, ".device", ret);
- if (r >= 0)
- return 1;
- if (r != -EINVAL)
+ if (path_is_absolute(name)) {
+ _cleanup_free_ char *n = NULL;
+
+ r = path_simplify_alloc(name, &n);
+ if (r < 0)
return r;
- }
- if (path_is_absolute(name)) {
- r = unit_name_from_path(name, ".mount", ret);
+ if (is_device_path(n)) {
+ r = unit_name_from_path(n, ".device", ret);
+ if (r >= 0)
+ return 1;
+ if (r != -EINVAL)
+ return r;
+ }
+
+ r = unit_name_from_path(n, ".mount", ret);
if (r >= 0)
return 1;
if (r != -EINVAL)
@@ -752,7 +763,7 @@ int unit_name_mangle_with_suffix(const char *name, const char *operation, UnitNa
mangled = do_escape_mangle(name, flags & UNIT_NAME_MANGLE_GLOB, s);
if (mangled)
- log_full(flags & UNIT_NAME_MANGLE_WARN ? LOG_NOTICE : LOG_DEBUG,
+ log_full(warn ? LOG_NOTICE : LOG_DEBUG,
"Invalid unit name \"%s\" escaped as \"%s\"%s.",
name, s,
suggest_escape ? " (maybe you should use systemd-escape?)" : "");