]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
- coding style
authorArvin Schnell <aschnell@suse.de>
Fri, 24 Mar 2023 08:29:11 +0000 (09:29 +0100)
committerArvin Schnell <aschnell@suse.de>
Fri, 24 Mar 2023 08:29:11 +0000 (09:29 +0100)
snapper/FileUtils.cc
snapper/FileUtils.h
snapper/Lvm.cc
snapper/Lvm.h
snapper/Selinux.cc
snapper/Snapper.cc

index 97c5f51f4c50424b067eb49850bca482caa2d678..92662d1914ea0607a3ec30cfc7af3399e349300e 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Copyright (c) [2011-2014] Novell, Inc.
- * Copyright (c) [2018-2020] SUSE LLC
+ * Copyright (c) [2018-2023] SUSE LLC
  *
  * All Rights Reserved.
  *
@@ -23,7 +23,7 @@
 
 #include "config.h"
 
-#include <string.h>
+#include <cstring>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/mount.h>
 #include <stddef.h>
 #include <dirent.h>
 #include <unistd.h>
-#include <errno.h>
+#include <cerrno>
 #include <stdlib.h>
-#include <assert.h>
-#ifdef ENABLE_SELINUX
-#include <selinux/selinux.h>
-#endif
+#include <cassert>
 #include <algorithm>
 
 #include "snapper/FileUtils.h"
@@ -633,8 +630,7 @@ namespace snapper
        {
            char *src_con = NULL;
 
-           int fd = ::openat(dirfd, name.c_str(), O_RDONLY | O_NOFOLLOW | O_NOATIME
-                             | O_NONBLOCK | O_CLOEXEC);
+           int fd = ::openat(dirfd, name.c_str(), O_RDONLY | O_NOFOLLOW | O_NOATIME | O_NONBLOCK | O_CLOEXEC);
            if (fd < 0)
            {
                // symlink, detached dev node?
@@ -657,7 +653,8 @@ namespace snapper
                    y2deb("setting new SELinux context on " << fullname() << "/" << name);
                    if (lsetfilecon(name.c_str(), con))
                    {
-                       y2err("lsetfilecon on " << fullname() << "/" << name << " failed errno: " << errno << " (" << stringerror(errno) << ")");
+                       y2err("lsetfilecon on " << fullname() << "/" << name << " failed errno: " << errno <<
+                             " (" << stringerror(errno) << ")");
                        retval = false;
                    }
                }
@@ -672,7 +669,8 @@ namespace snapper
                    y2deb("setting new SELinux context on " << fullname() << "/" << name);
                    if (::fsetfilecon(fd, con))
                    {
-                       y2err("fsetfilecon on " << fullname() << "/" << name << " failed errno: " << errno << " (" << stringerror(errno) << ")");
+                       y2err("fsetfilecon on " << fullname() << "/" << name << " failed errno: " << errno <<
+                             " (" << stringerror(errno) << ")");
                        retval = false;
                    }
                }
@@ -683,21 +681,23 @@ namespace snapper
            freecon(src_con);
        }
 #endif
+
        return retval;
     }
 
 
     bool
-    SDir::restorecon(const string& name, SelinuxLabelHandle* sh) const
+    SDir::restorecon(const string& name, SelinuxLabelHandle* selabel_handle) const
     {
        assert(name.find('/') == string::npos);
        assert(name != "..");
 
        bool retval = true;
+
 #ifdef ENABLE_SELINUX
        if (_is_selinux_enabled())
        {
-           assert(sh);
+           assert(selabel_handle);
 
            struct stat buf;
            if (stat(name, &buf, AT_SYMLINK_NOFOLLOW))
@@ -706,7 +706,7 @@ namespace snapper
                return false;
            }
 
-           char* con = sh->selabel_lookup(fullname() + "/" + name, buf.st_mode);
+           char* con = selabel_handle->selabel_lookup(fullname() + "/" + name, buf.st_mode);
            if (con)
            {
                retval = fsetfilecon(name, con);
@@ -719,6 +719,7 @@ namespace snapper
            freecon(con);
        }
 #endif
+
        return retval;
     }
 
@@ -746,18 +747,20 @@ namespace snapper
            freecon(src_con);
        }
 #endif
+
        return retval;
     }
 
 
     bool
-    SDir::restorecon(SelinuxLabelHandle* sh) const
+    SDir::restorecon(SelinuxLabelHandle* selabel_handle) const
     {
        bool retval = true;
+
 #ifdef ENABLE_SELINUX
        if (_is_selinux_enabled())
        {
-           assert(sh);
+           assert(selabel_handle);
 
            struct stat buf;
 
@@ -767,7 +770,7 @@ namespace snapper
                return false;
            }
 
-           char* con = sh->selabel_lookup(fullname(), buf.st_mode);
+           char* con = selabel_handle->selabel_lookup(fullname(), buf.st_mode);
            if (con)
            {
                retval = fsetfilecon(con);
@@ -781,6 +784,7 @@ namespace snapper
            freecon(con);
        }
 #endif
+
        return retval;
     }
 
@@ -855,10 +859,11 @@ namespace snapper
        dir.fsetfilecon(name, con);
     }
 
+
     void
