]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
syncSelinuxContexts: silence useless error messages 239/head
authorOndrej Kozina <okozina@redhat.com>
Tue, 21 Jun 2016 10:00:01 +0000 (12:00 +0200)
committerOndrej Kozina <okozina@redhat.com>
Tue, 21 Jun 2016 10:01:50 +0000 (12:01 +0200)
with btrfs backend try syncing Selinux contexts on read-only
'snapshot' subvolumes is useless and these error messages are
annoying

snapper/Snapper.cc
snapper/Snapper.h

index b2e0eff002f1bcf0ede2abcbcc3f7519483813eb..a2da3c8b9fa5aa5f6143790e70add1ca09bded27 100644 (file)
@@ -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<string> info_content = info_dir.entries();
            for (vector<string>::const_iterator it2 = info_content.begin(); it2 != info_content.end(); ++it2)
index d5dc4df98fdc56d709385fa5e3737ae0bb2b8d49..6f9ce8722de217194c387a5195b0f1e28bc99831 100644 (file)
@@ -177,8 +177,8 @@ namespace snapper
 
        void syncAcl(const vector<uid_t>& uids, const vector<gid_t>& 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;