From f0bbb9629f587a15c5432d8e42e252de703c93ea Mon Sep 17 00:00:00 2001 From: Ondrej Kozina Date: Tue, 21 Jun 2016 12:00:01 +0200 Subject: [PATCH] syncSelinuxContexts: silence useless error messages with btrfs backend try syncing Selinux contexts on read-only 'snapshot' subvolumes is useless and these error messages are annoying --- snapper/Snapper.cc | 18 +++++++++++------- snapper/Snapper.h | 4 ++-- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/snapper/Snapper.cc b/snapper/Snapper.cc index b2e0eff0..a2da3c8b 100644 --- a/snapper/Snapper.cc +++ b/snapper/Snapper.cc @@ -114,7 +114,8 @@ namespace snapper filesystem = Filesystem::create(*config_info, root_prefix); - syncSelinuxContexts(); + // With btrfs backend, it's useless try syncing snapshot RO subvolumes + syncSelinuxContexts(filesystem->fstype() == "btrfs"); bool sync_acl; if (config_info->getValue(KEY_SYNC_ACL, sync_acl) && sync_acl == true) @@ -780,7 +781,7 @@ namespace snapper void - Snapper::syncSelinuxContexts() const + Snapper::syncSelinuxContexts(bool skip_snapshot_dir) const { #ifdef ENABLE_SELINUX try @@ -790,14 +791,14 @@ namespace snapper if (infos_dir.restorecon(selabel_handle)) { - syncSelinuxContextsInInfosDir(); + syncSelinuxContextsInInfosDir(skip_snapshot_dir); } else { SnapperContexts scons; if (infos_dir.fsetfilecon(scons.subvolume_context())) - syncSelinuxContextsInInfosDir(); + syncSelinuxContextsInInfosDir(skip_snapshot_dir); } } catch (const SelinuxException& e) @@ -810,7 +811,7 @@ namespace snapper void - Snapper::syncSelinuxContextsInInfosDir() const + Snapper::syncSelinuxContextsInInfosDir(bool skip_snapshot_dir) const { #ifdef ENABLE_SELINUX Regex rx("^[0-9]+$"); @@ -832,8 +833,11 @@ namespace snapper SFile info(info_dir, "info.xml"); info.restorecon(selabel_handle); - SFile snapshot_dir(info_dir, "snapshot"); - snapshot_dir.restorecon(selabel_handle); // this usually fails w/ btrfs backend (it's RO) + if (!skip_snapshot_dir) + { + SFile snapshot_dir(info_dir, "snapshot"); + snapshot_dir.restorecon(selabel_handle); + } vector info_content = info_dir.entries(); for (vector::const_iterator it2 = info_content.begin(); it2 != info_content.end(); ++it2) diff --git a/snapper/Snapper.h b/snapper/Snapper.h index d5dc4df9..6f9ce872 100644 --- a/snapper/Snapper.h +++ b/snapper/Snapper.h @@ -177,8 +177,8 @@ namespace snapper void syncAcl(const vector& uids, const vector& gids) const; - void syncSelinuxContexts() const; - void syncSelinuxContextsInInfosDir() const; + void syncSelinuxContexts(bool skip_snapshot_dir) const; + void syncSelinuxContextsInInfosDir(bool skip_snapshot_dir) const; void syncInfoDir(SDir& dir) const; ConfigInfo* config_info; -- 2.47.3