Fix PgGetAccountEmails null verification and replace mutex signal from LeakLogSendThread 61/179261/11 accepted/tizen/unified/20180521.003556 submit/tizen/20180518.172923
authorSaulo Moraes <s.moraes@samsung.com>
Wed, 16 May 2018 16:26:01 +0000 (13:26 -0300)
committerSaulo Aldighieri Moraes <s.moraes@samsung.com>
Fri, 18 May 2018 16:40:09 +0000 (13:40 -0300)
Change-Id: I8918524cc928b17bcf696be9c20607f011a6ac48

client/inc/DlpLogsManager.h
client/src/DlpLogsManager.cpp
packaging/privacy-guard.spec
server/inc/DlpRuleChangeNotification.h
server/src/PrivacyGuardDb.cpp

index 93fa8c0..8b9b812 100644 (file)
@@ -28,6 +28,8 @@
 #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;
@@ -46,8 +48,6 @@ private:
        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();
index 86f5ff6..d05a731 100644 (file)
  */
 
 #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(&notify_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)
 {
@@ -75,12 +80,13 @@ DlpLogsManager::ParseAndLogLeak(const char *hostname, char *mem, size_t len, con
 
        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;
@@ -124,27 +130,24 @@ DlpLogsManager::LeakLogSendThread()
        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;
 }
index a472c63..814fd54 100644 (file)
@@ -1,5 +1,5 @@
 Name:           privacy-guard-server
-Version:        0.9.9
+Version:        0.9.10
 Release:        1
 License:        Apache-2.0
 Summary:        Privacy Management
index 028c6b4..3ac045c 100644 (file)
@@ -33,7 +33,6 @@ private:
        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);
index 6ca9edd..37048d0 100644 (file)
@@ -694,16 +694,16 @@ PrivacyGuardDb::PgForeachPrivacyCountByPrivacyId(const int userId, const int sta
 
        // 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));
@@ -2474,8 +2474,11 @@ PrivacyGuardDb::PgGetAccountEmails(const int userId, std::set<std::string> &emai
 
        // 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);