chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
localectl: use automatic cleanup
[elogind.git]
/
src
/
shared
/
unit-name.c
diff --git
a/src/shared/unit-name.c
b/src/shared/unit-name.c
index 71937187922835fb3fcf3d6c3c8037356f0bfa9d..88ca0b8f2ccbf90025ab40f3877cebc7c8740c93 100644
(file)
--- a/
src/shared/unit-name.c
+++ b/
src/shared/unit-name.c
@@
-33,7
+33,7
@@
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" \
":-_.\\"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" \
":-_.\\"
-
static
const char* const unit_type_table[_UNIT_TYPE_MAX] = {
+const char* const unit_type_table[_UNIT_TYPE_MAX] = {
[UNIT_SERVICE] = "service",
[UNIT_SOCKET] = "socket",
[UNIT_TARGET] = "target",
[UNIT_SERVICE] = "service",
[UNIT_SOCKET] = "socket",
[UNIT_TARGET] = "target",
@@
-48,7
+48,7
@@
static const char* const unit_type_table[_UNIT_TYPE_MAX] = {
DEFINE_STRING_TABLE_LOOKUP(unit_type, UnitType);
DEFINE_STRING_TABLE_LOOKUP(unit_type, UnitType);
-
static
const char* const unit_load_state_table[_UNIT_LOAD_STATE_MAX] = {
+const char* const unit_load_state_table[_UNIT_LOAD_STATE_MAX] = {
[UNIT_STUB] = "stub",
[UNIT_LOADED] = "loaded",
[UNIT_ERROR] = "error",
[UNIT_STUB] = "stub",
[UNIT_LOADED] = "loaded",
[UNIT_ERROR] = "error",
@@
-357,36
+357,29
@@
bool unit_name_is_instance(const char *n) {
char *unit_name_replace_instance(const char *f, const char *i) {
const char *p, *e;
char *r, *k;
char *unit_name_replace_instance(const char *f, const char *i) {
const char *p, *e;
char *r, *k;
- size_t a;
+ size_t a
, b
;
assert(f);
p = strchr(f, '@');
assert(f);
p = strchr(f, '@');
- assert_se(e = strrchr(f, '.'));
-
- a = p - f;
-
- if (p) {
- size_t b;
-
- b = strlen(i);
-
- r = new(char, a + 1 + b + strlen(e) + 1);
- if (!r)
- return NULL;
+ if (!p)
+ return strdup(f);
-
k = mempcpy(r, f, a + 1
);
- k = mempcpy(k, i, b);
- } else {
+
e = strrchr(f, '.'
);
+ if (!e)
+ assert_se(e = strchr(f, 0));
- r = new(char, a + strlen(e) + 1);
- if (!r)
- return NULL;
+ a = p - f;
+ b = strlen(i);
- k = mempcpy(r, f, a);
- }
+ r = new(char, a + 1 + b + strlen(e) + 1);
+ if (!r)
+ return NULL;
+ k = mempcpy(r, f, a + 1);
+ k = mempcpy(k, i, b);
strcpy(k, e);
strcpy(k, e);
+
return r;
}
return r;
}
@@
-477,15
+470,13
@@
char *unit_dbus_path_from_name(const char *name) {
char *unit_name_mangle(const char *name) {
char *r, *t;
const char *f;
char *unit_name_mangle(const char *name) {
char *r, *t;
const char *f;
- bool dot = false;
assert(name);
/* Try to turn a string that might not be a unit name into a
* sensible unit name. */
assert(name);
/* Try to turn a string that might not be a unit name into a
* sensible unit name. */
- if (path_startswith(name, "/dev/") ||
- path_startswith(name, "/sys/"))
+ if (is_device_path(name))
return unit_name_from_path(name, ".device");
if (path_is_absolute(name))
return unit_name_from_path(name, ".device");
if (path_is_absolute(name))
@@
-499,10
+490,6
@@
char *unit_name_mangle(const char *name) {
return NULL;
for (f = name, t = r; *f; f++) {
return NULL;
for (f = name, t = r; *f; f++) {
-
- if (*f == '.')
- dot = true;
-
if (*f == '/')
*(t++) = '-';
else if (!strchr("@" VALID_CHARS, *f))
if (*f == '/')
*(t++) = '-';
else if (!strchr("@" VALID_CHARS, *f))
@@
-511,7
+498,7
@@
char *unit_name_mangle(const char *name) {
*(t++) = *f;
}
*(t++) = *f;
}
- if (
!dot
)
+ if (
unit_name_to_type(name) < 0
)
strcpy(t, ".service");
else
*t = 0;
strcpy(t, ".service");
else
*t = 0;