Skip to content

Conversation

@GalaxP
Copy link

@GalaxP GalaxP commented Sep 25, 2025

ListDetector checks for a change in the configuration file, if a change is detected, the module automatically restarts itself

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements automatic configuration reloading functionality for the ListDetector module. When changes are detected in the configuration file, the module automatically restarts itself to apply the new configuration.

  • Adds a new ConfigReloader class that monitors configuration files for changes
  • Implements file timestamp-based change detection with periodic checking
  • Integrates automatic restart functionality using process replacement via execv()

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
modules/listDetector/src/main.cpp Integrates ConfigReloader into the main application, copies argv for restart capability
modules/listDetector/src/configReloader.hpp Declares ConfigReloader class with file monitoring and restart functionality
modules/listDetector/src/configReloader.cpp Implements file change detection, monitoring thread, and process restart logic
modules/listDetector/src/CMakeLists.txt Adds configReloader.cpp to the build configuration

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +111 to +113
argv_copy[argc] = nullptr;
strcpy(argv_copy[i], argv[i]);
}
Copy link

Copilot AI Sep 26, 2025

Choose a reason for hiding this comment

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

Line 111 sets argv_copy[argc] to nullptr inside the loop, but this should be done after the loop completes. This will overwrite the null terminator on every iteration except the last.

Suggested change
argv_copy[argc] = nullptr;
strcpy(argv_copy[i], argv[i]);
}
strcpy(argv_copy[i], argv[i]);
}
argv_copy[argc] = nullptr;

Copilot uses AI. Check for mistakes.
Comment on lines +108 to +113
char** argv_copy = new char*[argc + 1];
for (int i = 0; i < argc; ++i) {
argv_copy[i] = new char[strlen(argv[i]) + 1];
argv_copy[argc] = nullptr;
strcpy(argv_copy[i], argv[i]);
}
Copy link

Copilot AI Sep 26, 2025

Choose a reason for hiding this comment

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

Memory allocated with 'new' is never freed, causing a memory leak. Consider using smart pointers or RAII containers like std::vectorstd::string instead of manual memory management.

Copilot uses AI. Check for mistakes.
Comment on lines +33 to +42
auto previousTimestamp = getLastModified(filePath);
while (true) {
sleep(CHECK_INTERVAL);
auto currentTimestamp = getLastModified(filePath);
if (currentTimestamp != previousTimestamp && currentTimestamp != -1) {
previousTimestamp = currentTimestamp;

this->restart();
}
}
Copy link

Copilot AI Sep 26, 2025

Choose a reason for hiding this comment

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

The infinite loop will continue running even after restart() is called. Since restart() calls execv() which replaces the current process, the code after restart() should be unreachable, but if execv() fails, the loop will continue indefinitely without any error handling.

Copilot uses AI. Check for mistakes.
Comment on lines +45 to +48
void ConfigReloader::restart()
{
execv(argv[0], argv);
}
Copy link

Copilot AI Sep 26, 2025

Choose a reason for hiding this comment

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

No error handling for execv() failure. If execv() fails, the function returns normally but the process hasn't been replaced, potentially leading to unexpected behavior. Consider adding error handling or at least logging when execv() fails.

Copilot uses AI. Check for mistakes.
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