tree-wise: several cleanups for logging
- drop unnecessary SYNTHETIC_ERRNO() when the logger does not propagate error code, - drop unnecessary '%m' in error message when the error code is specified with SYNTHETIC_ERRNO(), - add missing full stop at the end of log message, - use RET_GATHER(), - add missing ", ignoring.", - upeercase the first letter, etc., etc...
This commit is contained in:
+12
-12
@@ -243,12 +243,12 @@ int unit_add_name(Unit *u, const char *text) {
|
||||
if (unit_name_is_valid(text, UNIT_NAME_TEMPLATE)) {
|
||||
if (!u->instance)
|
||||
return log_unit_debug_errno(u, SYNTHETIC_ERRNO(EINVAL),
|
||||
"instance is not set when adding name '%s': %m", text);
|
||||
"Instance is not set when adding name '%s'.", text);
|
||||
|
||||
r = unit_name_replace_instance(text, u->instance, &name);
|
||||
if (r < 0)
|
||||
return log_unit_debug_errno(u, r,
|
||||
"failed to build instance name from '%s': %m", text);
|
||||
"Failed to build instance name from '%s': %m", text);
|
||||
} else {
|
||||
name = strdup(text);
|
||||
if (!name)
|
||||
@@ -260,47 +260,47 @@ int unit_add_name(Unit *u, const char *text) {
|
||||
|
||||
if (hashmap_contains(u->manager->units, name))
|
||||
return log_unit_debug_errno(u, SYNTHETIC_ERRNO(EEXIST),
|
||||
"unit already exist when adding name '%s': %m", name);
|
||||
"Unit already exist when adding name '%s'.", name);
|
||||
|
||||
if (!unit_name_is_valid(name, UNIT_NAME_PLAIN|UNIT_NAME_INSTANCE))
|
||||
return log_unit_debug_errno(u, SYNTHETIC_ERRNO(EINVAL),
|
||||
"name '%s' is invalid: %m", name);
|
||||
"Name '%s' is invalid.", name);
|
||||
|
||||
t = unit_name_to_type(name);
|
||||
if (t < 0)
|
||||
return log_unit_debug_errno(u, SYNTHETIC_ERRNO(EINVAL),
|
||||
"failed to derive unit type from name '%s': %m", name);
|
||||
"failed to derive unit type from name '%s'.", name);
|
||||
|
||||
if (u->type != _UNIT_TYPE_INVALID && t != u->type)
|
||||
return log_unit_debug_errno(u, SYNTHETIC_ERRNO(EINVAL),
|
||||
"unit type is illegal: u->type(%d) and t(%d) for name '%s': %m",
|
||||
"Unit type is illegal: u->type(%d) and t(%d) for name '%s'.",
|
||||
u->type, t, name);
|
||||
|
||||
r = unit_name_to_instance(name, &instance);
|
||||
if (r < 0)
|
||||
return log_unit_debug_errno(u, r, "failed to extract instance from name '%s': %m", name);
|
||||
return log_unit_debug_errno(u, r, "Failed to extract instance from name '%s': %m", name);
|
||||
|
||||
if (instance && !unit_type_may_template(t))
|
||||
return log_unit_debug_errno(u, SYNTHETIC_ERRNO(EINVAL), "templates are not allowed for name '%s': %m", name);
|
||||
return log_unit_debug_errno(u, SYNTHETIC_ERRNO(EINVAL), "Templates are not allowed for name '%s'.", name);
|
||||
|
||||
/* Ensure that this unit either has no instance, or that the instance matches. */
|
||||
if (u->type != _UNIT_TYPE_INVALID && !streq_ptr(u->instance, instance))
|
||||
return log_unit_debug_errno(u, SYNTHETIC_ERRNO(EINVAL),
|
||||
"cannot add name %s, the instances don't match (\"%s\" != \"%s\").",
|
||||
"Cannot add name %s, the instances don't match (\"%s\" != \"%s\").",
|
||||
name, instance, u->instance);
|
||||
|
||||
if (u->id && !unit_type_may_alias(t))
|
||||
return log_unit_debug_errno(u, SYNTHETIC_ERRNO(EEXIST),
|
||||
"cannot add name %s, aliases are not allowed for %s units.",
|
||||
"Cannot add name %s, aliases are not allowed for %s units.",
|
||||
name, unit_type_to_string(t));
|
||||
|
||||
if (hashmap_size(u->manager->units) >= MANAGER_MAX_NAMES)
|
||||
return log_unit_warning_errno(u, SYNTHETIC_ERRNO(E2BIG), "cannot add name, manager has too many units: %m");
|
||||
return log_unit_warning_errno(u, SYNTHETIC_ERRNO(E2BIG), "Cannot add name, manager has too many units.");
|
||||
|
||||
/* Add name to the global hashmap first, because that's easier to undo */
|
||||
r = hashmap_put(u->manager->units, name, u);
|
||||
if (r < 0)
|
||||
return log_unit_debug_errno(u, r, "add unit to hashmap failed for name '%s': %m", text);
|
||||
return log_unit_debug_errno(u, r, "Add unit to hashmap failed for name '%s': %m", text);
|
||||
|
||||
if (u->id) {
|
||||
r = unit_add_alias(u, name); /* unit_add_alias() takes ownership of the name on success */
|
||||
|
||||
Reference in New Issue
Block a user