File tree Expand file tree Collapse file tree 3 files changed +38
-1
lines changed Expand file tree Collapse file tree 3 files changed +38
-1
lines changed Original file line number Diff line number Diff line change @@ -40,6 +40,7 @@ class Parallel : public Writer {
4040 bool init (std::string *error) override ;
4141 bool write (Transaction *transaction, int parts,
4242 std::string *error) override ;
43+ bool reopen (std::string *error) override ;
4344
4445
4546 /* *
Original file line number Diff line number Diff line change @@ -325,6 +325,25 @@ extern "C" void msc_rules_error_cleanup(const char *error) {
325325 free ((void *) error);
326326}
327327
328+ extern " C" int msc_rules_reopen_audit_log (RulesSet *rules, const char **error) {
329+ bool succeeded = true ;
330+ std::string errorStr;
331+
332+ if (rules->m_auditLog != NULL ) {
333+ succeeded = rules->m_auditLog ->reopen (&errorStr);
334+ }
335+
336+ if (!succeeded) {
337+ if (!errorStr.empty ()) {
338+ *error = strdup (errorStr.c_str ());
339+ } else {
340+ // Guarantee an error message is always assigned in the event of a failure
341+ *error = strdup (" Unknown error reopening audit log" );
342+ }
343+ }
344+
345+ return succeeded ? 0 : -1 ;
346+ }
328347
329348extern " C" int msc_rules_cleanup (RulesSet *rules) {
330349 delete rules;
Original file line number Diff line number Diff line change 1414 */
1515
1616#include " src/utils/shared_files.h"
17-
17+ # include < cstring >
1818#include < fcntl.h>
1919#ifdef WIN32
2020#include < algorithm>
@@ -101,6 +101,23 @@ void SharedFiles::close(const std::string& fileName) {
101101 }
102102}
103103
104+ bool SharedFiles::reopen (const std::string& fileName, std::string *error) {
105+ auto it = m_handlers.find (fileName);
106+ if (it == m_handlers.end ()) {
107+ return open (fileName, error);
108+ }
109+
110+ FILE* new_fp = fopen (fileName.c_str (), " a+" );
111+ if (new_fp == nullptr ) {
112+ error->assign (" Failed to reopen file: " + fileName + " - " + strerror (errno));
113+ return false ;
114+ }
115+
116+ fclose (it->second .fp );
117+ it->second .fp = new_fp;
118+
119+ return true ;
120+ }
104121
105122bool SharedFiles::write (const std::string& fileName,
106123 const std::string &msg, std::string *error) {
You can’t perform that action at this time.
0 commit comments