Skip to content

feat: add rootfsPropagation support and improve error handling#105

Merged
ComixHe merged 1 commit into
OpenAtom-Linyaps:masterfrom
ComixHe:master
Aug 5, 2025
Merged

feat: add rootfsPropagation support and improve error handling#105
ComixHe merged 1 commit into
OpenAtom-Linyaps:masterfrom
ComixHe:master

Conversation

@ComixHe

@ComixHe ComixHe commented Aug 5, 2025

Copy link
Copy Markdown
Collaborator
  • Add rootfsPropagation field to linux config (shared/slave/private/unbindable)
  • Fix mount propagation flag handling (use |= instead of &=)
  • Replace std::cerr with LINYAPS_BOX_ERR() for consistent logging
  • Use _exit() instead of exit() in child processes
  • Improve error messages with better context

Allows control over mount propagation for the root filesystem according to OCI spec.

- Add rootfsPropagation field to linux config (shared/slave/private/unbindable)
- Fix mount propagation flag handling (use |= instead of &=)
- Replace std::cerr with LINYAPS_BOX_ERR() for consistent logging
- Use _exit() instead of exit() in child processes
- Improve error messages with better context

Allows control over mount propagation for the root filesystem according
to OCI spec.

Signed-off-by: ComixHe <ComixHe1895@outlook.com>
@deepsource-io

deepsource-io Bot commented Aug 5, 2025

Copy link
Copy Markdown

Here's the code health analysis summary for commits 16f40a4..7ff9b3b. View details on DeepSource ↗.

Analysis Summary

AnalyzerStatusSummaryLink
DeepSource C & C++ LogoC & C++❌ Failure
❗ 3 occurences introduced
🎯 1 occurence resolved
View Check ↗
DeepSource Shell LogoShell✅ SuccessView Check ↗
DeepSource Secrets LogoSecrets✅ SuccessView Check ↗
DeepSource Test coverage LogoTest coverage⚠️ Artifact not reportedTimed out: Artifact was never reportedView Check ↗

💡 If you’re a repository administrator, you can configure the quality gates from the settings.

@ComixHe
ComixHe merged commit 308b80b into OpenAtom-Linyaps:master Aug 5, 2025
15 of 17 checks passed
Comment thread src/linyaps_box/app.cpp
Comment on lines 82 to 84
} catch (...) {
std::cerr << "Error: unknown" << std::endl;
LINYAPS_BOX_ERR() << "unknown error";
return -1;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The error handling for unknown exceptions logs a very generic message, which might not be helpful for diagnosing issues. Consider logging more context-specific information if possible, or at least include a suggestion to check the logs for more details. This could help in troubleshooting and maintaining the application more effectively.

Suggested Improvement:

LINYAPS_BOX_ERR() << "Unknown error occurred. Please check the logs for more details.";

Comment on lines 79 to 85
continue;
}
if (auto it = propagation_flags_map.find(opt); it != propagation_flags_map.end()) {
propagation_flags &= it->second;
propagation_flags |= it->second;
continue;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The repeated pattern of checking for an option in a map and then setting a flag is a candidate for refactoring to reduce code duplication and improve maintainability. Consider creating a helper function that takes the option, the map, and a reference to the flag variable. This function would encapsulate the logic found in lines 79-85, making the code cleaner and easier to maintain.

Comment on lines 262 to 282
linux.readonly_paths = std::move(readonly_paths);
}

if (auto rootfs_propagation = ptr / "rootfsPropagation"; obj.contains(rootfs_propagation)) {
auto val = obj[rootfs_propagation].get<std::string>();
if (val == "shared") {
linux.rootfs_propagation = MS_SHARED;
} else if (val == "slave") {
linux.rootfs_propagation = MS_SLAVE;
} else if (val == "private") {
linux.rootfs_propagation = MS_PRIVATE;
} else if (val == "unbindable") {
linux.rootfs_propagation = MS_UNBINDABLE;
} else {
throw std::runtime_error("unsupported rootfs propagation: " + val);
}
}

return linux;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The handling of rootfsPropagation using multiple if statements (lines 266-276) could be simplified and made more maintainable by using a map to associate string values with constants. This would reduce the complexity of the code and make it easier to add support for new propagation types in the future.

Comment thread src/linyaps_box/config.h
Comment on lines 123 to 125
std::optional<std::vector<id_mapping_t>> gid_mappings;
std::optional<std::vector<std::filesystem::path>> masked_paths;
std::optional<std::vector<std::filesystem::path>> readonly_paths;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The use of std::optional for std::vector types in lines 123-125 is unnecessary. A std::vector can be empty by default, which effectively represents 'no elements', making std::optional redundant. This not only simplifies the code but also avoids the overhead of checking whether the optional has a value.

Recommended Change:
Remove std::optional from gid_mappings, masked_paths, and readonly_paths, and handle them as regular vectors that can be empty if no elements are present.

Comment thread src/linyaps_box/config.h
std::optional<std::vector<id_mapping_t>> gid_mappings;
std::optional<std::vector<std::filesystem::path>> masked_paths;
std::optional<std::vector<std::filesystem::path>> readonly_paths;
unsigned int rootfs_propagation{ 0 };

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The rootfs_propagation field is initialized to zero without clear documentation or named constants, which can lead to confusion about the meaning of different values. Using named constants or an enum would improve the readability and maintainability of the code by making the mount propagation settings more explicit.

Recommended Change:
Define an enum or named constants that represent valid mount propagation settings and use these in place of the plain integer for rootfs_propagation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant