chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
core: rework unit name validation and manipulation logic
[elogind.git]
/
src
/
shared
/
cgroup-util.c
diff --git
a/src/shared/cgroup-util.c
b/src/shared/cgroup-util.c
index ce8ebb2ca425bc8b3506c085bf0154b3044ca372..78270b3fa93116bc1697166540d9b070196350f5 100644
(file)
--- a/
src/shared/cgroup-util.c
+++ b/
src/shared/cgroup-util.c
@@
-1153,7
+1153,7
@@
int cg_path_decode_unit(const char *cgroup, char **unit){
c = strndupa(cgroup, n);
c = cg_unescape(c);
c = strndupa(cgroup, n);
c = cg_unescape(c);
- if (!unit_name_is_valid(c,
TEMPLATE_INVALID
))
+ if (!unit_name_is_valid(c,
UNIT_NAME_PLAIN|UNIT_NAME_INSTANCE
))
return -ENXIO;
s = strdup(c);
return -ENXIO;
s = strdup(c);
@@
-1180,7
+1180,7
@@
static bool valid_slice_name(const char *p, size_t n) {
c = cg_unescape(buf);
c = cg_unescape(buf);
- return unit_name_is_valid(c,
TEMPLATE_INVALID
);
+ return unit_name_is_valid(c,
UNIT_NAME_PLAIN
);
}
return false;
}
return false;
@@
-1637,6
+1637,7
@@
bool cg_controller_is_valid(const char *p, bool allow_named) {
int cg_slice_to_path(const char *unit, char **ret) {
_cleanup_free_ char *p = NULL, *s = NULL, *e = NULL;
const char *dash;
int cg_slice_to_path(const char *unit, char **ret) {
_cleanup_free_ char *p = NULL, *s = NULL, *e = NULL;
const char *dash;
+ int r;
assert(unit);
assert(ret);
assert(unit);
assert(ret);
@@
-1651,15
+1652,15
@@
int cg_slice_to_path(const char *unit, char **ret) {
return 0;
}
return 0;
}
- if (!unit_name_is_valid(unit,
TEMPLATE_INVALID
))
+ if (!unit_name_is_valid(unit,
UNIT_NAME_PLAIN
))
return -EINVAL;
if (!endswith(unit, ".slice"))
return -EINVAL;
return -EINVAL;
if (!endswith(unit, ".slice"))
return -EINVAL;
-
p = unit_name_to_prefix(unit
);
- if (
!p
)
- return
-ENOMEM
;
+
r = unit_name_to_prefix(unit, &p
);
+ if (
r < 0
)
+ return
r
;
dash = strchr(p, '-');
while (dash) {
dash = strchr(p, '-');
while (dash) {
@@
-1670,7
+1671,7
@@
int cg_slice_to_path(const char *unit, char **ret) {
return -EINVAL;
strcpy(stpncpy(n, p, dash - p), ".slice");
return -EINVAL;
strcpy(stpncpy(n, p, dash - p), ".slice");
- if (!unit_name_is_valid(n,
TEMPLATE_INVALID
))
+ if (!unit_name_is_valid(n,
UNIT_NAME_PLAIN
))
return -EINVAL;
escaped = cg_escape(n);
return -EINVAL;
escaped = cg_escape(n);