File backups on seperate partition; Fixed bug 146; created performance benchmark...
authorIngo Huerner <ingo.huerner@xse.de>
Fri, 24 Jan 2014 13:33:15 +0000 (14:33 +0100)
committerIngo Huerner <ingo.huerner@xse.de>
Fri, 24 Jan 2014 13:33:15 +0000 (14:33 +0100)
21 files changed:
configure.ac
include_protected/persistence_client_library_data_organization.h
include_protected/persistence_client_library_db_access.h
src/persistence_client_library.c
src/persistence_client_library_backup_filelist.c
src/persistence_client_library_backup_filelist.h
src/persistence_client_library_custom_loader.h
src/persistence_client_library_data_organization.c
src/persistence_client_library_db_access.c
src/persistence_client_library_dbus_cmd.c
src/persistence_client_library_dbus_service.c
src/persistence_client_library_file.c
src/persistence_client_library_key.c
src/persistence_client_library_prct_access.c
src/persistence_client_library_prct_access.h
test/Makefile.am
test/data/Data.tar.gz
test/persistence_admin_service_mockup.c
test/persistence_client_library_benchmark.c [new file with mode: 0644]
test/persistence_client_library_test.c
test/persistence_lifeCycle_mockup.c

index 27f7587..03af087 100644 (file)
@@ -96,6 +96,26 @@ AC_MSG_NOTICE([Tests enabled: $enable_tests])
 AC_MSG_NOTICE([Local check enabled: $localcheck])
 
 
+# enable persistence administration service dbus interface ###########
+AC_ARG_ENABLE([pasinterface],
+            [AS_HELP_STRING([--enable-pasinterface],[Enable pas interface])],
+            [use_pasinterface=$enableval],
+            [use_pasinterface="no"])
+
+AM_CONDITIONAL([USE_PASINTERFACE], [test x"$use_pasinterface" = "no"])
+
+if test "$use_pasinterface" != "yes" -a "$use_pasinterface" != "no"; then
+   AC_MSG_ERROR([Invalid pas interface check mode specified: $use_pasinterface. Only "yes" or "no" is valid])
+else   
+   AC_MSG_NOTICE([Use pas interface check is: $use_pasinterface])
+
+   if test "$use_pasinterface" = "yes"; then
+      AC_DEFINE_UNQUOTED([USE_PASINTERFACE], [1], [pasinterface enabled])   
+   fi
+fi
+######################################################################
+
+
 AC_ARG_ENABLE(debug,
 AS_HELP_STRING([--enable-debug],
                [enable debugging, default: no]),
index 2e6842c..17fa9f7 100644 (file)
@@ -124,6 +124,10 @@ extern const char* gUser;
 /// directory structure seat name defintion
 extern const char* gSeat;
 
+extern const char* gBackupPrefix;
+
+extern const int gCPathPrefixSize;
+extern const int gWTPathPrefixSize;
 
 /// path prefix for local cached database: /Data/mnt_c/<appId>/<database_name>
 extern const char* gLocalCachePath;
index feb7a8d..3c560f6 100644 (file)
@@ -107,6 +107,11 @@ void pers_db_close(PersistenceInfo_s* info);
 void pers_db_close_all();
 
 
+/**
+ * @brief close all rct's
+ */
+void pers_rct_close_all();
+
 
 /**
  * @brief register or unregister for change notifications of a key
index ac1c830..34c13ac 100644 (file)
@@ -66,6 +66,15 @@ int pclInitLibrary(const char* appName, int shutdownMode)
       /// blacklist path environment variable
       const char *pBlacklistPath = getenv("PERS_BLACKLIST_PATH");
 
+#if USE_PASINTERFACE == 1
+      //printf("* ADMIN INTERFACE is  - e n a b l e d - \n");
+      DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("PAS interface is enabled!!"));
+#else
+      //printf("* ADMIN INTERFACE is  - d i s a b l e d - enable with \"./configure --enable-pasinterface\"\n");
+      DLT_LOG(gDLTContext, DLT_LOG_WARN, DLT_STRING("PAS interface is not enabled, enable with \"./configure --enable-pasinterface\""));
+#endif
+
+
       pthread_mutex_lock(&gDbusPendingRegMtx);   // block until pending received
 
       if(pDataSize != NULL)
@@ -90,6 +99,7 @@ int pclInitLibrary(const char* appName, int shutdownMode)
          return EPERS_DBUS_MAINLOOP;
       }
 
+
       if(gShutdownMode != PCL_SHUTDOWN_TYPE_NONE)
       {
          // register for lifecycle and persistence admin service dbus messages
@@ -100,13 +110,14 @@ int pclInitLibrary(const char* appName, int shutdownMode)
             return EPERS_REGISTER_LIFECYCLE;
          }
       }
-
+#if USE_PASINTERFACE == 1
       if(register_pers_admin_service() == -1)
       {
          DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pclInitLibrary => Failed to register to pers admin dbus interface"));
          pthread_mutex_unlock(&gDbusPendingRegMtx);
          return EPERS_REGISTER_ADMIN;
       }
+#endif
 
       /// get custom library names to load
       status = get_custom_libraries();
@@ -186,12 +197,13 @@ int pclDeinitLibrary(void)
    {
       DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclDeinitLibrary -> D E I N I T  client library - "), DLT_STRING(gAppId),
                                          DLT_STRING("- init counter: "), DLT_INT(gPclInitialized));
-
       // unregister for lifecycle and persistence admin service dbus messages
       if(gShutdownMode != PCL_SHUTDOWN_TYPE_NONE)
          rval = unregister_lifecycle(gShutdownMode);
 
+#if USE_PASINTERFACE == 1
       rval = unregister_pers_admin_service();
+#endif
 
       // unload custom client libraries
       for(i=0; i<PersCustomLib_LastEntry; i++)
@@ -207,6 +219,12 @@ int pclDeinitLibrary(void)
          }
       }
 
+      // close all apend rct
+      pers_rct_close_all();
+
+      // close opend database
+      pers_db_close_all();
+
       gPclInitialized = PCLnotInitialized;
 
       DLT_UNREGISTER_CONTEXT(gDLTContext);
index 24cf12b..168f30c 100644 (file)
@@ -17,6 +17,7 @@
  */
 
 #include "persistence_client_library_backup_filelist.h"
+#include "persistence_client_library_handle.h"
 #include "rbtree.h"
 #include "../include_protected/crc32.h"
 #include "../include_protected/persistence_client_library_data_organization.h"
@@ -317,3 +318,459 @@ void  key_val_rel(void *p )
 }
 
 
