Skip to content

Updated Code from PR #2304 #3371

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

Closed
wants to merge 3 commits into from

Conversation

akama-aka
Copy link

@akama-aka akama-aka commented May 6, 2025

I won't continue that because I don't have the time and motivation to do so. Even tho it's just vibe coded and thats not a way how to solve issues or missing features.

akama-aka added 2 commits May 6, 2025 08:06
This code was written by: @brandonpayton

Co-authored-by: @brandonpayton
@@ -369,6 +369,12 @@ bool AuditLog::merge(AuditLog *from, std::string *error) {
return init(error);
}

bool AuditLog::reopen(std::string *error) {
if (m_writer != NULL) {
Copy link
Member

Choose a reason for hiding this comment

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

As Sonarcloud shows here you should use nullptr instead of NULL. I see there are many other NULL literals in this file - feel free to replace them.

Comment on lines +328 to 347
extern "C" int msc_rules_reopen_audit_log(RulesSet *rules, const char **error) {
bool succeeded = true;
std::string errorStr;

if (rules->m_auditLog != NULL) {
succeeded = rules->m_auditLog->reopen(&errorStr);
}

if (!succeeded) {
if (!errorStr.empty()) {
*error = strdup(errorStr.c_str());
} else {
// Guarantee an error message is always assigned in the event of a failure
*error = strdup("Unknown error reopening audit log");
}
}

return succeeded ? 0 : -1;
}

Copy link
Member

Choose a reason for hiding this comment

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

I know this is a completely valid solution, but as you can see in other "C" API functions, the authors tied to avoid all the logic and use C++ types (like here the bool and std::string).

My suggestion here: create a thin wrapper, an "extra" function.

You should add a new function to RulesSet class with name reopen(), move this body there, and in this "C" API you have to call only that function.

//
//

functionConst:src/utils/shared_files.h:60
Copy link
Member

Choose a reason for hiding this comment

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

Generally: please don't use this file to collect suppressions. If you need to add some suppression, please use an inline one.

But here: why it this necessary? It seems in that file in line 60 there is only a condition...

//

functionConst:src/utils/shared_files.h:60
useInitializationList:src/utils/shared_files.h:88
Copy link
Member

Choose a reason for hiding this comment

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

Similar here, but it seems that file only has 77 lines, so adding line 88 makes no sense.

@airween
Copy link
Member

airween commented May 6, 2025

Hi @akama-aka,

many thanks for this pull request, and special welcome to your first contribution!

I added some questions above, please review them.

And one more question - you wrote:

Implements the ability to reopen audit log files to ensure compatibility with Linux log rotation

Could you try this patch on Windows? I think the result is almost the same, but I'm curios how Windows handles the reopen() method. Do you have any idea how can we add a test case to check this method?

Cc: @eduar-hte (regarding to Windows).

And finally: I saw you added a "C" API function. I assume that will be used in Nginx to reopen audit.log files, right? Do you mind to add that feature to Nginx connector if we merge this?

@akama-aka
Copy link
Author

Hi @akama-aka,

many thanks for this pull request, and special welcome to your first contribution!

I added some questions above, please review them.

And one more question - you wrote:

Implements the ability to reopen audit log files to ensure compatibility with Linux log rotation

Could you try this patch on Windows? I think the result is almost the same, but I'm curios how Windows handles the reopen() method. Do you have any idea how can we add a test case to check this method?

Cc: @eduar-hte (regarding to Windows).

And finally: I saw you added a "C" API function. I assume that will be used in Nginx to reopen audit.log files, right? Do you mind to add that feature to Nginx connector if we merge this?

Thank you for your comment to this draft pr. I'll try to learn C/C++ more to understand more of it and try to fix those things up ^^

Copy link

sonarqubecloud bot commented Jun 2, 2025

@akama-aka akama-aka closed this Jun 25, 2025
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.

2 participants