From a2fd65a1e9a711fae0734bdb539aae617115bd30 Mon Sep 17 00:00:00 2001 From: gcontini <1121667+gcontini@users.noreply.github.com> Date: 周三, 14 10月 2020 22:31:25 +0800 Subject: [PATCH] add debug --- src/library/locate/ExternalDefinition.cpp | 2 +- .travis.yml | 2 +- src/library/hw_identifier/default_strategy.cpp | 7 +++++-- src/library/os/linux/os_linux.cpp | 28 ++++++++++++++++++---------- 4 files changed, 25 insertions(+), 14 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6c0f6d6..95f04df 100644 --- a/.travis.yml +++ b/.travis.yml @@ -34,7 +34,7 @@ - ctest -T memcheck - os: linux dist: focal - name: "Ubuntu 20.04 - Travis CI VM" + name: "Ubuntu 20.04 - Travis CI VM - Debug" env: - VIRTUAL_ENV=VM - CTEST_OUTPUT_ON_FAILURE=1 diff --git a/src/library/hw_identifier/default_strategy.cpp b/src/library/hw_identifier/default_strategy.cpp index 2ca1aa4..5c924f1 100644 --- a/src/library/hw_identifier/default_strategy.cpp +++ b/src/library/hw_identifier/default_strategy.cpp @@ -67,9 +67,12 @@ } return identifiers; } - +/** +* default strategy should never be used to validate an identifier. The strategy that was used in the first place to generate it +* should handle it. DefaultStrategy is just a switch. +*/ LCC_EVENT_TYPE DefaultStrategy::validate_identifier(const HwIdentifier& identifier) const { - // default strategy should always realize itself as a concrete strategy + // return IDENTIFIERS_MISMATCH; } diff --git a/src/library/locate/ExternalDefinition.cpp b/src/library/locate/ExternalDefinition.cpp index a7386de..00a58ed 100644 --- a/src/library/locate/ExternalDefinition.cpp +++ b/src/library/locate/ExternalDefinition.cpp @@ -54,7 +54,7 @@ if (licenseLocation == get_strategy_name()) { string licData(m_location->licenseData, mstrnlen_s(m_location->licenseData, LCC_API_MAX_LICENSE_DATA_LENGTH)); if (m_location->license_data_type == LICENSE_ENCODED) { - // FIXME what if license is wrong + // FIXME what if license content is not base64 vector<uint8_t> raw = unbase64(licData); string str = string(reinterpret_cast<char *>(raw.data())); return str; diff --git a/src/library/os/linux/os_linux.cpp b/src/library/os/linux/os_linux.cpp index 0f53b9c..3c0dde2 100644 --- a/src/library/os/linux/os_linux.cpp +++ b/src/library/os/linux/os_linux.cpp @@ -3,6 +3,7 @@ #include <stdio.h> #include <cerrno> #include <cstring> +#include <string> #include "../os.h" #include "../../base/logger.h" @@ -93,8 +94,8 @@ currentDrive = 0; while (NULL != (ent = getmntent(aFile)) && currentDrive < maxDrives) { if ((strncmp(ent->mnt_type, "ext", 3) == 0 || strncmp(ent->mnt_type, "xfs", 3) == 0 || - strncmp(ent->mnt_type, "vfat", 4) == 0 || strncmp(ent->mnt_type, "ntfs", 4) == 0 - || strncmp(ent->mnt_type, "btr", 3) == 0) && + strncmp(ent->mnt_type, "vfat", 4) == 0 || strncmp(ent->mnt_type, "ntfs", 4) == 0 || + strncmp(ent->mnt_type, "btr", 3) == 0) && ent->mnt_fsname != NULL && strncmp(ent->mnt_fsname, "/dev/", 5) == 0) { if (stat(ent->mnt_fsname, &mount_stat) == 0) { drive_found = -1; @@ -104,7 +105,7 @@ } } if (drive_found == -1) { - LOG_DEBUG("mntent: %s %s %d\n", ent->mnt_fsname, ent->mnt_dir, + LOG_DEBUG("mntent fs:[%s],dir:[%s],inode:[%d]\n", ent->mnt_fsname, ent->mnt_dir, (unsigned long int)mount_stat.st_ino); strncpy(tmpDrives[currentDrive].device, ent->mnt_fsname, 255 - 1); statDrives[currentDrive] = mount_stat.st_ino; @@ -131,28 +132,36 @@ result = (currentDrive > 0) ? FUNC_RET_OK : FUNC_RET_NOT_AVAIL; } else if (*disk_info_size >= currentDrive) { disk_by_uuid_dir = opendir("/dev/disk/by-uuid"); - if (disk_by_uuid_dir == NULL) { + if (disk_by_uuid_dir == nullptr) { LOG_WARN("Open /dev/disk/by-uuid fail"); free(statDrives); return FUNC_RET_ERROR; } result = FUNC_RET_OK; *disk_info_size = currentDrive; - while ((dir = readdir(disk_by_uuid_dir)) != NULL) { - strcpy(cur_dir, "/dev/disk/by-uuid/"); - strncat(cur_dir, dir->d_name, 200); - if (stat(cur_dir, &sym_stat) == 0) { + + while ((dir = readdir(disk_by_uuid_dir)) != nullptr) { + std::string cur_dir("/dev/disk/by-uuid/"); + cur_dir += dir->d_name; + bool found = false; + if (stat(cur_dir.c_str(), &sym_stat) == 0) { for (i = 0; i < currentDrive; i++) { if (sym_stat.st_ino == statDrives[i]) { + found = true; parseUUID(dir->d_name, tmpDrives[i].disk_sn, sizeof(tmpDrives[i].disk_sn)); #ifndef NDEBUG VALGRIND_CHECK_VALUE_IS_DEFINED(tmpDrives[i].device); - LOG_DEBUG("uuid %d %s %02x%02x%02x%02x\n", i, tmpDrives[i].device, tmpDrives[i].disk_sn[0], tmpDrives[i].disk_sn[1], tmpDrives[i].disk_sn[2], tmpDrives[i].disk_sn[3]); #endif } } + if (!found) { + LOG_DEBUG("Drive [%s] inode [%d] did not match any existing drive\n", cur_dir, + (unsigned long int)sym_stat.st_ino); + } + } else { + LOG_DEBUG("Error %s during stat of %s \n", std::strerror(errno), cur_dir); } } closedir(disk_by_uuid_dir); @@ -179,7 +188,6 @@ free(statDrives); return result; } - FUNCTION_RETURN getMachineName(unsigned char identifier[6]) { static struct utsname u; -- Gitblit v1.9.1