Skip to content

Commit

Permalink
Merge pull request #124 from microsoft/policheck-fixes
Browse files Browse the repository at this point in the history
Yashkhatri/policheck fixes (#10)
  • Loading branch information
Yash-Khatri committed Aug 9, 2022
2 parents e24d39a + 1658246 commit 637d092
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 29 deletions.
8 changes: 4 additions & 4 deletions source/code/scxsystemlib/disk/diskdepend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1020,8 +1020,8 @@ namespace SCXSystemLib
// device was an LVM device path and dmDevice is the path to
// the same device using the device mapper name. The dm device
// is located on one or more normal devices, known as slaves.
std::vector< std::wstring > slaves = lvmUtils.GetDMSlaves(dmDevice);
if (slaves.size() == 0)
std::vector< std::wstring > children = lvmUtils.GetDMSlaves(dmDevice);
if (children.size() == 0)
{
// this condition can only be reached on RHEL4/SLES9 systems
std::wstringstream out;
Expand All @@ -1038,8 +1038,8 @@ namespace SCXSystemLib
}
else
{
for (std::vector< std::wstring >::const_iterator iter = slaves.begin();
iter != slaves.end(); iter++)
for (std::vector< std::wstring >::const_iterator iter = children.begin();
iter != children.end(); iter++)
{
if ((*iter).empty() || !isdigit((int)(*iter)[(*iter).size() - 1]))
{
Expand Down
38 changes: 19 additions & 19 deletions source/code/scxsystemlib/disk/scxlvmutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ namespace SCXSystemLib {
static inline std::wstring GetSysfsPath(const std::wstring& dmDeviceName)
{
// First look in Sysfs to find out what partitions the dm device
// maps onto. This is done by listing the slaves entries for the
// maps onto. This is done by listing the child entries for the
// given dm device.
//
// Note: The entries in slaves are links and it is the link name
Expand All @@ -219,16 +219,16 @@ namespace SCXSystemLib {
return sysfsPath.str();
}

static inline bool PushIfDMSlave(const SCXCoreLib::SCXFilePath & slave, std::stack<std::wstring> &dmDeviceStack)
static inline bool PushIfDMSlave(const SCXCoreLib::SCXFilePath & child, std::stack<std::wstring> &dmDeviceStack)
{
if (!slave.Get().empty() && *(slave.Get().rbegin()) == SCXCoreLib::SCXFilePath::GetFolderSeparator())
if (!child.Get().empty() && *(child.Get().rbegin()) == SCXCoreLib::SCXFilePath::GetFolderSeparator())
{
// A precautionary check - avoid any possible entries in the slaves folder that are not links to directories
SCXCoreLib::SCXFilePath slaveName = slave.Get().substr(0, slave.Get().length() - 1);
if(SCXCoreLib::StrIsPrefix(slaveName.GetFilename(), L"dm-"))
SCXCoreLib::SCXFilePath childName = child.Get().substr(0, child.Get().length() - 1);
if(SCXCoreLib::StrIsPrefix(childName.GetFilename(), L"dm-"))
{
// add only those files which have the dm- prefix
dmDeviceStack.push(slaveName.GetFilename());
dmDeviceStack.push(childName.GetFilename());
return true;
}
}
Expand All @@ -237,7 +237,7 @@ namespace SCXSystemLib {
}

/**
Get the slave devices that contain the given devicemapper (dm) device.
Get the child devices that contain the given devicemapper (dm) device.
\param[in] dmDevice the path to a dm device.
Expand Down Expand Up @@ -265,7 +265,7 @@ namespace SCXSystemLib {
// we use a non-recursive depth-first traversal.
std::stack<std::wstring> dmDeviceStack;
dmDeviceStack.push(((SCXCoreLib::SCXFilePath) dmDevice).GetFilename());
std::vector< SCXCoreLib::SCXFilePath > slaves;
std::vector< SCXCoreLib::SCXFilePath > children;
unsigned int loopCount = 0;

while(!dmDeviceStack.empty())
Expand All @@ -275,12 +275,12 @@ namespace SCXSystemLib {
{
std::wstring currentDeviceName = dmDeviceStack.top();
dmDeviceStack.pop();
std::vector< SCXCoreLib::SCXFilePath > slaveEntries = m_extDepends->GetFileSystemEntries(GetSysfsPath(currentDeviceName));
for( std::vector< SCXCoreLib::SCXFilePath >::const_iterator iter = slaveEntries.begin(); iter != slaveEntries.end(); ++iter)
std::vector< SCXCoreLib::SCXFilePath > childEntries = m_extDepends->GetFileSystemEntries(GetSysfsPath(currentDeviceName));
for( std::vector< SCXCoreLib::SCXFilePath >::const_iterator iter = childEntries.begin(); iter != childEntries.end(); ++iter)
{
if(!PushIfDMSlave(*iter, dmDeviceStack))
{
slaves.push_back(*iter);
children.push_back(*iter);
}
}
if (loopCount > maxLoopCount)
Expand All @@ -298,7 +298,7 @@ namespace SCXSystemLib {
out.str(L"");
out << L"Exceeded " << maxLoopCount << L" while evaluating device " << dmDevice;
SCX_LOG(log,suppressor.GetSeverity(out.str()), out.str());
slaves.clear();
children.clear();
break;
}
}
Expand Down Expand Up @@ -332,13 +332,13 @@ namespace SCXSystemLib {
return result;
#endif
out.str(L"");
out << L"An exception occurred while getting the slave devices for \"" << dmDevice << L"\": " << e.What();
out << L"An exception occurred while getting the child devices for \"" << dmDevice << L"\": " << e.What();
SCX_LOG(log, m_errorSuppressor.GetSeverity(out.str()), out.str());
throw;
}
}

if (slaves.size() == 0)
if (children.size() == 0)
{
#if defined(linux) && \
( ( defined(PF_DISTRO_SUSE) && (PF_MAJOR<=9) ) || \
Expand Down Expand Up @@ -370,15 +370,15 @@ namespace SCXSystemLib {

out.str(L"");

out << L"There are no slave entries for the device \"" << dmDevice << L"\"";
out << L"There are no child entries for the device \"" << dmDevice << L"\"";
SCX_LOG(log, m_errorSuppressor.GetSeverity(out.str()), out.str());

throw SCXBadLVMDeviceException(dmDevice, out.str(), SCXSRCLOCATION);
}

// Each slave entry should be the name of a block device in /dev.
for (std::vector< SCXCoreLib::SCXFilePath >::const_iterator iter = slaves.begin();
iter != slaves.end(); iter++)
// Each child entry should be the name of a block device in /dev.
for (std::vector< SCXCoreLib::SCXFilePath >::const_iterator iter = children.begin();
iter != children.end(); iter++)
{
std::wstring dirpath = iter->GetDirectory();
size_t dirPathLen = dirpath.length();
Expand All @@ -389,7 +389,7 @@ namespace SCXSystemLib {
{
out.str(L"");

out << L"The slave device entry \"" << dirpath << L"\" could not be parsed and will be ignored";
out << L"The child device entry \"" << dirpath << L"\" could not be parsed and will be ignored";
SCX_LOG(log, m_warningSuppressor.GetSeverity(dirpath), out.str());
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ namespace SCXSystemLib
1-to-1 relationship and the <id> is equal to the device minor ID that both
device entries have in common. Discovery of the physical device(s) that
contain the LVM partition is done by mapping the LVM device to the dm device,
then looking at the dm devices slave entries in Sysfs, and then finally
then looking at the dm devices child entries in Sysfs, and then finally
performing the same conversion from a logical Linux partition name to a
physical drive name that is done for all other partitions.
Expand Down
10 changes: 5 additions & 5 deletions source/code/scxsystemlib/os/osinstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ static LocaleInfo LocaleInfoTable[] =
{ "sr", "RS", 0x081A, 381, 65001 }, // Serbian-Serbia (Latin alphabet)
{ "sk", "SK", 0x041B, 421, 28591 }, // Slovak default to Slovakia
{ "sq", "AL", 0x041C, 355, 65001 }, // Albanian-Albania
{ "mk", "MK", 0x042F, 389, 65001 }, // Macedonia, FYRO
{ "mk", "MK", 0x042F, 389, 65001 }, // North Macedonia
{ "be", "BY", 0x0423, 375, 65001 }, // Belarusian-Belarus
{ "sl", "SI", 0x0424, 386, 65001 }, // Slovenian-Sloveniua
{ "et", "EE", 0x0425, 372, 65001 }, // Estonian-Estonia
Expand Down Expand Up @@ -355,7 +355,7 @@ static unsigned int GetWindowsLocaleCode(
char isoCountryCode1,
char isoCountryCode2)
{
// search the language and locale table for a match with the language and country passed in
// search the language and locale table for a match with the language and country/region passed in
for (size_t i = 0; i < sizeof LocaleInfoTable / sizeof (LocaleInfo); i++)
{
if (LocaleInfoTable[i].Iso639LanguageCode[0] == isoLangCode1 &&
Expand All @@ -382,7 +382,7 @@ static unsigned int GetCountryCode(
char isoLangCode1,
char isoLangCode2)
{
// search the locale table for a match with the country passed in
// search the locale table for a match with the country/region passed in
for (size_t i = 0; i < sizeof LocaleInfoTable / sizeof (LocaleInfo); i++)
{
if (LocaleInfoTable[i].Iso3166CountryCode[0] == isoCountryCode1 &&
Expand All @@ -392,7 +392,7 @@ static unsigned int GetCountryCode(
}
}

// if the country wasn't there, return the default country for the language
// if the country/region wasn't there, return the default country/region for the language
return GetDefaultCountryCode(isoLangCode1, isoLangCode2);
}

Expand Down Expand Up @@ -531,7 +531,7 @@ namespace SCXSystemLib
const wchar_t *OSInstance::moduleIdentifier = L"scx.core.common.pal.system.os.osinstance";

/*
Get the language, country and code page information from the Unix/Linux LANG variable.
Get the language, country/region and code page information from the Unix/Linux LANG variable.
The LANG variable is supposed to be of one of the forms:
la
Expand Down

0 comments on commit 637d092

Please sign in to comment.