Removed usage of pthreads and replaced with std C++ features

- Replaced pthread_mutex_t in modsecurity::operators::Pm with std::mutex
- Replaced pthread's thread usage in reading_logs_via_rule_message
  example with std::thread.
  - Simplified and modernized C++ code.
- Removed unnecessary includes of pthread.h
This commit is contained in:
Eduardo Arias
2024-08-07 13:54:58 -07:00
parent 4e15f9ef71
commit 293cd214c7
12 changed files with 27 additions and 70 deletions

View File

@@ -25,8 +25,6 @@
#include <memory>
#endif
#include <pthread.h>
#include "modsecurity/variable_value.h"
#include "src/utils/regex.h"
#include "src/utils/string.h"

View File

@@ -27,8 +27,6 @@
#include <string>
#include <memory>
#include <pthread.h>
#include "modsecurity/variable_value.h"
#include "src/utils/regex.h"
#include "src/variables/variable.h"

View File

@@ -27,12 +27,10 @@
#ifdef WITH_LMDB
#include <lmdb.h>
#include <semaphore.h>
#endif // WITH_LMDB
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <pthread.h>
#include "modsecurity/variable_value.h"
#include "modsecurity/collection/collection.h"

View File

@@ -39,9 +39,6 @@ Pm::~Pm() {
free(m_p);
m_p = NULL;
#ifdef MODSEC_MUTEX_ON_PM
pthread_mutex_destroy(&m_lock);
#endif
}
@@ -89,11 +86,12 @@ bool Pm::evaluate(Transaction *transaction, RuleWithActions *rule,
pt.ptr = NULL;
const char *match = NULL;
#ifdef MODSEC_MUTEX_ON_PM
pthread_mutex_lock(&m_lock);
{
const std::lock_guard lock(m_mutex);
#endif
rc = acmp_process_quick(&pt, &match, input.c_str(), input.length());
#ifdef MODSEC_MUTEX_ON_PM
pthread_mutex_unlock(&m_lock);
}
#endif
if (rc >= 0 && transaction) {
@@ -118,9 +116,6 @@ bool Pm::init(const std::string &file, std::string *error) {
std::istringstream *iss;
const char *err = NULL;
#ifdef MODSEC_MUTEX_ON_PM
pthread_mutex_init(&m_lock, NULL);
#endif
char *content = parse_pm_content(m_param.c_str(), m_param.length(), &err);
if (content == NULL) {
iss = new std::istringstream(m_param);

View File

@@ -20,6 +20,7 @@
#include <list>
#include <memory>
#include <utility>
#include <mutex>
#include "src/operators/operator.h"
#include "src/utils/acmp.h"
@@ -56,7 +57,7 @@ class Pm : public Operator {
#ifdef MODSEC_MUTEX_ON_PM
private:
pthread_mutex_t m_lock;
std::mutex m_mutex;
#endif
};