* 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)))
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;
}
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;
}
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;
}
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");
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;
"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:
if (at == n)
return false;
- if (at[1] == '.')
+ if (!template_ok && at+1 == e)
return false;
}
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, '.'));
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);
if (!s)
return -ENOMEM;
- if (!unit_name_is_valid(s)) {
+ if (!unit_name_is_valid(s, false)) {
r = -EINVAL;
goto fail;
}
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] = {
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);