File tree 3 files changed +38
-1
lines changed
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 {
40
40
bool init (std::string *error) override ;
41
41
bool write (Transaction *transaction, int parts,
42
42
std::string *error) override ;
43
+ bool reopen (std::string *error) override ;
43
44
44
45
45
46
/* *
Original file line number Diff line number Diff line change @@ -325,6 +325,25 @@ extern "C" void msc_rules_error_cleanup(const char *error) {
325
325
free ((void *) error);
326
326
}
327
327
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
+ }
328
347
329
348
extern " C" int msc_rules_cleanup (RulesSet *rules) {
330
349
delete rules;
Original file line number Diff line number Diff line change 14
14
*/
15
15
16
16
#include " src/utils/shared_files.h"
17
-
17
+ # include < cstring >
18
18
#include < fcntl.h>
19
19
#ifdef WIN32
20
20
#include < algorithm>
@@ -101,6 +101,23 @@ void SharedFiles::close(const std::string& fileName) {
101
101
}
102
102
}
103
103
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
+ }
104
121
105
122
bool SharedFiles::write (const std::string& fileName,
106
123
const std::string &msg, std::string *error) {
You can’t perform that action at this time.
0 commit comments