+int pclCreateFile(const char* path)
+{
+   const char* delimiters = "/\n";   // search for blank and end of line
+   char* tokenArray[24];
+   char* thePath = (char*)path;
+   int numTokens = 0, i = 0, validPath = 1;
+   int handle = 0;
+
+   tokenArray[numTokens++] = strtok(thePath, delimiters);
+   while(tokenArray[numTokens-1] != NULL )
+   {
+     tokenArray[numTokens] = strtok(NULL, delimiters);
+     if(tokenArray[numTokens] != NULL)
+     {
+        numTokens++;
+        if(numTokens >= 24)
+        {
+           validPath = 0;
+           break;
+        }
+     }
+     else
+     {
+        break;
+     }
+   }
+
+   if(validPath == 1)
+   {
+      char createPath[DbPathMaxLen] = {0};
+      snprintf(createPath, DbPathMaxLen, "/%s",tokenArray[0] );
+      for(i=1; i<numTokens-1; i++)
+      {
+         // create folders
+         strncat(createPath, "/", DbPathMaxLen-1);
+         strncat(createPath, tokenArray[i], DbPathMaxLen-1);
+         mkdir(createPath, 0744);
+      }
+      // finally create the file
+      strncat(createPath, "/", DbPathMaxLen-1);
+      strncat(createPath, tokenArray[i], DbPathMaxLen-1);
+      handle = open(createPath, O_CREAT|O_RDWR |O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
+      if(handle != -1)
+      {
+         if(handle < MaxPersHandle)
+         {
+            __sync_fetch_and_add(&gOpenFdArray[handle], FileOpen); // set open flag
+         }
+         else
+         {
+            close(handle);
+            handle = EPERS_MAXHANDLE;
+         }
+      }
+   }
+   else
+   {
+      DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pclCreateFile ==> no valid path to create: "), DLT_STRING(path) );
+   }
+
+   return handle;
+}
+
+
+int pclVerifyConsistency(const char* origPath, const char* backupPath, const char* csumPath, int openFlags)
+{
+   int handle = 0, readSize = 0;
+   int backupAvail = 0, csumAvail = 0;
+   int fdCsum = 0, fdBackup = 0;
+
+   char origCsumBuf[ChecksumBufSize] = {0};
+   char backCsumBuf[ChecksumBufSize] = {0};
+   char csumBuf[ChecksumBufSize]     = {0};
+
+   // check if we have a backup and checksum file
+   backupAvail = access(backupPath, F_OK);
+   csumAvail   = access(csumPath, F_OK);
+
+   // *************************************************
+   // there is a backup file and a checksum
+   // *************************************************
+   if( (backupAvail == 0) && (csumAvail == 0) )
+   {
+      DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclVerifyConsistency => there is a backup file AND a checksum"));
+      // calculate checksum form backup file
+      fdBackup = open(backupPath,  O_RDONLY);
+      if(fdBackup != -1)
+      {
+         pclCalcCrc32Csum(fdBackup, backCsumBuf);
+
+         fdCsum = open(csumPath,  O_RDONLY);
+         if(fdCsum != -1)
+         {
+            readSize = read(fdCsum, csumBuf, ChecksumBufSize);
+            if(readSize > 0)
+            {
+               if(strcmp(csumBuf, backCsumBuf)  == 0)
+               {
+                  // checksum matches ==> replace with original file
+                  handle = pclRecoverFromBackup(fdBackup, origPath);
+               }
+               else
+               {
+                  // checksum does not match, check checksum with original file
+                  handle = open(origPath, openFlags);
+                  if(handle != -1)
+                  {
+                     pclCalcCrc32Csum(handle, origCsumBuf);
+                     if(strcmp(csumBuf, origCsumBuf)  != 0)
+                     {
+                        close(handle);
+                        handle = -1;  // error: file corrupt
+                     }
+                     // else case: checksum matches ==> keep original file ==> nothing to do
+
+                  }
+                  else
+                  {
+                     close(handle);
+                     handle = -1;     // error: file corrupt
+                  }
+               }
+            }
+            close(fdCsum);
+         }
+         else
+         {
+            close(fdCsum);
+            handle = -1;     // error: file corrupt
+         }
+      }
+      else
+      {
+         handle = -1;
+      }
+      close(fdBackup);
+   }
+   // *************************************************
+   // there is ONLY a checksum file
+   // *************************************************
+   else if(csumAvail == 0)
+   {
+      DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclVerifyConsistency => there is ONLY a checksum file"));
+
+      fdCsum = open(csumPath,  O_RDONLY);
+      if(fdCsum != -1)
+      {
+         readSize = read(fdCsum, csumBuf, ChecksumBufSize);
+         if(readSize <= 0)
+         {
+            DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pclVerifyConsistency => read checksum: invalid readSize"));
+         }
+         close(fdCsum);
+
+         // calculate the checksum form the original file to see if it matches
+         handle = open(origPath, openFlags);
+         if(handle != -1)
+         {
+            pclCalcCrc32Csum(handle, origCsumBuf);
+
+            if(strcmp(csumBuf, origCsumBuf)  != 0)
+            {
+                close(handle);
+                handle = -1;  // checksum does NOT match ==> error: file corrupt
+            }
+            // else case: checksum matches ==> keep original file ==> nothing to do
+         }
+         else
+         {
+            close(handle);
+            handle = -1;      // error: file corrupt
+         }
+      }
+      else
+      {
+         close(fdCsum);
+         handle = -1;         // error: file corrupt
+      }
+   }
+   // *************************************************
+   // there is ONLY a backup file
+   // *************************************************
+   else if(backupAvail == 0)
+   {
+      DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclVerifyConsistency => there is ONLY a backup file"));
+
+      // calculate checksum form backup file
+      fdBackup = open(backupPath,  O_RDONLY);
+      if(fdBackup != -1)
+      {
+         pclCalcCrc32Csum(fdBackup, backCsumBuf);
+         close(fdBackup);
+
+         // calculate the checksum form the original file to see if it matches
+         handle = open(origPath, openFlags);
+         if(handle != -1)
+         {
+            pclCalcCrc32Csum(handle, origCsumBuf);
+
+            if(strcmp(backCsumBuf, origCsumBuf)  != 0)
+            {
+               close(handle);
+               handle = -1;   // checksum does NOT match ==> error: file corrupt
+            }
+            // else case: checksum matches ==> keep original file ==> nothing to do
+
+         }
+         else
+         {
+            close(handle);
+            handle = -1;      // error: file corrupt
+         }
+      }
+      else
+      {
+         close(fdBackup);
+         handle = -1;         // error: file corrupt
+      }
+   }
+   // for else case: nothing to do
+
+
+   // if we are in an inconsistent state: delete file, backup and checksum
+   if(handle == -1)
+   {
+      remove(origPath);
+      remove(backupPath);
+      remove(csumPath);
+   }
+
+   return handle;
+}
+
+
+
+int pclRecoverFromBackup(int backupFd, const char* original)
+{
+   int handle = 0;
+   int readSize = 0;
+   char buffer[RDRWBufferSize];
+
+   handle = open(original, O_TRUNC | O_RDWR);
+   if(handle != -1)
+   {
+      // copy data from one file to another
+      while((readSize = read(backupFd, buffer, RDRWBufferSize)) > 0)
+      {
+         if(write(handle, buffer, readSize) != readSize)
+         {
+            DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pclRecoverFromBackup => couldn't write whole buffer"));
+            break;
+         }
+      }
+
+   }
+
+   return handle;
+}
+
+
+
+int pclCreateBackup(const char* dstPath, int srcfd, const char* csumPath, const char* csumBuf)
+{
+   int dstFd = 0, csfd = 0;
+   int readSize = -1;
+   char buffer[RDRWBufferSize];
+
+   if(access(dstPath, F_OK) != 0)
+   {
+      char pathToCreate[DbPathMaxLen] = {0};
+      strncpy(pathToCreate, dstPath, DbPathMaxLen);
+      pclCreateFileAndPath(pathToCreate);
+   }
+
+   // create checksum file and and write checksum
+   csfd = open(csumPath, O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
+   if(csfd != -1)
+   {
+      int csumSize = strlen(csumBuf);
+      if(write(csfd, csumBuf, csumSize) != csumSize)
+      {
+         DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pclCreateBackup => failed to write checksum to file"));
+      }
+      close(csfd);
+   }
+   else
+   {
+      DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pclCreateBackup => failed to create checksum file:"), DLT_STRING(strerror(errno)) );
+   }
+
+   // create backup file, user and group has read/write permission, others have read permission
+   dstFd = open(dstPath, O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
+   if(dstFd != -1)
+   {
+      off_t curPos = 0;
+      // remember the current position
+      curPos = lseek(srcfd, 0, SEEK_CUR);
+
+      // copy data from one file to another
+      while((readSize = read(srcfd, buffer, RDRWBufferSize)) > 0)
+      {
+         if(write(dstFd, buffer, readSize) != readSize)
+         {
+            DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pclCreateBackup => couldn't write whole buffer"));
+            break;
+         }
+      }
+
+      if(readSize == -1)
+         DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pcl_create_backup => error copying file"));
+
+      if((readSize = close(dstFd)) == -1)
+         DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pcl_create_backup => error closing fd"));
+
+      // set back to the position
+      lseek(srcfd, curPos, SEEK_SET);
+   }
+   else
+   {
+      DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pclCreateBackup => failed to open backup file"),
+                                          DLT_STRING(dstPath), DLT_STRING(strerror(errno)));
+   }
+
+   return readSize;
+}
+
+
+
+int pclCalcCrc32Csum(int fd, char crc32sum[])
+{
+   int rval = 1;
+
+   if(crc32sum != 0)
+   {
+      char* buf;
+      struct stat statBuf;
+
+      fstat(fd, &statBuf);
+      buf = malloc((unsigned int)statBuf.st_size);
+
+      if(buf != 0)
+      {
+         off_t curPos = 0;
+         // remember the current position
+         curPos = lseek(fd, 0, SEEK_CUR);
+
+         if(curPos != 0)
+         {
+            // set to beginning of the file
+            lseek(fd, 0, SEEK_SET);
+         }
+
+         while((rval = read(fd, buf, statBuf.st_size)) > 0)
+         {
+            unsigned int crc = 0;
+            crc = pclCrc32(crc, (unsigned char*)buf, statBuf.st_size);
+            snprintf(crc32sum, ChecksumBufSize-1, "%x", crc);
+         }
+
+         // set back to the position
+         lseek(fd, curPos, SEEK_SET);
+
+         free(buf);
+      }
+   }
+   return rval;
+}
+
+
+
+int pclBackupNeeded(const char* path)
+{
+   return need_backup_key(pclCrc32(0, (const unsigned char*)path, strlen(path)));
+}
+
+
+
+int pclCreateFileAndPath(const char* path)
+{
+   const char* delimiters = "/\n";   // search for blank and end of line
+   char* tokenArray[24];
+   char* thePath = (char*)path;
+   char createPath[DbPathMaxLen] = {0};
+   int numTokens = 0, i = 0, validPath = 1;
+   int rval = -1;
+
+   tokenArray[numTokens++] = strtok(thePath, delimiters);
+   while(tokenArray[numTokens-1] != NULL )
+   {
+     tokenArray[numTokens] = strtok(NULL, delimiters);
+     if(tokenArray[numTokens] != NULL)
+     {
+        numTokens++;
+        if(numTokens >= 24)
+        {
+           validPath = 0;
+           break;
+        }
+     }
+     else
+     {
+        break;
+     }
+   }
+
+   if(validPath == 1)
+   {
+      snprintf(createPath, DbPathMaxLen, "/%s",tokenArray[0] );
+      for(i=1; i<numTokens-1; i++)
+      {
+         // create folders
+         strncat(createPath, "/", DbPathMaxLen-1);
+         strncat(createPath, tokenArray[i], DbPathMaxLen-1);
+         mkdir(createPath, 0744);
+      }
+      // finally create the file
+      strncat(createPath, "/", DbPathMaxLen-1);
+      strncat(createPath, tokenArray[i], DbPathMaxLen-1);
+      rval = open(createPath, O_CREAT|O_RDWR |O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
+      close(rval);
+   }
+   else
+   {
+      DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pclCreateFileAndPath ==> no valid path to create:"), DLT_STRING(path));
+   }
+
+   return rval;
+}
+
+
+
+int pclGetPosixPermission(PersistencePermission_e permission)
+{
+   int posixPerm = 0;
+
+   switch( (int)permission)
+   {
+   case PersistencePermission_ReadWrite:
+      posixPerm = O_RDWR;
+      break;
+   case PersistencePermission_ReadOnly:
+      posixPerm = O_RDONLY;
+      break;
+   case PersistencePermission_WriteOnly:
+      posixPerm = O_WRONLY;
+      break;
+   default:
+      posixPerm = O_RDONLY;
+      break;
+   }
+
+   return posixPerm;
+}
+
+
+
index d89181d..65a6a3c 100644 (file)
 int readBlacklistConfigFile(const char* filename);
 
 
+/**
+ * @brief
+ *
+ * @param
+ *
+ * @return
+ */
 int need_backup_key(unsigned int key);
 
 
+/**
+ * @brief create the file
+ *
+ * @param
+ *
+ * @return
+ */
+int pclCreateFile(const char* path);
+
+
+/**
+ * @brief create a backup of a file
+ *
+ * @param
+ *
+ * @return
+ */
+int pclCreateBackup(const char* srcPath, int srcfd, const char* csumPath, const char* csumBuf);
+
+
+/**
+ * @brief recover file form backup
+ *
+ * @param
+ *
+ * @return
+ */
+int pclRecoverFromBackup(int backupFd, const char* original);
+
+
+/**
+ * @brief calculate crc32 checksum
+ *
+ * @param
+ *
+ * @return
+ */
+int pclCalcCrc32Csum(int fd, char crc32sum[]);
+
+
+/**
+ * @brief verify file for consistency
+ *
+ * @param
+ *
+ * @return
+ */
+int pclVerifyConsistency(const char* origPath, const char* backupPath, const char* csumPath, int openFlags);
+
+
+/**
+ * @brief check if file needs to be backuped
+ *
+ * @param
+ *
+ * @return
+ */
+inline int pclBackupNeeded(const char* path);
+
+
+
 #endif /* PERS_BACKUP_BLACKLIST_H */
index b1b90fe..ff92fcd 100644 (file)
@@ -158,7 +158,7 @@ int load_all_custom_libraries();
  *
  * @return the array position or -1 if the position can't be found
  */
-int check_valid_idx(int idx);
+inline int check_valid_idx(int idx);
 
 
 
@@ -167,7 +167,7 @@ int check_valid_idx(int idx);
  *
  * @return the name of the custom library ot NULL if invalid
  */
-char* get_custom_client_lib_name(int idx);
+inline char* get_custom_client_lib_name(int idx);
 
 
 /**
index 73d45cf..12d5eea 100644 (file)
@@ -45,34 +45,47 @@ const char* gUser = "/user/";
 const char* gSeat = "/seat/";
 
 
+/// cached path location
+#define CACHEPREFIX         "/Data/mnt-c/"
+/// write through path location
+#define WTPREFIX            "/Data/mnt-wt/"
+
+/// size of cached path string
+const int gCPathPrefixSize = sizeof(CACHEPREFIX)-1;
+/// size of write through string
+const int gWTPathPrefixSize = sizeof(WTPREFIX)-1;
+
+/// path for the backup location
+const char* gBackupPrefix = "/Data/mnt-backup/";
+
 /// path prefix for local cached database: /Data/mnt_c/<appId>/ (<database_name>
-const char* gLocalCachePath        = "/Data/mnt-c/%s";
+const char* gLocalCachePath        = CACHEPREFIX "%s";
 /// path prefix for local write through database /Data/mnt_wt/<appId>/<database_name>
-const char* gLocalWtPath           = "/Data/mnt-wt/%s";
+const char* gLocalWtPath           = WTPREFIX "%s";
 /// path prefix for shared cached database: /Data/mnt_c/Shared/Group/<group_no>/<database_name>
-const char* gSharedCachePath       = "/Data/mnt-c/%s/Shared_Group_%x";
+const char* gSharedCachePath       = CACHEPREFIX "%s/Shared_Group_%x";
 /// path prefix for shared write through database: /Data/mnt_wt/Shared/Group/<group_no>/<database_name>
-const char* gSharedWtPath          = "/Data/mnt-wt/%s/Shared_Group_%x";
+const char* gSharedWtPath          = WTPREFIX "%s/Shared_Group_%x";
 /// path prefix for shared public cached database: /Data/mnt_c/Shared/Public//<database_name>
-const char* gSharedPublicCachePath = "/Data/mnt-c/%s/Shared_Public";
+const char* gSharedPublicCachePath = CACHEPREFIX "%s/Shared_Public";
 /// path prefix for shared public write through database: /Data/mnt_wt/Shared/Public/<database_name>
-const char* gSharedPublicWtPath    = "/Data/mnt-wt/%s/Shared_Public";
+const char* gSharedPublicWtPath    = WTPREFIX "%s/Shared_Public";
 
 /// path prefix for local cached database: /Data/mnt_c/<appId>/ (<database_name>
-const char* gLocalCachePathKey        = "/Data/mnt-c/%s%s";
+const char* gLocalCachePathKey        = CACHEPREFIX "%s%s";
 /// path prefix for local write through database /Data/mnt_wt/<appId>/<database_name>
-const char* gLocalWtPathKey           = "/Data/mnt-wt/%s%s";
+const char* gLocalWtPathKey           = WTPREFIX "%s%s";
 /// path prefix for shared cached database: /Data/mnt_c/Shared/Group/<group_no>/<database_name>
-const char* gSharedCachePathKey       = "/Data/mnt-c/%s/Shared_Group_%x%s";
+const char* gSharedCachePathKey       = CACHEPREFIX "%s/Shared_Group_%x%s";
 /// path prefix for shared write through database: /Data/mnt_wt/Shared/Group/<group_no>/<database_name>
-const char* gSharedWtPathKey          = "/Data/mnt-wt/%s/Shared_Group_%x%s";
+const char* gSharedWtPathKey          = WTPREFIX "%s/Shared_Group_%x%s";
 /// path prefix for shared public cached database: /Data/mnt_c/Shared/Public//<database_name>
-const char* gSharedPublicCachePathKey = "/Data/mnt-c/%s/Shared_Public%s";
+const char* gSharedPublicCachePathKey = CACHEPREFIX "%s/Shared_Public%s";
 /// path prefix for shared public write through database: /Data/mnt_wt/Shared/Public/<database_name>
-const char* gSharedPublicWtPathKey    = "/Data/mnt-wt/%s/Shared_Public%s";
+const char* gSharedPublicWtPathKey    = WTPREFIX "%s/Shared_Public%s";
 
 /// path prefix for local cached files: /Data/mnt_c/<appId>/<user>/<seat>/<resource>
-const char* gLocalCacheFilePath        = "/Data/mnt-c/%s/user/%d/seat/%d/%s";
+const char* gLocalCacheFilePath        = CACHEPREFIX "%s/user/%d/seat/%d/%s";
 
 
 const char* gChangeSignal = "PersistenceResChange";
index e974198..8c10ae9 100644 (file)
@@ -209,6 +209,29 @@ void pers_db_close_all()
 }
 
 
+void pers_rct_close_all()
+{
+   int i = 0;
+   itzam_btree* resourceTable = NULL;
+   itzam_state  state = ITZAM_FAILED;
+
+   // close open persistence resource configuration table
+   for(i=0; i< PrctDbTableSize; i++)
+   {
+      resourceTable = (itzam_btree*)get_resource_cfg_table_by_idx(i);
+      // dereference opend database
+      if(resourceTable != NULL &&  get_resource_cfg_table_status(i) == 1)
+      {
+         state = itzam_btree_close(resourceTable);
+         invalidate_resource_cfg_table(i);
+         if (state != ITZAM_OKAY)
+         {
+            DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("process_prepare_shutdown => itzam_btree_close: Itzam problem"), DLT_STRING(STATE_MESSAGES[state]));
+         }
+      }
+   }
+}
+
 int pers_db_read_key(char* dbPath, char* key, PersistenceInfo_s* info, unsigned char* buffer, unsigned int buffer_size)
 {
    int read_size = -1;
@@ -766,7 +789,8 @@ int pers_db_cursor_create(char* dbPath)
 
 int pers_db_cursor_next(unsigned int handlerDB)
 {
-   int rval = -1;
+   int rval = -99;
+
    //if(handlerDB < MaxPersHandle && handlerDB >= 0)
    if(handlerDB < MaxPersHandle )
    {
@@ -786,11 +810,13 @@ int pers_db_cursor_next(unsigned int handlerDB)
       }
       else
       {
+         printf("Invalid handle\n");
          DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pers_db_cursor_next ==> invalid handle: "), DLT_INT(handlerDB));
       }
    }
    else
    {
+      printf("Handle bigger than max\n");
       DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pers_db_cursor_next ==> handle bigger than max:"), DLT_INT(MaxPersHandle));
    }
    return rval;
index c3f69af..b9a99b4 100644 (file)
@@ -170,8 +170,6 @@ void process_block_and_write_data_back(unsigned int requestID, unsigned int stat
 void process_prepare_shutdown(unsigned char requestId, unsigned int status)
 {
    int i = 0;
-   itzam_btree* resourceTable = NULL;
-   itzam_state  state = ITZAM_FAILED;
 
    // block write
    pers_lock_access();
@@ -187,23 +185,10 @@ void process_prepare_shutdown(unsigned char requestId, unsigned int status)
       }
    }
 
-   // close open gvdb persistence resource configuration table
-   for(i=0; i< PrctDbTableSize; i++)
-   {
-     resourceTable = get_resource_cfg_table_by_idx(i);
-     // dereference opend database
-     if(resourceTable != NULL &&  get_resource_cfg_table_status(i) == 1)
-     {
-        state = itzam_btree_close(resourceTable);
-        invalidate_resource_cfg_table(i);
-        if (state != ITZAM_OKAY)
-        {
-           DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("process_prepare_shutdown => itzam_btree_close: Itzam problem"), DLT_STRING(STATE_MESSAGES[state]));
-        }
-     }
-   }
+   // close all opend rct
+   pers_rct_close_all();
 
-   //close opend database
+   // close opend database
    pers_db_close_all();
 
 
@@ -305,7 +290,7 @@ void process_send_pas_register(DBusConnection* conn, int regType, int notificati
 
             if(!dbus_pending_call_set_notify(pending, msg_pending_func, method, NULL))
             {
-               printf("process_send_pas_register => dbus_pending_call_set_notify: FAILED\n");
+               DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("process_send_pas_register => dbus_pending_call_set_notify: FAILED\n") );
             }
             dbus_pending_call_unref(pending);
          }
index 486b04a..ae45186 100644 (file)
@@ -243,6 +243,8 @@ void* run_mainloop(void* dataPtr)
    // setup the dbus
    mainLoop(vtablePersAdmin, vtableLifecycle, vtableFallback, dataPtr);
 
+   printf("<== run_mainloop\n");
+
    return NULL;
 }
 
@@ -501,8 +503,10 @@ int mainLoop(DBusObjectPathVTable vtable, DBusObjectPathVTable vtable2,
          dbus_bus_add_match(conn, "type='signal',interface='org.genivi.persistence.admin',member='PersistenceModeChanged',path='/org/genivi/persistence/admin'", &err);
 
          // register for messages
-         if (   (TRUE==dbus_connection_register_object_path(conn, "/org/genivi/persistence/adminconsumer", &vtable, userData))
-             && (TRUE==dbus_connection_register_object_path(conn, "/org/genivi/NodeStateManager/LifeCycleConsumer", &vtable2, userData))
+         if (   (TRUE==dbus_connection_register_object_path(conn, "/org/genivi/NodeStateManager/LifeCycleConsumer", &vtable2, userData))
+#if USE_PASINTERFACE == 1
+             && (TRUE==dbus_connection_register_object_path(conn, "/org/genivi/persistence/adminconsumer", &vtable, userData))
+#endif
              && (TRUE==dbus_connection_register_fallback(conn, "/", &vtableFallback, userData)) )
          {
             if(   (TRUE!=dbus_connection_set_watch_functions(conn, addWatch, removeWatch, watchToggled, NULL, NULL))
@@ -593,7 +597,7 @@ int mainLoop(DBusObjectPathVTable vtable, DBusObjectPathVTable vtable2,
                                           process_send_lifecycle_register(conn, (buf[1]), buf[2]);
                                           break;
                                        case CMD_QUIT:
-                                          bContinue = FALSE;
+                                          bContinue = 0;
                                           break;
 
                                        // ******************************************************
@@ -643,7 +647,9 @@ int mainLoop(DBusObjectPathVTable vtable, DBusObjectPathVTable vtable2,
                }
                while (0!=bContinue);
             }
+#if USE_PASINTERFACE == 1
             dbus_connection_unregister_object_path(conn, "/org/genivi/persistence/adminconsumer");
+#endif
             dbus_connection_unregister_object_path(conn, "/org/genivi/NodeStateManager/LifeCycleConsumer");
             dbus_connection_unregister_object_path(conn, "/");
          }
@@ -656,6 +662,7 @@ int mainLoop(DBusObjectPathVTable vtable, DBusObjectPathVTable vtable2,
 
    pthread_cond_signal(&gDbusInitializedCond);
    pthread_mutex_unlock(&gDbusInitializedMtx);
+   printf("End Mainloop\n");
    return 0;
 }
 
index fea9c68..d73fe12 100644 (file)
 #include <stdlib.h>
 
 
-// header prototype definition of internal functions
-int pclCreateFile(const char* path);
-
-int pclCreateBackup(const char* srcPath, int srcfd, const char* csumPath, const char* csumBuf);
-
-int pclRecoverFromBackup(int backupFd, const char* original);
-
-int pclCalcCrc32Csum(int fd, char crc32sum[]);
-
-int pclVerifyConsistency(const char* origPath, const char* backupPath, const char* csumPath, int openFlags);
-
-int pclBackupNeeded(const char* path);
-//-------------------------------------------------------------
-
-
 
 int pclFileClose(int fd)
 {
@@ -160,6 +145,23 @@ int pclFileOpen(unsigned int ldbid, const char* resource_id, unsigned int user_n
 
       if(dbContext.configKey.type == PersistenceResourceType_file)   // check if the resource is really a file
       {
+         // create backup path
+         int length = 0;
+         char fileSubPath[DbPathMaxLen] = {0};
+
+         if(dbContext.configKey.policy ==  PersistencePolicy_wc)
+         {
+            length = gCPathPrefixSize;
+         }
+         else
+         {
+            length = gWTPathPrefixSize;
+         }
+
+         strncpy(fileSubPath, dbPath+length, DbPathMaxLen);
+         snprintf(backupPath, DbPathMaxLen, "%s%s", gBackupPrefix, fileSubPath);
+         snprintf(csumPath,   DbPathMaxLen, "%s%s%s", gBackupPrefix, fileSubPath, ".crc");
+
          if(shared_DB >= 0)                                          // check valid database context
          {
             int flags = pclGetPosixPermission(dbContext.configKey.permission);
@@ -168,9 +170,6 @@ int pclFileOpen(unsigned int ldbid, const char* resource_id, unsigned int user_n
             if( (dbContext.configKey.permission != PersistencePermission_ReadOnly)
                && pclBackupNeeded(dbPath) )
             {
-               snprintf(backupPath, DbPathMaxLen, "%s%s", dbPath, "~");
-               snprintf(csumPath,   DbPathMaxLen, "%s%s", dbPath, "~.crc");
-
                if((handle = pclVerifyConsistency(dbPath, backupPath, csumPath, flags)) == -1)
                {
                   DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pclFileOpen: error => file inconsistent, recovery  N O T  possible!"));
@@ -194,7 +193,6 @@ int pclFileOpen(unsigned int ldbid, const char* resource_id, unsigned int user_n
                   {
                      strcpy(gFileHandleArray[handle].backupPath, backupPath);
                      strcpy(gFileHandleArray[handle].csumPath,   csumPath);
-
                      gFileHandleArray[handle].backupCreated = 0;
                      gFileHandleArray[handle].permission = dbContext.configKey.permission;
                   }
@@ -220,10 +218,8 @@ int pclFileOpen(unsigned int ldbid, const char* resource_id, unsigned int user_n
             {
                if(handle < MaxPersHandle)
                {
-                  snprintf(backupPath, DbPathMaxLen, "%s%s", dbPath, "~");
-                  snprintf(csumPath,   DbPathMaxLen, "%s%s", dbPath, "~.crc");
-
                   __sync_fetch_and_add(&gOpenFdArray[handle], FileOpen); // set open flag
+
                   strcpy(gFileHandleArray[handle].backupPath, backupPath);
                   strcpy(gFileHandleArray[handle].csumPath,   csumPath);
                   gFileHandleArray[handle].backupCreated = 0;
@@ -378,7 +374,6 @@ int pclFileWriteData(int fd, const void * buffer, int buffer_size)
 
                   // calculate checksum
                   pclCalcCrc32Csum(fd, csumBuf);
-
                   // create checksum and backup file
                   pclCreateBackup(gFileHandleArray[fd].backupPath, fd, gFileHandleArray[fd].csumPath, csumBuf);
 
@@ -562,455 +557,3 @@ int pclFileReleasePath(int pathHandle)
 
 
 
-/****************************************************************************************
- * Functions to create backup files
- ****************************************************************************************/
-
-int pclCreateFile(const char* path)
-{
-   const char* delimiters = "/\n";   // search for blank and end of line
-   char* tokenArray[24];
-   char* thePath = (char*)path;
-   int numTokens = 0, i = 0, validPath = 1;
-   int handle = 0;
-
-   tokenArray[numTokens++] = strtok(thePath, delimiters);
-   while(tokenArray[numTokens-1] != NULL )
-   {
-     tokenArray[numTokens] = strtok(NULL, delimiters);
-     if(tokenArray[numTokens] != NULL)
-     {
-        numTokens++;
-        if(numTokens >= 24)
-        {
-           validPath = 0;
-           break;
-        }
-     }
-     else
-     {
-        break;
-     }
-   }
-
-   if(validPath == 1)
-   {
-      char createPath[DbPathMaxLen] = {0};
-      snprintf(createPath, DbPathMaxLen, "/%s",tokenArray[0] );
-      for(i=1; i<numTokens-1; i++)
-      {
-         // create folders
-         strncat(createPath, "/", DbPathMaxLen-1);
-         strncat(createPath, tokenArray[i], DbPathMaxLen-1);
-         mkdir(createPath, 0744);
-      }
-      // finally create the file
-      strncat(createPath, "/", DbPathMaxLen-1);
-      strncat(createPath, tokenArray[i], DbPathMaxLen-1);
-      handle = open(createPath, O_CREAT|O_RDWR |O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
-      if(handle != -1)
-      {
-         if(handle < MaxPersHandle)
-         {
-            __sync_fetch_and_add(&gOpenFdArray[handle], FileOpen); // set open flag
-         }
-         else
-         {
-            close(handle);
-            handle = EPERS_MAXHANDLE;
-         }
-      }
-   }
-   else
-   {
-      DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pclCreateFile ==> no valid path to create: "), DLT_STRING(path) );
-   }
-
-   return handle;
-}
-
-
-int pclVerifyConsistency(const char* origPath, const char* backupPath, const char* csumPath, int openFlags)
-{
-   int handle = 0, readSize = 0;
-   int backupAvail = 0, csumAvail = 0;
-   int fdCsum = 0, fdBackup = 0;
-
-   char origCsumBuf[ChecksumBufSize] = {0};
-   char backCsumBuf[ChecksumBufSize] = {0};
-   char csumBuf[ChecksumBufSize]     = {0};
-
-   // check if we have a backup and checksum file
-   backupAvail = access(backupPath, F_OK);
-   csumAvail   = access(csumPath, F_OK);
-
-   // *************************************************
-   // there is a backup file and a checksum
-   // *************************************************
-   if( (backupAvail == 0) && (csumAvail == 0) )
-   {
-      DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclVerifyConsistency => there is a backup file AND a checksum"));
-      // calculate checksum form backup file
-      fdBackup = open(backupPath,  O_RDONLY);
-      if(fdBackup != -1)
-      {
-         pclCalcCrc32Csum(fdBackup, backCsumBuf);
-
-         fdCsum = open(csumPath,  O_RDONLY);
-         if(fdCsum != -1)
-         {
-            readSize = read(fdCsum, csumBuf, ChecksumBufSize);
-            if(readSize > 0)
-            {
-               if(strcmp(csumBuf, backCsumBuf)  == 0)
-               {
-                  // checksum matches ==> replace with original file
-                  handle = pclRecoverFromBackup(fdBackup, origPath);
-               }
-               else
-               {
-                  // checksum does not match, check checksum with original file
-                  handle = open(origPath, openFlags);
-                  if(handle != -1)
-                  {
-                     pclCalcCrc32Csum(handle, origCsumBuf);
-                     if(strcmp(csumBuf, origCsumBuf)  != 0)
-                     {
-                        close(handle);
-                        handle = -1;  // error: file corrupt
-                     }
-                     // else case: checksum matches ==> keep original file ==> nothing to do
-
-                  }
-                  else
-                  {
-                     close(handle);
-                     handle = -1;     // error: file corrupt
-                  }
-               }
-            }
-            close(fdCsum);
-         }
-         else
-         {
-            close(fdCsum);
-            handle = -1;     // error: file corrupt
-         }
-      }
-      else
-      {
-         handle = -1;
-      }
-      close(fdBackup);
-   }
-   // *************************************************
-   // there is ONLY a checksum file
-   // *************************************************
-   else if(csumAvail == 0)
-   {
-      DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclVerifyConsistency => there is ONLY a checksum file"));
-
-      fdCsum = open(csumPath,  O_RDONLY);
-      if(fdCsum != -1)
-      {
-         readSize = read(fdCsum, csumBuf, ChecksumBufSize);
-         if(readSize <= 0)
-         {
-            DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pclVerifyConsistency => read checksum: invalid readSize"));
-         }
-         close(fdCsum);
-
-         // calculate the checksum form the original file to see if it matches
-         handle = open(origPath, openFlags);
-         if(handle != -1)
-         {
-            pclCalcCrc32Csum(handle, origCsumBuf);
-
-            if(strcmp(csumBuf, origCsumBuf)  != 0)
-            {
-                close(handle);
-                handle = -1;  // checksum does NOT match ==> error: file corrupt
-            }
-            // else case: checksum matches ==> keep original file ==> nothing to do
-         }
-         else
-         {
-            close(handle);
-            handle = -1;      // error: file corrupt
-         }
-      }
-      else
-      {
-         close(fdCsum);
-         handle = -1;         // error: file corrupt
-      }
-   }
-   // *************************************************
-   // there is ONLY a backup file
-   // *************************************************
-   else if(backupAvail == 0)
-   {
-      DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclVerifyConsistency => there is ONLY a backup file"));
-
-      // calculate checksum form backup file
-      fdBackup = open(backupPath,  O_RDONLY);
-      if(fdBackup != -1)
-      {
-         pclCalcCrc32Csum(fdBackup, backCsumBuf);
-         close(fdBackup);
-
-         // calculate the checksum form the original file to see if it matches
-         handle = open(origPath, openFlags);
-         if(handle != -1)
-         {
-            pclCalcCrc32Csum(handle, origCsumBuf);
-
-            if(strcmp(backCsumBuf, origCsumBuf)  != 0)
-            {
-               close(handle);
-               handle = -1;   // checksum does NOT match ==> error: file corrupt
-            }
-            // else case: checksum matches ==> keep original file ==> nothing to do
-
-         }
-         else
-         {
-            close(handle);
-            handle = -1;      // error: file corrupt
-         }
-      }
-      else
-      {
-         close(fdBackup);
-         handle = -1;         // error: file corrupt
-      }
-   }
-   // for else case: nothing to do
-
-
-   // if we are in an inconsistent state: delete file, backup and checksum
-   if(handle == -1)
-   {
-      remove(origPath);
-      remove(backupPath);
-      remove(csumPath);
-   }
-
-   return handle;
-}
-
-
-
-int pclRecoverFromBackup(int backupFd, const char* original)
-{
-   int handle = 0;
-   int readSize = 0;
-   char buffer[RDRWBufferSize];
-
-   handle = open(original, O_TRUNC | O_RDWR);
-   if(handle != -1)
-   {
-      // copy data from one file to another
-      while((readSize = read(backupFd, buffer, RDRWBufferSize)) > 0)
-      {
-         if(write(handle, buffer, readSize) != readSize)
-         {
-            DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pclRecoverFromBackup => couldn't write whole buffer"));
-            break;
-         }
-      }
-
-   }
-
-   return handle;
-}
-
-
-
-int pclCreateBackup(const char* dstPath, int srcfd, const char* csumPath, const char* csumBuf)
-{
-   int dstFd = 0, csfd = 0;
-   int readSize = -1;
-   char buffer[RDRWBufferSize];
-
-   // create checksum file and and write checksum
-   csfd = open(csumPath, O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
-   if(csfd != -1)
-   {
-      int csumSize = strlen(csumBuf);
-      if(write(csfd, csumBuf, csumSize) != csumSize)
-      {
-         DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pclCreateBackup => failed to write checksum to file"));
-      }
-      close(csfd);
-   }
-   else
-   {
-      DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pclCreateBackup => failed to create checksum file:"), DLT_STRING(strerror(errno)) );
-   }
-
-
-   // create backup file, user and group has read/write permission, others have read permission
-   dstFd = open(dstPath, O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
-   if(dstFd != -1)
-   {
-      off_t curPos = 0;
-      // remember the current position
-      curPos = lseek(srcfd, 0, SEEK_CUR);
-
-      // copy data from one file to another
-      while((readSize = read(srcfd, buffer, RDRWBufferSize)) > 0)
-      {
-         if(write(dstFd, buffer, readSize) != readSize)
-         {
-            DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pclCreateBackup => couldn't write whole buffer"));
-            break;
-         }
-      }
-
-      if(readSize == -1)
-         DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pcl_create_backup => error copying file"));
-
-      if((readSize = close(dstFd)) == -1)
-         DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pcl_create_backup => error closing fd"));
-
-      // set back to the position
-      lseek(srcfd, curPos, SEEK_SET);
-   }
-   else
-   {
-      DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pclCreateBackup => failed to open backup file"),
-                                          DLT_STRING(dstPath), DLT_STRING(strerror(errno)));
-   }
-
-   return readSize;
-}
-
-
-
-int pclCalcCrc32Csum(int fd, char crc32sum[])
-{
-   int rval = 1;
-
-   if(crc32sum != 0)
-   {
-      char* buf;
-      struct stat statBuf;
-
-      fstat(fd, &statBuf);
-      buf = malloc((unsigned int)statBuf.st_size);
-
-      if(buf != 0)
-      {
-         off_t curPos = 0;
-         // remember the current position
-         curPos = lseek(fd, 0, SEEK_CUR);
-
-         if(curPos != 0)
-         {
-            // set to beginning of the file
-            lseek(fd, 0, SEEK_SET);
-         }
-
-         while((rval = read(fd, buf, statBuf.st_size)) > 0)
-         {
-            unsigned int crc = 0;
-            crc = pclCrc32(crc, (unsigned char*)buf, statBuf.st_size);
-            snprintf(crc32sum, ChecksumBufSize-1, "%x", crc);
-         }
-
-         // set back to the position
-         lseek(fd, curPos, SEEK_SET);
-
-         free(buf);
-      }
-   }
-   return rval;
-}
-
-
-
-int pclBackupNeeded(const char* path)
-{
-   return need_backup_key(pclCrc32(0, (const unsigned char*)path, strlen(path)));
-}
-
-
-
-int pclCreateFileAndPath(const char* path)
-{
-   const char* delimiters = "/\n";   // search for blank and end of line
-   char* tokenArray[24];
-   char* thePath = (char*)path;
-   char createPath[DbPathMaxLen] = {0};
-   int numTokens = 0, i = 0, validPath = 1;
-   int rval = -1;
-
-   tokenArray[numTokens++] = strtok(thePath, delimiters);
-   while(tokenArray[numTokens-1] != NULL )
-   {
-     tokenArray[numTokens] = strtok(NULL, delimiters);
-     if(tokenArray[numTokens] != NULL)
-     {
-        numTokens++;
-        if(numTokens >= 24)
-        {
-           validPath = 0;
-           break;
-        }
-     }
-     else
-     {
-        break;
-     }
-   }
-
-   if(validPath == 1)
-   {
-      snprintf(createPath, DbPathMaxLen, "/%s",tokenArray[0] );
-      for(i=1; i<numTokens-1; i++)
-      {
-         // create folders
-         strncat(createPath, "/", DbPathMaxLen-1);
-         strncat(createPath, tokenArray[i], DbPathMaxLen-1);
-         mkdir(createPath, 0744);
-      }
-      // finally create the file
-      strncat(createPath, "/", DbPathMaxLen-1);
-      strncat(createPath, tokenArray[i], DbPathMaxLen-1);
-      rval = open(createPath, O_CREAT|O_RDWR |O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
-      close(rval);
-   }
-   else
-   {
-      DLT_LOG(gDLTContext, DLT_LOG_ERROR, DLT_STRING("pclCreateFileAndPath ==> no valid path to create:"), DLT_STRING(path));
-   }
-
-   return rval;
-}
-
-
-
-int pclGetPosixPermission(PersistencePermission_e permission)
-{
-   int posixPerm = 0;
-
-   switch(permission)
-   {
-   case PersistencePermission_ReadWrite:
-      posixPerm = O_RDWR;
-      break;
-   case PersistencePermission_ReadOnly:
-      posixPerm = O_RDONLY;
-      break;
-   case PersistencePermission_WriteOnly:
-      posixPerm = O_WRONLY;
-      break;
-   default:
-      posixPerm = O_RDONLY;
-      break;
-   }
-
-   return posixPerm;
-}
-
index 6f42dcc..a080a1e 100644 (file)
@@ -134,6 +134,7 @@ int pclKeyHandleClose(int key_handle)
          else
          {
             set_persistence_handle_close_idx(key_handle);
+            rval = 1;
          }
 
          // invalidate entries
index b27c125..6dac0e1 100644 (file)
@@ -192,7 +192,7 @@ int get_db_context(PersistenceInfo_s* dbContext, const char* resource_id, unsign
       //
       dbContext->configKey.policy      = PersistencePolicy_wc;
       dbContext->configKey.storage     = PersistenceStorage_local;
-      dbContext->configKey.permission  = O_RDWR;
+      dbContext->configKey.permission  = PersistencePermission_ReadWrite;
       dbContext->configKey.max_size    = defaultMaxKeyValDataSize;
       if(isFile == PersistenceResourceType_file)
       {
index 44982f3..a14ebdc 100644 (file)
@@ -79,7 +79,7 @@ itzam_btree* get_resource_cfg_table_by_idx(int i);
  *
  * @return status of database, 1 is db is opened and 0 is closed
  */
-int get_resource_cfg_table_status(int i);
+inline int get_resource_cfg_table_status(int i);
 
 
 
@@ -88,7 +88,7 @@ int get_resource_cfg_table_status(int i);
  *
  * @param i the index
  */
-void invalidate_resource_cfg_table(int i);
+inline void invalidate_resource_cfg_table(int i);
 
 
 
index fb7e5f7..da7b652 100644 (file)
@@ -9,6 +9,7 @@ endif
 
 noinst_PROGRAMS = persistence_client_library_test \
                   persistence_client_library_dbus_test \
+                  persistence_client_library_benchmark \
                   persistence_admin_service_mockup \
                   persistence_lifeCycle_mockup
 
@@ -16,6 +17,10 @@ persistence_client_library_dbus_test_SOURCES = persistence_client_library_dbus_t
 persistence_client_library_dbus_test_LDADD = $(DEPS_LIBS) \
    $(top_srcdir)/src/libpersistence_client_library.la
 
+persistence_client_library_benchmark_SOURCES = persistence_client_library_benchmark.c
+persistence_client_library_benchmark_LDADD = $(DEPS_LIBS) \
+   $(top_srcdir)/src/libpersistence_client_library.la
+   
 persistence_client_library_test_SOURCES = persistence_client_library_test.c
 persistence_client_library_test_LDADD = $(DEPS_LIBS) $(CHECK_LIBS) \
    $(top_srcdir)/src/libpersistence_client_library.la
index 180fbc2..93e23cd 100644 (file)
Binary files a/test/data/Data.tar.gz and b/test/data/Data.tar.gz differ
index ea7c644..c21adb3 100644 (file)
@@ -109,11 +109,41 @@ static int endLoop = 0;
 
 void sigHandler(int signo)
 {
-   endLoop = 1;
+   switch(signo)
+   {
+      case SIGHUP:
+         // noting to do
+         printf("* * * * S I G H U P * * * *\n");
+         break;
+      default:
+         endLoop = 1;
+         break;
+   }
 }
 //------------------------------------------------------------------------
 
 
+static int setupSignalHandler(const int nSignal, void (*pHandler)(int))
+{
+   struct sigaction sa_old;
+   int ret = sigaction(nSignal, NULL, &sa_old);
+   if (0==ret)
+   {
+      if (pHandler!=sa_old.sa_handler)
+      {
+         /* setup own signal handler */
+         struct sigaction sa_new;
+         memset(&sa_new, 0, sizeof(sa_new));
+         sa_new.sa_handler = pHandler;
+         sa_new.sa_flags = 0;
+         ret = sigaction(nSignal, &sa_new, 0);
+      }
+   }
+
+   return ret;
+}
+
+
 
 #define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
 
@@ -322,9 +352,10 @@ int mainLoop(DBusObjectPathVTable vtable, DBusObjectPathVTable vtableFallback, v
    // lock mutex to make sure dbus main loop is running
    pthread_mutex_lock(&gDbusInitializedMtx);
 
-   signal(SIGTERM, sigHandler);
-   signal(SIGQUIT, sigHandler);
-   signal(SIGINT,  sigHandler);
+   setupSignalHandler(SIGTERM, sigHandler);
+   setupSignalHandler(SIGQUIT, sigHandler);
+   setupSignalHandler(SIGINT,  sigHandler);
+   setupSignalHandler(SIGHUP,  sigHandler);
 
    DBusConnection* conn = (DBusConnection*)userData;
    dbus_error_init(&err);
diff --git a/test/persistence_client_library_benchmark.c b/test/persistence_client_library_benchmark.c
new file mode 100644 (file)
index 0000000..6b6c51c
--- /dev/null
@@ -0,0 +1,389 @@
+/******************************************************************************
+ * Project         Persistency
+ * (c) copyright   2014
+ * Company         XS Embedded GmbH
+ *****************************************************************************/
+/******************************************************************************
+ * This Source Code Form is subject to the terms of the
+ * Mozilla Public License, v. 2.0. If a  copy of the MPL was not distributed
+ * with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+******************************************************************************/
+ /**
+ * @file           persistence_client_library_benchmark.c
+ * @ingroup        Persistence client library test
+ * @author         Ingo Huerner
+ * @brief          Test of persistence client library
+ * @see            
+ */
+
+#include "../include/persistence_client_library_key.h"
+#include "../include/persistence_client_library_file.h"
+#include "../include/persistence_client_library_error_def.h"
+
+#include <stdio.h>
+#include <string.h>
+
+#include <dlt/dlt.h>
+#include <dlt/dlt_common.h>
+
+#include <sys/time.h>
+#include <sys/resource.h>
+
+
+#define SECONDS2NANO 1000000000L
+#define NANO2MIL        1000000L
+#define MIL2SEC            1000L
+
+#define BUFFER_SIZE  1024
+
+// define for the used clock: "CLOCK_MONOTONIC" or "CLOCK_REALTIME"
+#define CLOCK_ID  CLOCK_MONOTONIC
+
+// definition of weekday to generate random string
+char* dayOfWeek[] = { "Sunday   ",
+                      "Monday   ",
+                      "Tuesday  ",
+                      "Wednesday",
+                      "Thursday ",
+                      "Friday   ",
+                      "Saturday "};
+
+
+char sysTimeBuffer[BUFFER_SIZE];
+char sysTimeBuffer2[BUFFER_SIZE];
+
+
+
+inline long long getNsDuration(struct timespec* start, struct timespec* end)
+{
+   return ((end->tv_sec * SECONDS2NANO) + end->tv_nsec) - ((start->tv_sec * SECONDS2NANO) + start->tv_nsec);
+}
+
+inline double getMsDuration(struct timespec* start, struct timespec* end)
+{
+   return (double)((end->tv_sec * SECONDS2NANO) + end->tv_nsec) - ((start->tv_sec * SECONDS2NANO) + start->tv_nsec)/NANO2MIL;
+}
+
+
+void read_benchmark(int numLoops)
+{
+   int ret = 0, i = 0;
+   long long duration = 0;
+   struct timespec readStart, readEnd;
+
+   unsigned char buffer[BUFFER_SIZE] = {0};
+
+   printf("\nTest  r e a d  performance: %d times\n", numLoops);
+
+   clock_gettime(CLOCK_ID, &readStart);
+   ret = pclKeyReadData(0xFF, "pos/last_position_ro_bench",      1, 2, buffer, BUFFER_SIZE);
+   clock_gettime(CLOCK_ID, &readEnd);
+   duration += getNsDuration(&readStart, &readEnd);
+   printf(" INITIAL read 1 \"pos/last_position_ro_bench\"  => %f ms [%d bytes]\n", (double)((double)duration/NANO2MIL), ret);
+
+   duration = 0;
+   memset(buffer, 0, BUFFER_SIZE);
+   for(i=0; i<numLoops; i++)
+   {
+      clock_gettime(CLOCK_ID, &readStart);
+      ret = pclKeyReadData(0xFF, "pos/last_position_ro_bench",      1, 2, buffer, BUFFER_SIZE);
+      clock_gettime(CLOCK_ID, &readEnd);
+
+      duration += getNsDuration(&readStart, &readEnd);
+   }
+   printf(" Further read 1 \"pos/last_position_ro_bench\"  => %f ms [%d bytes]\n", (double)((double)duration/NANO2MIL/numLoops), ret);
+
+
+   duration = 0;
+   memset(buffer, 0, BUFFER_SIZE);
+   for(i=0; i<numLoops; i++)
+   {
+      clock_gettime(CLOCK_ID, &readStart);
+      ret = pclKeyReadData(0xFF, "pos/last_position_ro_bench",      1, 2, buffer, BUFFER_SIZE);
+      clock_gettime(CLOCK_ID, &readEnd);
+
+      duration += getNsDuration(&readStart, &readEnd);
+   }
+   printf(" Further read 1 \"pos/last_position_ro_bench\"  => %f ms [%d bytes]\n", (double)((double)duration/NANO2MIL)/numLoops, ret);
+
+
+   duration = 0;
+   memset(buffer, 0, BUFFER_SIZE);
+
+      clock_gettime(CLOCK_ID, &readStart);
+      ret = pclKeyReadData(0xFF, "pos/last_position_ro_bench2",      1, 2, buffer, BUFFER_SIZE);
+      clock_gettime(CLOCK_ID, &readEnd);
+
+   duration = getNsDuration(&readStart, &readEnd);
+   printf(" INITIAL read 2 \"pos/last_position_ro_bench2\" => %f ms [%d bytes]\n", (double)((double)duration/NANO2MIL), ret);
+
+
+   duration = 0;
+   memset(buffer, 0, BUFFER_SIZE);
+   for(i=0; i<numLoops; i++)
+   {
+      clock_gettime(CLOCK_ID, &readStart);
+      ret = pclKeyReadData(0xFF, "pos/last_position_ro_bench2",      1, 2, buffer, BUFFER_SIZE);
+      clock_gettime(CLOCK_ID, &readEnd);
+
+      duration += getNsDuration(&readStart, &readEnd);
+   }
+   printf(" Further read 2 \"pos/last_position_ro_bench2\" => %f ms [%d bytes]\n", (double)((double)duration/NANO2MIL)/numLoops, ret);
+
+
+   duration = 0;
+   memset(buffer, 0, BUFFER_SIZE);
+   for(i=0; i<numLoops; i++)
+   {
+      clock_gettime(CLOCK_ID, &readStart);
+      ret = pclKeyReadData(0xFF, "pos/last_position_ro_bench",      1, 2, buffer, BUFFER_SIZE);
+      clock_gettime(CLOCK_ID, &readEnd);
+
+      duration += getNsDuration(&readStart, &readEnd);
+   }
+   printf(" Further read 1 \"pos/last_position_ro_bench\"  => %f ms [%d bytes]\n", (double)((double)duration/NANO2MIL)/numLoops, ret);
+
+
+#if 0
+   printf(" Size [pos/last_position_ro_bench] : %d bytes\n", pclKeyGetSize(0xFF, "pos/last_position_ro_bench",  1, 2));
+   printf(" Size [pos/last_position_ro_bench2]: %d bytes\n", pclKeyGetSize(0xFF, "pos/last_position_ro_bench2", 1, 2));
+#endif
+
+}
+
+
+
+void write_benchmark(int numLoops)
+{
+   int ret = 0, ret2 = 0, i = 0;
+   long long duration = 0;
+   struct timespec writeStart, writeEnd;
+   unsigned char buffer[BUFFER_SIZE] = {0};
+
+   printf("\nTest  w r i t e  performance: %d times\n", numLoops);
+
+   clock_gettime(CLOCK_ID, &writeStart);
+   ret = pclKeyWriteData(0xFF, "pos/last_position_w_bench", 1, 2, (unsigned char*)sysTimeBuffer, strlen(sysTimeBuffer));
+   clock_gettime(CLOCK_ID, &writeEnd);
+   duration = getNsDuration(&writeStart, &writeEnd);
+   printf(" Initial Write 1 => %f ms [%d bytes]\n", (double)((double)duration/NANO2MIL), ret);
+
+   duration = 0;
+   for(i=0; i<numLoops; i++)
+   {
+      clock_gettime(CLOCK_ID, &writeStart);
+      ret = pclKeyWriteData(0xFF, "pos/last_position_w_bench", 1, 2, (unsigned char*)sysTimeBuffer, strlen(sysTimeBuffer));
+      clock_gettime(CLOCK_ID, &writeEnd);
+
+      duration += getNsDuration(&writeStart, &writeEnd);
+   }
+   printf(" Further Write 1 => %f ms [%d bytes]\n", (double)((double)duration/NANO2MIL)/numLoops, ret);
+
+
+   duration = 0;
+   for(i=0; i<numLoops; i++)
+   {
+      clock_gettime(CLOCK_ID, &writeStart);
+      ret2 = pclKeyWriteData(0xFF, "pos/last_position_w_bench2", 1, 2, (unsigned char*)sysTimeBuffer2, strlen(sysTimeBuffer2));
+      clock_gettime(CLOCK_ID, &writeEnd);
+
+      duration += getNsDuration(&writeStart, &writeEnd);
+   }
+   printf(" Initial Write 2 => %f ms [%d bytes]\n", (double)((double)duration/NANO2MIL)/numLoops, ret2);
+
+
+   duration = 0;
+   for(i=0; i<numLoops; i++)
+   {
+      clock_gettime(CLOCK_ID, &writeStart);
+      ret2 = pclKeyWriteData(0xFF, "pos/last_position_w_bench2", 1, 2, (unsigned char*)sysTimeBuffer2, strlen(sysTimeBuffer2));
+      clock_gettime(CLOCK_ID, &writeEnd);
+
+      duration += getNsDuration(&writeStart, &writeEnd);
+   }
+   printf(" Further Write 2 => %f ms [%d bytes]\n", (double)((double)duration/NANO2MIL)/numLoops, ret2);
+
+
+#if 0
+   printf(" Size [pos/last_position_w_bench]: %d\n", ret);
+   printf(" Size [pos/last_position_w_bench]: %d\n", ret2);
+#endif
+
+   clock_gettime(CLOCK_ID, &writeStart);
+   ret = pclKeyReadData(0xFF, "pos/last_position_w_bench2",      1, 2, buffer, BUFFER_SIZE);
+   clock_gettime(CLOCK_ID, &writeEnd);
+   duration = getNsDuration(&writeStart, &writeEnd);
+   printf(" Write verification, pclKeyReadData => %f ms [%d bytes]\n", (double)((double)duration/NANO2MIL), ret);
+
+
+#if 0
+   printf(" Buffer [pos/last_position_w_bench2]:\n %s \n\n", buffer);
+#endif
+}
+
+
+
+void handle_benchmark(int numLoops)
+{
+   int hdl = 0, hdl2 = 0, hdl3 = 0, hdl4 = 0, ret = 0, i = 0;
+   long long duration = 0;
+   struct timespec openStart, openEnd;
+   unsigned char buffer[BUFFER_SIZE] = {0};
+
+   printf("\nTest  h a n d l e  performance: %d times\n", numLoops);
+
+   duration = 0;
+   for(i=0; i<1; i++)
+   {
+      clock_gettime(CLOCK_ID, &openStart);
+      hdl = pclKeyHandleOpen(0xFF, "handlePos/last_position_ro_bench", 1, 2);
+      clock_gettime(CLOCK_ID, &openEnd);
+
+      //pclKeyHandleClose(hdl);
+
+      duration += getNsDuration(&openStart, &openEnd);
+   }
+   printf(" Open 1 => %f ms\n", (double)((double)duration/NANO2MIL));
+
+   duration = 0;
+   for(i=0; i<2; i++)
+   {
+      clock_gettime(CLOCK_ID, &openStart);
+      hdl2 = pclKeyHandleOpen(0xFF, "handlePos/last_position_ro_bench2", 1, 2);
+      clock_gettime(CLOCK_ID, &openEnd);
+
+      //pclKeyHandleClose(hdl2);
+
+      duration += getNsDuration(&openStart, &openEnd);
+   }
+   printf(" Open 2 => %f ms\n", (double)((double)duration/NANO2MIL));
+
+   /*
+   hdl  = pclKeyHandleOpen(0xFF, "handlePos/last_position_ro_bench", 1, 2);
+   hdl2 = pclKeyHandleOpen(0xFF, "handlePos/last_position_ro_bench2", 1, 2);
+   */
+
+
+   duration = 0;
+   for(i=0; i<numLoops; i++)
+   {
+      clock_gettime(CLOCK_ID, &openStart);
+      ret = pclKeyHandleReadData(hdl, buffer, BUFFER_SIZE);
+      clock_gettime(CLOCK_ID, &openEnd);
+
+      duration += getNsDuration(&openStart, &openEnd);
+   }
+   printf(" Read 1 => %f ms [%d bytes]\n", (double)((double)duration/NANO2MIL)/numLoops, ret);
+#if 0
+   printf(" Buffer [handlePos/last_position_ro_bench] => %d :\n %s \n\n", ret,  buffer);
+#endif
+
+
+
+   duration = 0;
+   for(i=0; i<numLoops; i++)
+   {
+      clock_gettime(CLOCK_ID, &openStart);
+      ret = pclKeyHandleReadData(hdl2, buffer, BUFFER_SIZE);
+      clock_gettime(CLOCK_ID, &openEnd);
+
+      duration += getNsDuration(&openStart, &openEnd);
+   }
+   printf(" Read 2 => %f ms [%d bytes]\n", (double)((double)duration/NANO2MIL)/numLoops, ret);
+#if 0
+   printf(" Buffer [handlePos/last_position_ro_bench2] => %d :\n %s \n\n", ret,  buffer);
+#endif
+
+
+
+
+   clock_gettime(CLOCK_ID, &openStart);
+   hdl3 = pclKeyHandleOpen(0xFF, "handlePos/last_position_w_bench", 1, 2);
+   clock_gettime(CLOCK_ID, &openEnd);
+   duration = getNsDuration(&openStart, &openEnd);
+   printf(" Open 3 => %f ms\n", (double)((double)duration/NANO2MIL));
+
+
+   clock_gettime(CLOCK_ID, &openStart);
+   hdl4 = pclKeyHandleOpen(0xFF, "handlePos/last_position_w_bench2", 1, 2);
+   clock_gettime(CLOCK_ID, &openEnd);
+   duration = getNsDuration(&openStart, &openEnd);
+   printf(" Open 4 => %f ms\n", (double)((double)duration/NANO2MIL));
+
+
+   pclKeyHandleClose(hdl);
+   pclKeyHandleClose(hdl2);
+   pclKeyHandleClose(hdl3);
+   pclKeyHandleClose(hdl4);
+}
+
+
+
+
+int main(int argc, char *argv[])
+{
+   int ret = 0;
+   int numLoops = 5000;
+   long long duration = 0, resolution = 0;
+   unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
+   const char* appName = "lt-persistence_client_library_test";
+   struct timespec initStart, initEnd, clockRes;
+   struct tm *locTime;
+
+   time_t t = time(0);
+   locTime = localtime(&t);
+   snprintf(sysTimeBuffer, BUFFER_SIZE, "The benchmark string to do write benchmarking: \"%s %.2d.%.2d.%d - %d:%.2d:%.2d Uhr\" [time and date]", dayOfWeek[locTime->tm_wday],
+                                         locTime->tm_mday, (locTime->tm_mon)+1, (locTime->tm_year+1900),
+                                         locTime->tm_hour, locTime->tm_min, locTime->tm_sec);
+
+   snprintf(sysTimeBuffer2, BUFFER_SIZE, "The benchmark string to do write benchmarking: \"%s %.2d.%.2d.%d - %d:%.2d:%.2d Uhr\" [time and date]  ==> The benchmark string to do write benchmarking: The quick brown fox jumps over the lazy dog !!!",
+                                         dayOfWeek[locTime->tm_wday],
+                                         locTime->tm_mday, (locTime->tm_mon)+1, (locTime->tm_year+1900),
+                                         locTime->tm_hour, locTime->tm_min, locTime->tm_sec);
+
+   printf("\n\n============================\n");
+   printf("      PCL benchmark\n");
+   printf("============================\n\n");
+
+   /// debug log and trace (DLT) setup
+   DLT_REGISTER_APP("noty","tests the persistence client library");
+
+
+   clock_getres(CLOCK_ID, &clockRes);
+   resolution = ((clockRes.tv_sec * SECONDS2NANO) + clockRes.tv_nsec);
+   printf("Clock resolution  => %f ms\n\n", (double)((double)resolution/NANO2MIL));
+
+
+   clock_gettime(CLOCK_ID, &initStart);
+   ret = pclInitLibrary(appName , shutdownReg);
+   clock_gettime(CLOCK_ID, &initEnd);
+   duration = getNsDuration(&initStart, &initEnd);
+   printf("Init library  => %lld ns | %f ms\n", duration, (double)((double)duration/NANO2MIL));
+
+
+   read_benchmark(numLoops);
+
+   write_benchmark(numLoops);
+
+   handle_benchmark(numLoops);
+
+
+#if 0
+   printf("\nPress a key to end test\n");
+   getchar();
+#endif
+
+   clock_gettime(CLOCK_ID, &initStart);
+   pclDeinitLibrary();
+   clock_gettime(CLOCK_ID, &initEnd);
+   duration = ((initEnd.tv_sec * SECONDS2NANO) + initEnd.tv_nsec) - ((initStart.tv_sec * SECONDS2NANO) + initStart.tv_nsec);
+   printf("\nDeinit library  => %lld ns | %f ms\n", duration, (double)((double)duration/NANO2MIL));
+
+
+   // unregister debug log and trace
+   DLT_UNREGISTER_APP();
+
+   dlt_free();
+
+   return ret;
+}
index 0e187aa..9f9a7aa 100644 (file)
@@ -663,6 +663,7 @@ START_TEST(test_DataFileRecovery)
    ret = pclInitLibrary(gTheAppId, shutdownReg);
    fail_unless(ret <= 1, "Failed to init PCL");
 #if 1
+
    // test backup creation --------------------------------------------
    fd_RO = pclFileOpen(0xFF, "media/mediaDB_ReadOnly.db", 1, 1);
    fail_unless(fd_RO != -1, "Could not open file ==> /media/mediaDB_ReadOnly.db");
@@ -896,10 +897,11 @@ START_TEST(test_Cursor)
       memset(bufferDataDst, 0, READ_SIZE);
 
       // get key
-      rval = pers_db_cursor_get_key(handle, bufferKeySrc, 128);
+      rval = pers_db_cursor_get_key(handle, bufferKeySrc, 256);
       fail_unless(rval != -1, "Cursor failed to get key!!");
       // get data
-      rval = pers_db_cursor_get_data(handle, bufferDataSrc, 128);
+      rval = pers_db_cursor_get_data(handle, bufferDataSrc, 256);
+
       fail_unless(rval != -1, "Cursor failed to get data!!");
       // get size
       size = pers_db_cursor_get_data_size(handle);
@@ -907,10 +909,10 @@ START_TEST(test_Cursor)
       //printf("1. Key: %s | Data: %s ยป Size: %d \n", bufferKeySrc, bufferDataSrc, size);
 
       // get key
-      rval = pers_db_cursor_get_key(handle1, bufferKeyDst, 128);
+      rval = pers_db_cursor_get_key(handle1, bufferKeyDst, 256);
       fail_unless(rval != -1, "Cursor failed to get key!!");
       // get data
-      rval = pers_db_cursor_get_data(handle1, bufferDataDst, 128);
+      rval = pers_db_cursor_get_data(handle1, bufferDataDst, 256);
       fail_unless(rval != -1, "Cursor failed to get data!!");
       // get size
       size = pers_db_cursor_get_data_size(handle1);
@@ -1127,8 +1129,6 @@ static Suite * persistencyClientLib_suite()
    tcase_add_test(tc_GetPath, test_GetPath);
 
    suite_add_tcase(s, tc_persSetData);
-
-#if 1
    suite_add_tcase(s, tc_persGetData);
    suite_add_tcase(s, tc_persSetDataNoPRCT);
    suite_add_tcase(s, tc_persGetDataSize);
@@ -1142,7 +1142,6 @@ static Suite * persistencyClientLib_suite()
    suite_add_tcase(s, tc_ReadDefault);
    suite_add_tcase(s, tc_ReadConfDefault);
    suite_add_tcase(s, tc_GetPath);
-#endif
    //suite_add_tcase(s, tc_Plugin); // activate only if the plugins are available
    return s;
 }
index 115d1eb..eaab68d 100644 (file)
@@ -97,11 +97,40 @@ static int endLoop = 0;
 
 void sigHandler(int signo)
 {
-   endLoop = 1;
+   switch(signo)
+   {
+      case SIGHUP:
+         // nothing to do
+         printf("* * * * S I G H U P * * * *\n");
+         break;
+      default:
+         endLoop = 1;
+         break;
+   }
 }
 //------------------------------------------------------------------------
 
 
+static int setupSignalHandler(const int nSignal, void (*pHandler)(int))
+{
+   struct sigaction sa_old;
+   int ret = sigaction(nSignal, NULL, &sa_old);
+   if (0==ret)
+   {
+      if (pHandler!=sa_old.sa_handler)
+      {
+         /* setup own signal handler */
+         struct sigaction sa_new;
+         memset(&sa_new, 0, sizeof(sa_new));
+         sa_new.sa_handler = pHandler;
+         sa_new.sa_flags = 0;
+         ret = sigaction(nSignal, &sa_new, 0);
+      }
+   }
+
+   return ret;
+}
+
 
 #define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
 
@@ -343,9 +372,10 @@ int mainLoop(DBusObjectPathVTable vtable, DBusObjectPathVTable vtableFallback, v
    // lock mutex to make sure dbus main loop is running
    pthread_mutex_lock(&gDbusInitializedMtx);
 
-   signal(SIGTERM, sigHandler);
-   signal(SIGQUIT, sigHandler);
-   signal(SIGINT,  sigHandler);
+   setupSignalHandler(SIGTERM, sigHandler);
+   setupSignalHandler(SIGQUIT, sigHandler);
+   setupSignalHandler(SIGINT,  sigHandler);
+   setupSignalHandler(SIGHUP,  sigHandler);
 
    DBusConnection* conn = (DBusConnection*)userData;
    dbus_error_init(&err);