Skip to content

refactor: use Cmd class for hook command execution#1674

Merged
dengbo11 merged 1 commit into
OpenAtom-Linyaps:masterfrom
dengbo11:fix-security
Jun 18, 2026
Merged

refactor: use Cmd class for hook command execution#1674
dengbo11 merged 1 commit into
OpenAtom-Linyaps:masterfrom
dengbo11:fix-security

Conversation

@dengbo11

Copy link
Copy Markdown
Collaborator
  1. Replace std::system() calls with Cmd class for better process control
  2. Remove escapeAndWrapCommandForShell function, now using Cmd.exec() with argument list
  3. Replace EnvironmentVariableGuard with Cmd.setEnv() for environment handling
  4. Simplify error handling by leveraging Cmd class result types
  5. Update copyright year to 2025-2026
  6. Remove unused includes (linglong/utils/env.h, cstdlib)

Influence:

  1. Test hook commands execution with valid commands
  2. Verify hook commands with environment variables are properly set
  3. Test error handling when hook commands fail
  4. Verify pre-install, post-install, and post-uninstall hooks work correctly
  5. Test commands with special characters and quotes
  6. Verify proper error messages are returned for failed commands

@dengbo11 dengbo11 requested review from ComixHe and reddevillg June 12, 2026 01:42

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request refactors hook command execution in libs/utils/src/linglong/utils/hooks.cpp by replacing std::system and manual shell escaping with a custom Cmd class wrapper. This simplifies environment variable handling and command execution. Feedback on this change highlights that switching to Cmd::exec() captures standard output into the result, which is currently discarded. It is recommended to log this output when successful to prevent losing debugging and monitoring information.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +49 to 53
auto result = cmd.exec({ "-c", command });
if (!result.has_value()) {
return LINGLONG_ERR(
fmt::format("Hook command '{}' failed: {}.", command, result.error()));
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

With the switch from std::system() to Cmd::exec(), the standard output (stdout) of the hook commands is now captured into result.value() instead of being printed directly to the standard output of the parent process. Since result.value() is currently discarded, any output printed by successful hook commands will be completely lost, which can make debugging and monitoring difficult.

Consider logging the stdout of the hook command if it is not empty.

        auto result = cmd.exec({ "-c", command });
        if (!result.has_value()) {
            return LINGLONG_ERR(
              fmt::format("Hook command '{}' failed: {}.", command, result.error()));
        }
        if (!result.value().empty()) {
            LogD("Hook command '{}' output: {}", command, result.value());
        }

@codecov

codecov Bot commented Jun 12, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 8 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
libs/utils/src/linglong/utils/hooks.cpp 0.00% 8 Missing ⚠️
Files with missing lines Coverage Δ
libs/utils/src/linglong/utils/hooks.cpp 0.00% <0.00%> (ø)

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread libs/utils/src/linglong/utils/hooks.cpp Outdated
Comment thread libs/utils/src/linglong/utils/hooks.cpp
1. Replace std::system() calls with Cmd class for better process control
2. Remove escapeAndWrapCommandForShell function, now using Cmd.exec()
with argument list
3. Replace EnvironmentVariableGuard with Cmd.setEnv() for environment
handling
4. Simplify error handling by leveraging Cmd class result types
5. Update copyright year to 2025-2026
6. Remove unused includes (linglong/utils/env.h, cstdlib)

Influence:
1. Test hook commands execution with valid commands
2. Verify hook commands with environment variables are properly set
3. Test error handling when hook commands fail
4. Verify pre-install, post-install, and post-uninstall hooks work
correctly
5. Test commands with special characters and quotes
6. Verify proper error messages are returned for failed commands
@dengbo11 dengbo11 requested a review from ComixHe June 18, 2026 08:58
@dengbo11 dengbo11 merged commit 9e3220f into OpenAtom-Linyaps:master Jun 18, 2026
15 of 16 checks passed
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.

3 participants