-    SFile::restorecon(SelinuxLabelHandle* sh) const
+    SFile::restorecon(SelinuxLabelHandle* selabel_handle) const
     {
-       dir.restorecon(name, sh);
+       dir.restorecon(name, selabel_handle);
     }
 
 
index 2b189d06f35a364b084688a00380213aff134187..7cf0d689c6378f95d39127affcbd92b17192ba06 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Copyright (c) [2011-2014] Novell, Inc.
- * Copyright (c) 2020 SUSE LLC
+ * Copyright (c) [2020-2023] SUSE LLC
  *
  * All Rights Reserved.
  *
@@ -110,8 +110,8 @@ namespace snapper
 
        bool fsetfilecon(const string& name, const char* con) const;
        bool fsetfilecon(const char* con) const;
-       bool restorecon(SelinuxLabelHandle* sh) const;
-       bool restorecon(const string& name, SelinuxLabelHandle* sh) const;
+       bool restorecon(SelinuxLabelHandle* selabel_handle) const;
+       bool restorecon(const string& name, SelinuxLabelHandle* selabel_handle) const;
 
     private:
 
@@ -147,7 +147,7 @@ namespace snapper
        ssize_t getxattr(const char* name, void* value, size_t size) const;
 
        void fsetfilecon(const char* con) const;
-       void restorecon(SelinuxLabelHandle* sh) const;
+       void restorecon(SelinuxLabelHandle* selabel_handle) const;
 
     private:
 
index e2abeaac66c7114c5625a310e8bc7244ad8067d7..6021faef62e94ab4bbc00e77fcf3746755256f51 100644 (file)
 
 #include "config.h"
 
-#include <string.h>
+#include <cstring>
 #include <sys/stat.h>
 #include <sys/types.h>
-#include <errno.h>
+#include <cerrno>
 #include <unistd.h>
 #include <fcntl.h>
 #include <sys/ioctl.h>
@@ -69,7 +69,7 @@ namespace snapper
     Lvm::Lvm(const string& subvolume, const string& root_prefix, const string& mount_type)
        : Filesystem(subvolume, root_prefix), mount_type(mount_type),
          caps(LvmCapabilities::get_lvm_capabilities()),
-         cache(LvmCache::get_lvm_cache()), sh(NULL)
+         cache(LvmCache::get_lvm_cache())
     {
        if (access(LVCREATEBIN, X_OK) != 0)
        {
@@ -108,7 +108,7 @@ namespace snapper
 #ifdef ENABLE_SELINUX
        try
        {
-           sh = SelinuxLabelHandle::get_selinux_handle();
+           selabel_handle = SelinuxLabelHandle::get_selinux_handle();
        }
        catch (const SelinuxException& e)
        {
@@ -140,7 +140,7 @@ namespace snapper
 #ifdef ENABLE_SELINUX
        if (_is_selinux_enabled())
        {
-           assert(sh);
+           assert(selabel_handle);
 
            char* con = NULL;
 
@@ -148,7 +148,7 @@ namespace snapper
            {
                string path(subvolume_dir.fullname() + "/.snapshots");
 
-               con = sh->selabel_lookup(path, mode);
+               con = selabel_handle->selabel_lookup(path, mode);
                if (con)
                {
                    // race free mkdir with correct Selinux context preset
index ff9a56699d6905907661f45ea5abf722ca991ce3..6a31e984d3f6b6bfa963643cbae9874a0b527a1b 100644 (file)
@@ -115,7 +115,7 @@ namespace snapper
        const string mount_type;
        const LvmCapabilities* caps;
        LvmCache* cache;
-       SelinuxLabelHandle* sh;
+       SelinuxLabelHandle* selabel_handle = nullptr;
 
        bool detectThinVolumeNames(const MtabData& mtab_data);
        void activateSnapshot(const string& vg_name, const string& lv_name) const;
index e7fad52361b15272564b4396ef56303c8af5bbd8..23955ec5dd1341dcc1a711065eeb79d599473a20 100644 (file)
@@ -21,7 +21,6 @@
 
 #include <cerrno>
 #include <map>
-
 #include <boost/algorithm/string.hpp>
 
 #include "snapper/AppUtil.h"
@@ -131,13 +130,14 @@ namespace snapper
     bool
     _is_selinux_enabled()
     {
-       static bool selinux_enabled, selinux_checked = false;
+       static bool selinux_enabled = false;
+       static bool selinux_checked = false;
 
        if (!selinux_checked)
        {
            selinux_enabled = (is_selinux_enabled() == 1); // may return -1 on error
            selinux_checked = true;
-           y2mil("Selinux support " << (selinux_enabled ? "en" : "dis") << "abled");
+           y2mil("Selinux support " << (selinux_enabled ? "enabled" : "disabled"));
        }
 
        return selinux_enabled;
@@ -153,7 +153,7 @@ namespace snapper
            return &handle;
        }
 
-       return NULL;
+       return nullptr;
     }
 
 }
index e76977b2e2dd2457eca480c6d7bdcad3552b59c7..5966c471f2775df403847907a1f8ef5bad38ce8c 100644 (file)
@@ -26,7 +26,7 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <glob.h>
-#include <string.h>
+#include <cstring>
 #include <mntent.h>
 #include <sys/acl.h>
 #include <acl/libacl.h>