-
Notifications
You must be signed in to change notification settings - Fork 21
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
base: P11_Dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
|
||
// Do we have the entry for device tree in parsed JSON? | ||
if (m_parsedJson.find("devTree") == m_parsedJson.end()) | ||
{ | ||
|
@@ -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") == | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? constexpr auto EEXIST = 17; |
||
constants::STR_CMP_SUCCESS) | ||
{ | ||
ec.clear(); | ||
logging::logMessage( | ||
"Sym link already exists, file [" + | ||
std::string(INVENTORY_JSON_SYM_LINK) + | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we have a format to print the error message, something like : |
||
} | ||
} | ||
else | ||
{ | ||
logging::logMessage( | ||
"remove system call failed for file[" + | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of this statement "remove system call failed for file" 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: " + | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing symlink source and target path There was a problem hiding this comment. Choose a reason for hiding this commentThe 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", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() && | ||
|
@@ -504,7 +547,6 @@ void Worker::setDeviceTreeAndJson() | |
return; | ||
} | ||
|
||
// Set fitconfig even if it is read as empty. | ||
setEnvAndReboot("fitconfig", devTreeFromJson); | ||
exit(EXIT_SUCCESS); | ||
} | ||
|
There was a problem hiding this comment.
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?