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:
@@ -111,8 +111,7 @@ bool bpf_restrict_fs_supported(bool initialize) {
|
||||
return (supported = false);
|
||||
}
|
||||
if (r == 0) {
|
||||
log_info_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
|
||||
"bpf-restrict-fs: BPF LSM hook not enabled in the kernel, BPF LSM not supported");
|
||||
log_info("bpf-restrict-fs: BPF LSM hook not enabled in the kernel, BPF LSM not supported.");
|
||||
return (supported = false);
|
||||
}
|
||||
|
||||
@@ -121,8 +120,7 @@ bool bpf_restrict_fs_supported(bool initialize) {
|
||||
return (supported = false);
|
||||
|
||||
if (!bpf_can_link_lsm_program(obj->progs.restrict_filesystems)) {
|
||||
log_warning_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
|
||||
"bpf-restrict-fs: Failed to link program; assuming BPF LSM is not available");
|
||||
log_warning("bpf-restrict-fs: Failed to link program; assuming BPF LSM is not available.");
|
||||
return (supported = false);
|
||||
}
|
||||
|
||||
@@ -258,11 +256,11 @@ bool bpf_restrict_fs_supported(bool initialize) {
|
||||
}
|
||||
|
||||
int bpf_restrict_fs_setup(Manager *m) {
|
||||
return log_debug_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "bpf-restrict-fs: Failed to set up LSM BPF: %m");
|
||||
return log_debug_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "bpf-restrict-fs: BPF framework is not supported.");
|
||||
}
|
||||
|
||||
int bpf_restrict_fs_update(const Set *filesystems, uint64_t cgroup_id, int outer_map_fd, const bool allow_list) {
|
||||
return log_debug_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "bpf-restrict-fs: Failed to restrict filesystems using LSM BPF: %m");
|
||||
return log_debug_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "bpf-restrict-fs: BPF framework is not supported.");
|
||||
}
|
||||
|
||||
int bpf_restrict_fs_cleanup(Unit *u) {
|
||||
|
||||
+1
-2
@@ -20,8 +20,7 @@ bool cgroup_bpf_supported(void) {
|
||||
}
|
||||
|
||||
if (r == 0) {
|
||||
log_info_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
|
||||
"Not running with unified cgroup hierarchy, disabling cgroup BPF features.");
|
||||
log_info("Not running with unified cgroup hierarchy, disabling cgroup BPF features.");
|
||||
return (supported = false);
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -1129,7 +1129,7 @@ int cgroup_context_add_bpf_foreign_program(CGroupContext *c, uint32_t attach_typ
|
||||
assert(bpffs_path);
|
||||
|
||||
if (!path_is_normalized(bpffs_path) || !path_is_absolute(bpffs_path))
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Path is not normalized: %m");
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Path is not normalized.");
|
||||
|
||||
d = strdup(bpffs_path);
|
||||
if (!d)
|
||||
@@ -1954,7 +1954,7 @@ static int cgroup_apply_devices(Unit *u) {
|
||||
}
|
||||
|
||||
if (prog && !any) {
|
||||
log_unit_warning_errno(u, SYNTHETIC_ERRNO(ENODEV), "No devices matched by device filter.");
|
||||
log_unit_warning(u, "No devices matched by device filter.");
|
||||
|
||||
/* The kernel verifier would reject a program we would build with the normal intro and outro
|
||||
but no allow-listing rules (outro would contain an unreachable instruction for successful
|
||||
@@ -5109,7 +5109,7 @@ static int unit_cgroup_freezer_kernel_state(Unit *u, FreezerState *ret) {
|
||||
else if (streq(val, "1"))
|
||||
s = FREEZER_FROZEN;
|
||||
else {
|
||||
log_unit_debug_errno(u, SYNTHETIC_ERRNO(EINVAL), "Unexpected cgroup frozen state: %s", val);
|
||||
log_unit_debug(u, "Unexpected cgroup frozen state: %s", val);
|
||||
s = _FREEZER_STATE_INVALID;
|
||||
}
|
||||
|
||||
|
||||
@@ -2932,7 +2932,7 @@ static int aux_scope_from_message(Manager *m, sd_bus_message *message, Unit **re
|
||||
|
||||
unit = manager_get_unit_by_pidref(m, &p);
|
||||
if (!unit) {
|
||||
log_unit_warning_errno(from, SYNTHETIC_ERRNO(ENOENT), "Failed to get unit from PIDFD, ignoring: %m");
|
||||
log_unit_warning(from, "Failed to get unit from PIDFD, ignoring.");
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -4204,7 +4204,7 @@ int exec_invoke(
|
||||
|
||||
*exit_status = EXIT_CONFIRM;
|
||||
return log_exec_error_errno(context, params, SYNTHETIC_ERRNO(ECANCELED),
|
||||
"Execution cancelled by the user");
|
||||
"Execution cancelled by the user.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4246,12 +4246,12 @@ int exec_invoke(
|
||||
|
||||
if (!uid_is_valid(uid)) {
|
||||
*exit_status = EXIT_USER;
|
||||
return log_exec_error_errno(context, params, SYNTHETIC_ERRNO(ESRCH), "UID validation failed for \""UID_FMT"\"", uid);
|
||||
return log_exec_error_errno(context, params, SYNTHETIC_ERRNO(ESRCH), "UID validation failed for \""UID_FMT"\".", uid);
|
||||
}
|
||||
|
||||
if (!gid_is_valid(gid)) {
|
||||
*exit_status = EXIT_USER;
|
||||
return log_exec_error_errno(context, params, SYNTHETIC_ERRNO(ESRCH), "GID validation failed for \""GID_FMT"\"", gid);
|
||||
return log_exec_error_errno(context, params, SYNTHETIC_ERRNO(ESRCH), "GID validation failed for \""GID_FMT"\".", gid);
|
||||
}
|
||||
|
||||
if (runtime->dynamic_creds->user)
|
||||
|
||||
@@ -1360,7 +1360,7 @@ static int mount_image(
|
||||
if (r < 0)
|
||||
return log_debug_errno(r, "Failed to acquire 'os-release' data of OS tree '%s': %m", empty_to_root(root_directory));
|
||||
if (isempty(host_os_release_id))
|
||||
return log_debug_errno(SYNTHETIC_ERRNO(EINVAL), "'ID' field not found or empty in 'os-release' data of OS tree '%s': %m", empty_to_root(root_directory));
|
||||
return log_debug_errno(SYNTHETIC_ERRNO(EINVAL), "'ID' field not found or empty in 'os-release' data of OS tree '%s'.", empty_to_root(root_directory));
|
||||
}
|
||||
|
||||
r = verity_dissect_and_mount(
|
||||
@@ -1532,7 +1532,7 @@ static int apply_one_mount(
|
||||
r = mode_to_inaccessible_node(runtime_dir, target.st_mode, &inaccessible);
|
||||
if (r < 0)
|
||||
return log_debug_errno(SYNTHETIC_ERRNO(ELOOP),
|
||||
"File type not supported for inaccessible mounts. Note that symlinks are not allowed");
|
||||
"File type not supported for inaccessible mounts. Note that symlinks are not allowed.");
|
||||
what = inaccessible;
|
||||
break;
|
||||
}
|
||||
@@ -1583,7 +1583,7 @@ static int apply_one_mount(
|
||||
if (r < 0)
|
||||
return log_debug_errno(r, "Failed to acquire 'os-release' data of OS tree '%s': %m", empty_to_root(root_directory));
|
||||
if (isempty(host_os_release_id))
|
||||
return log_debug_errno(SYNTHETIC_ERRNO(EINVAL), "'ID' field not found or empty in 'os-release' data of OS tree '%s': %m", empty_to_root(root_directory));
|
||||
return log_debug_errno(SYNTHETIC_ERRNO(EINVAL), "'ID' field not found or empty in 'os-release' data of OS tree '%s'.", empty_to_root(root_directory));
|
||||
|
||||
r = load_extension_release_pairs(mount_entry_source(m), class, extension_name, /* relax_extension_release_check= */ false, &extension_release);
|
||||
if (r == -ENOENT && m->ignore)
|
||||
@@ -1602,7 +1602,7 @@ static int apply_one_mount(
|
||||
if (r < 0)
|
||||
return log_debug_errno(r, "Failed to compare directory %s extension-release metadata with the root's os-release: %m", extension_name);
|
||||
if (r == 0)
|
||||
return log_debug_errno(SYNTHETIC_ERRNO(ESTALE), "Directory %s extension-release metadata does not match the root's", extension_name);
|
||||
return log_debug_errno(SYNTHETIC_ERRNO(ESTALE), "Directory %s extension-release metadata does not match the root's.", extension_name);
|
||||
|
||||
_fallthrough_;
|
||||
}
|
||||
|
||||
+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