Merge pull request #3266 from ericcurtin/if-file-missing-on-relabel-continue

remount: ignore ENOENT error during SELinux relabeling
This commit is contained in:
Colin Walters 2024-06-18 14:14:02 -04:00 committed by GitHub
commit f280b1216b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 2 deletions

View File

@ -25,7 +25,7 @@ After=-.mount var.mount
After=systemd-remount-fs.service
# But we run *before* most other core bootup services that need write access to /etc and /var
Before=local-fs.target umount.target
Before=systemd-random-seed.service plymouth-read-write.service systemd-journal-flush.service
Before=systemd-random-seed.service plymouth-read-write.service systemd-journal-flush.service systemd-sysusers.service
Before=systemd-tmpfiles-setup.service systemd-rfkill.service systemd-rfkill.socket
[Service]

View File

@ -90,8 +90,18 @@ static void
relabel_dir_for_upper (const char *upper_path, const char *real_path, gboolean is_dir)
{
#ifdef HAVE_SELINUX
/* Ignore ENOENT, because if there is no file to relabel we can continue,
* systemd-sysusers runs in parallel and can create temporary files in /etc
* causing failures like:
* "Failed to relabel /etc/.#gshadowJzu4Rx: No such file or directory"
*/
if (selinux_restorecon (real_path, 0))
err (EXIT_FAILURE, "Failed to relabel %s", real_path);
{
if (errno == ENOENT)
return;
err (EXIT_FAILURE, "Failed to relabel %s", real_path);
}
if (!is_dir)
return;