Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle existing sym link with no devTree tag #442

Open
wants to merge 1 commit into
base: P11_Dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 51 additions & 9 deletions src/worker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,9 @@ void Worker::setDeviceTreeAndJson()
types::VPDMapVariant parsedVpdMap;
fillVPDMap(SYSTEM_VPD_FILE_PATH, parsedVpdMap);

// ToDo: Need to check is INVENTORY_JSON_SYM_LINK pointing to correct system
// JSON or not, if the sym link exists already.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need this todo anymore?


// Do we have the entry for device tree in parsed JSON?
if (m_parsedJson.find("devTree") == m_parsedJson.end())
{
Expand All @@ -466,31 +469,71 @@ void Worker::setDeviceTreeAndJson()
ec);
if (ec)
{
throw std::runtime_error(
"create_symlink system call failed with error" + ec.message());
if (ec.message().compare("File exists") ==

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of doing string compare, can we check on the error code which is 17 for file exists?
https://mariadb.com/kb/en/operating-system-error-codes/

constexpr auto EEXIST = 17;
if(errno == EEXIST)
{
...
}

constants::STR_CMP_SUCCESS)
{
ec.clear();
logging::logMessage(
"Sym link already exists, file [" +
std::string(INVENTORY_JSON_SYM_LINK) +

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we know that the symlink path is always /var/lib/vpd/vpd_inventory.json.

what we don't know here is to which target JSON the link is pointing to. You can use filesystem::read_symlink(p) to get the target json path.

Please try to add the target json along with the source json in the below logs as well.

"] deleting and creating sym link again, target file: " +
systemJson);

if (std::filesystem::remove(INVENTORY_JSON_SYM_LINK, ec))
{
std::filesystem::create_symlink(
systemJson, INVENTORY_JSON_SYM_LINK, ec);
if (ec)
{
throw std::runtime_error(
"create_symlink system call failed with error: " +
ec.message());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we have a format to print the error message, something like :
"Error description message. " +
"errno = " +
" Symlink : <source_json_ path> --> < target json path> "

}
}
else
{
logging::logMessage(
"remove system call failed for file[" +

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of this statement "remove system call failed for file"
can we have something like - "Unable to delete the existing symlink " -> this will create a relation with the message you logged in line 477.

If there is a continuity in the message statements we log, it will help us in debugging without looking at the code.

std::string(INVENTORY_JSON_SYM_LINK) + "], error[" +
ec.message() + "], continuing with existing sym link.");
}
}
else
{
throw std::runtime_error(
"create_symlink system call failed with error: " +

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing symlink source and target path

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also the error message in line 504 and line 489 are same. While debugging it is not easy to figure out where we hit the issue. So let's have a description which helps us in debugging.

ec.message());
}
}

// re-parse the JSON once appropriate JSON has been selected.
try
{
m_parsedJson = nlohmann::json::parse(INVENTORY_JSON_SYM_LINK);
m_parsedJson = jsonUtility::getParsedJson(INVENTORY_JSON_SYM_LINK);
}
catch (const nlohmann::json::parse_error& ex)
{
throw(JsonException("Json parsing failed", systemJson));
}
}

auto devTreeFromJson = m_parsedJson["devTree"];
if (devTreeFromJson.empty())
std::string devTreeFromJson;
if (m_parsedJson.contains("devTree"))
{
throw JsonException("Mandatory value for device tree missing from JSON",
INVENTORY_JSON_SYM_LINK);
devTreeFromJson = m_parsedJson["devTree"];

if (devTreeFromJson.empty())
{
throw JsonException(
"Mandatory value for device tree missing from JSON",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

your commit message says that, you will allow the application to run if devTree tag is not found. But here you are throwing the exception. can you please check on this

INVENTORY_JSON_SYM_LINK);
}
}

auto fitConfigVal = readFitConfigValue();

if (fitConfigVal.find(devTreeFromJson) != std::string::npos)
if (devTreeFromJson.empty() ||
fitConfigVal.find(devTreeFromJson) != std::string::npos)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in line 536, why are you using find and not == ?

{ // fitconfig is updated and correct JSON is set.

if (isSystemVPDOnDBus() &&
Expand All @@ -504,7 +547,6 @@ void Worker::setDeviceTreeAndJson()
return;
}

// Set fitconfig even if it is read as empty.
setEnvAndReboot("fitconfig", devTreeFromJson);
exit(EXIT_SUCCESS);
}
Expand Down