From: Arvin Schnell Date: Fri, 24 Mar 2023 08:29:11 +0000 (+0100) Subject: - coding style X-Git-Tag: v0.10.5~30^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=df51d44d535fd1010e85ced792713067142a672f;p=thirdparty%2Fsnapper.git - coding style --- diff --git a/snapper/FileUtils.cc b/snapper/FileUtils.cc index 97c5f51f..92662d19 100644 --- a/snapper/FileUtils.cc +++ b/snapper/FileUtils.cc @@ -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 +#include #include #include #include @@ -33,12 +33,9 @@ #include #include #include -#include +#include #include -#include -#ifdef ENABLE_SELINUX -#include -#endif +#include #include #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); } diff --git a/snapper/FileUtils.h b/snapper/FileUtils.h index 2b189d06..7cf0d689 100644 --- a/snapper/FileUtils.h +++ b/snapper/FileUtils.h @@ -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: diff --git a/snapper/Lvm.cc b/snapper/Lvm.cc index e2abeaac..6021faef 100644 --- a/snapper/Lvm.cc +++ b/snapper/Lvm.cc @@ -23,10 +23,10 @@ #include "config.h" -#include +#include #include #include -#include +#include #include #include #include @@ -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 diff --git a/snapper/Lvm.h b/snapper/Lvm.h index ff9a5669..6a31e984 100644 --- a/snapper/Lvm.h +++ b/snapper/Lvm.h @@ -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; diff --git a/snapper/Selinux.cc b/snapper/Selinux.cc index e7fad523..23955ec5 100644 --- a/snapper/Selinux.cc +++ b/snapper/Selinux.cc @@ -21,7 +21,6 @@ #include #include - #include #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; } } diff --git a/snapper/Snapper.cc b/snapper/Snapper.cc index e76977b2..5966c471 100644 --- a/snapper/Snapper.cc +++ b/snapper/Snapper.cc @@ -26,7 +26,7 @@ #include #include #include -#include +#include #include #include #include