mirror of
https://github.com/systemd/systemd.git
synced 2024-12-01 06:13:38 +08:00
execute: rework logging in setup_keyring() to include unit info
Let's use log_unit_error() instead of log_error() everywhere (and friends).
This commit is contained in:
parent
0cde65e263
commit
8002fb9747
@ -2192,13 +2192,13 @@ static int setup_keyring(
|
||||
keyring = keyctl(KEYCTL_JOIN_SESSION_KEYRING, 0, 0, 0, 0);
|
||||
if (keyring == -1) {
|
||||
if (errno == ENOSYS)
|
||||
log_debug_errno(errno, "Kernel keyring not supported, ignoring.");
|
||||
log_unit_debug_errno(u, errno, "Kernel keyring not supported, ignoring.");
|
||||
else if (IN_SET(errno, EACCES, EPERM))
|
||||
log_debug_errno(errno, "Kernel keyring access prohibited, ignoring.");
|
||||
log_unit_debug_errno(u, errno, "Kernel keyring access prohibited, ignoring.");
|
||||
else if (errno == EDQUOT)
|
||||
log_debug_errno(errno, "Out of kernel keyrings to allocate, ignoring.");
|
||||
log_unit_debug_errno(u, errno, "Out of kernel keyrings to allocate, ignoring.");
|
||||
else
|
||||
return log_error_errno(errno, "Setting up kernel keyring failed: %m");
|
||||
return log_unit_error_errno(u, errno, "Setting up kernel keyring failed: %m");
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -2209,19 +2209,19 @@ static int setup_keyring(
|
||||
|
||||
key = add_key("user", "invocation_id", &u->invocation_id, sizeof(u->invocation_id), KEY_SPEC_SESSION_KEYRING);
|
||||
if (key == -1)
|
||||
log_debug_errno(errno, "Failed to add invocation ID to keyring, ignoring: %m");
|
||||
log_unit_debug_errno(u, errno, "Failed to add invocation ID to keyring, ignoring: %m");
|
||||
else {
|
||||
if (keyctl(KEYCTL_SETPERM, key,
|
||||
KEY_POS_VIEW|KEY_POS_READ|KEY_POS_SEARCH|
|
||||
KEY_USR_VIEW|KEY_USR_READ|KEY_USR_SEARCH, 0, 0) < 0)
|
||||
return log_error_errno(errno, "Failed to restrict invocation ID permission: %m");
|
||||
return log_unit_error_errno(u, errno, "Failed to restrict invocation ID permission: %m");
|
||||
}
|
||||
}
|
||||
|
||||
/* And now, make the keyring owned by the service's user */
|
||||
if (uid_is_valid(uid) || gid_is_valid(gid))
|
||||
if (keyctl(KEYCTL_CHOWN, keyring, uid, gid, 0) < 0)
|
||||
return log_error_errno(errno, "Failed to change ownership of session keyring: %m");
|
||||
return log_unit_error_errno(u, errno, "Failed to change ownership of session keyring: %m");
|
||||
|
||||
/* When requested link the user keyring into the session keyring. */
|
||||
if (context->keyring_mode == EXEC_KEYRING_SHARED) {
|
||||
@ -2237,13 +2237,13 @@ static int setup_keyring(
|
||||
|
||||
if (gid_is_valid(gid) && gid != saved_gid) {
|
||||
if (setregid(gid, -1) < 0)
|
||||
return log_error_errno(errno, "Failed to change GID for user keyring: %m");
|
||||
return log_unit_error_errno(u, errno, "Failed to change GID for user keyring: %m");
|
||||
}
|
||||
|
||||
if (uid_is_valid(uid) && uid != saved_uid) {
|
||||
if (setreuid(uid, -1) < 0) {
|
||||
(void) setregid(saved_gid, -1);
|
||||
return log_error_errno(errno, "Failed to change UID for user keyring: %m");
|
||||
return log_unit_error_errno(u, errno, "Failed to change UID for user keyring: %m");
|
||||
}
|
||||
}
|
||||
|
||||
@ -2256,19 +2256,19 @@ static int setup_keyring(
|
||||
(void) setreuid(saved_uid, -1);
|
||||
(void) setregid(saved_gid, -1);
|
||||
|
||||
return log_error_errno(r, "Failed to link user keyring into session keyring: %m");
|
||||
return log_unit_error_errno(u, r, "Failed to link user keyring into session keyring: %m");
|
||||
}
|
||||
|
||||
if (uid_is_valid(uid) && uid != saved_uid) {
|
||||
if (setreuid(saved_uid, -1) < 0) {
|
||||
(void) setregid(saved_gid, -1);
|
||||
return log_error_errno(errno, "Failed to change UID back for user keyring: %m");
|
||||
return log_unit_error_errno(u, errno, "Failed to change UID back for user keyring: %m");
|
||||
}
|
||||
}
|
||||
|
||||
if (gid_is_valid(gid) && gid != saved_gid) {
|
||||
if (setregid(saved_gid, -1) < 0)
|
||||
return log_error_errno(errno, "Failed to change GID back for user keyring: %m");
|
||||
return log_unit_error_errno(u, errno, "Failed to change GID back for user keyring: %m");
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user