#include "DlpPacketParser.h"
#include "DlpPacketParserResult.h"
#include "PrivacyGuardTypes.h"
+#include "PrivacyGuardDlp.h"
+#include "Utils.h"
typedef struct _leak_log_queue_entry_s {
std::string hostname;
static DlpLogsManager *m_pInstance;
std::list<leak_log_queue_entry_s> m_logQueue;
PrivacyGuardDlp *m_privacyGuardDlp;
- std::mutex m_logQueueMutex;
- std::mutex m_leakLogSendMutex;
DlpLogsManager();
~DlpLogsManager();
*/
#include "DlpLogsManager.h"
-#include "PrivacyGuardDlp.h"
-#include "Utils.h"
std::mutex DlpLogsManager::m_singletonMutex;
DlpLogsManager *DlpLogsManager::m_pInstance = NULL;
+pthread_cond_t pthread_cond = PTHREAD_COND_INITIALIZER;
+pthread_mutex_t pthread_mutex = PTHREAD_MUTEX_INITIALIZER;
+
DlpLogsManager::DlpLogsManager(void)
{
pthread_t notify_thread;
m_privacyGuardDlp = PrivacyGuardDlp::getInstance();
// launch leak log send thread
- m_leakLogSendMutex.lock();
if (pthread_create(¬ify_thread, NULL, LeakLogSendThreadFunc, this)) {
- m_leakLogSendMutex.unlock();
PG_LOGE("Error creating privacy guard leak log send thread");
}
}
+DlpLogsManager::~DlpLogsManager(void)
+{
+ //sem_destroy(&m_noLogSemaphore);
+ //sem_destroy(&m_logsSentSemaphore);
+}
+
DlpLogsManager*
DlpLogsManager::getInstance(void)
{
if (!entry.rlist.empty() || !entry.llist.empty()) {
// add entry to the m_logQueue to be processed when the thread awakes
- m_logQueueMutex.lock();
+ pthread_mutex_lock(&pthread_mutex);
+
m_logQueue.push_back(entry);
- m_logQueueMutex.unlock();
- // signal the leak log send thread
- m_leakLogSendMutex.unlock();
+ // semaphore signal to LeakLogSendThread
+ pthread_cond_signal(&pthread_cond);
+ pthread_mutex_unlock(&pthread_mutex);
}
return res;
uid_t pid = getpid();
uid_t uid = getuid();
- for (;;) {
- // wait for new entries on the queue
- m_leakLogSendMutex.lock();
+ while (TRUE) {
+ pthread_mutex_lock(&pthread_mutex);
+ // wait up the main thread (if it is sleeping) to test the value of done
+ pthread_cond_wait(&pthread_cond, &pthread_mutex);
// with new entries, try to process them
- m_logQueueMutex.lock();
for (auto it = m_logQueue.begin(); it != m_logQueue.end(); it++) {
- m_logQueueMutex.unlock();
// if packet has not been parsed yet, parse now
if (!it->rlist.empty())
ParseAndLogLeakNow(*it);
if (!it->llist.empty())
m_privacyGuardDlp->PgAddLeakLog(uid, pid, it->hostname.c_str(), it->mem, it->len, it->llist);
-
- m_logQueueMutex.lock();
}
// all entries processed, call clear destroying each element from queue
m_logQueue.clear();
- m_logQueueMutex.unlock();
+ pthread_mutex_unlock(&pthread_mutex);
}
return NULL;
}
Name: privacy-guard-server
-Version: 0.9.9
+Version: 0.9.10
Release: 1
License: Apache-2.0
Summary: Privacy Management
static std::mutex m_singletonMutex;
static DlpRuleChangeNotification* m_pInstance;
std::list<privacy_semaphore_s> m_semaphore_list;
- std::mutex m_semaphore_mutex;
public:
static DlpRuleChangeNotification *getInstance(void);
// bind
res = sqlite3_bind_int(m_stmt, 1, userId);
- TryReturn(res == SQLITE_OK, PRIV_GUARD_ERROR_DB_ERROR, , "sqlite3_bind_int : %d", res);
+ TryReturn(res == SQLITE_OK, PRIV_GUARD_ERROR_DB_ERROR, m_dbMutex.unlock(), "sqlite3_bind_int : %d", res);
res = sqlite3_bind_text(m_stmt, 2, privacyId.c_str(), -1, SQLITE_TRANSIENT);
- TryReturn(res == SQLITE_OK, PRIV_GUARD_ERROR_DB_ERROR, , "sqlite3_bind_text : %d", res);
+ TryReturn(res == SQLITE_OK, PRIV_GUARD_ERROR_DB_ERROR, m_dbMutex.unlock(), "sqlite3_bind_text : %d", res);
res = sqlite3_bind_int(m_stmt, 3, startDate);
- TryReturn(res == SQLITE_OK, PRIV_GUARD_ERROR_DB_ERROR, , "sqlite3_bind_int : %d", res);
+ TryReturn(res == SQLITE_OK, PRIV_GUARD_ERROR_DB_ERROR, m_dbMutex.unlock(), "sqlite3_bind_int : %d", res);
res = sqlite3_bind_int(m_stmt, 4, endDate);
- TryReturn(res == SQLITE_OK, PRIV_GUARD_ERROR_DB_ERROR, , "sqlite3_bind_int : %d", res);
+ TryReturn(res == SQLITE_OK, PRIV_GUARD_ERROR_DB_ERROR, m_dbMutex.unlock(), "sqlite3_bind_int : %d", res);
while ((res = sqlite3_step(m_stmt)) == SQLITE_ROW) {
const char* packageId = reinterpret_cast < const char* > (sqlite3_column_text(m_stmt, 0));
// step
while (sqlite3_step(stmt) == SQLITE_ROW) {
- std::string email((const char *)sqlite3_column_text(stmt, 0));
- emails.insert(email);
+ const char *email_value = (const char *)sqlite3_column_text(stmt, 0);
+ if (email_value && strlen(email_value)) {
+ std::string email(email_value);
+ emails.insert(email);
+ }
}
sqlite3_finalize(stmt);