summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIngo Huerner <ingo_huerner@mentor.com>2017-03-07 10:32:32 +0100
committerIngo Huerner <ingo_huerner@mentor.com>2017-03-07 10:32:32 +0100
commit0c7939b0c1725224ff85827a8e44eb1e23dcd40b (patch)
treea79419fc4eceb91d78862f76aee9191a8216561a /src
parente88cdcdee8aa92d62b6a77ed1e938afb107229f4 (diff)
downloadpersistence-client-library-0c7939b0c1725224ff85827a8e44eb1e23dcd40b.tar.gz
Added pclCustomLibConfigFileTest.cfg.in config file for tests.
Removed in pclCustomLibConfigFile.cfg.in entries for test plugins. Replaced sync call by syncfs (process_prepare_shutdown function). Removed some unnecessary close calls (findings static code analysis tool).
Diffstat (limited to 'src')
-rw-r--r--src/persistence_client_library.c88
-rw-r--r--src/persistence_client_library_backup_filelist.c35
-rw-r--r--src/persistence_client_library_data_organization.c5
-rw-r--r--src/persistence_client_library_data_organization.h5
-rw-r--r--src/persistence_client_library_dbus_cmd.c3
5 files changed, 91 insertions, 45 deletions
diff --git a/src/persistence_client_library.c b/src/persistence_client_library.c
index 1b1b551..f64a5bd 100644
--- a/src/persistence_client_library.c
+++ b/src/persistence_client_library.c
@@ -54,11 +54,19 @@ static int gCancelCounter = 0;
static pthread_mutex_t gInitMutex = PTHREAD_MUTEX_INITIALIZER;
/// name of the backup blacklist file (contains all the files which are excluded from backup creation)
-const char* gBackupFilename = "BackupFileList.info";
+static const char* gBackupFilename = "BackupFileList.info";
+
+static const char* gNsmAppId = "NodeStateManager";
+
+static char gAppFolder[PERS_ORG_MAX_LENGTH_PATH_FILENAME] = {0};
+
#if USE_APPCHECK
/// global flag
static int gAppCheckFlag = -1;
+
+static char gRctFilename[PERS_ORG_MAX_LENGTH_PATH_FILENAME] = {0};
+
#endif
int customAsyncInitClbk(int errcode)
@@ -80,11 +88,11 @@ static int private_pclDeinitLibrary(void);
#if USE_APPCHECK
static void doInitAppcheck(const char* appName)
{
+ // no need for NULL ptr check for appName, already done in calling function
- char rctFilename[PERS_ORG_MAX_LENGTH_PATH_FILENAME] = {0};
- snprintf(rctFilename, PERS_ORG_MAX_LENGTH_PATH_FILENAME, getLocalWtPathKey(), appName, plugin_gResTableCfg);
+ snprintf(gRctFilename, PERS_ORG_MAX_LENGTH_PATH_FILENAME, getLocalWtPathKey(), appName, plugin_gResTableCfg);
- if(access(rctFilename, F_OK) == 0)
+ if(access(gRctFilename, F_OK) == 0)
{
gAppCheckFlag = 1; // "trusted" application
DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("initLibrary - app check: "), DLT_STRING(appName), DLT_STRING("trusted app"));
@@ -105,9 +113,7 @@ int doAppcheck(void)
if(gAppCheckFlag != 1)
{
- char rctFilename[PERS_ORG_MAX_LENGTH_PATH_FILENAME] = {0};
- snprintf(rctFilename, PERS_ORG_MAX_LENGTH_PATH_FILENAME, getLocalWtPathKey(), gAppId, plugin_gResTableCfg);
- if(access(rctFilename, F_OK) == 0)
+ if(access(gRctFilename, F_OK) == 0)
{
gAppCheckFlag = 1; // "trusted" application
}
@@ -204,26 +210,35 @@ int pclInitLibrary(const char* appName, int shutdownMode)
int lock = pthread_mutex_lock(&gInitMutex);
if(lock == 0)
{
- if(gPclInitCounter == 0)
+ if(appName != NULL)
{
- DLT_REGISTER_CONTEXT(gPclDLTContext,"PCL","Ctx for PCL Logging");
+ if(gPclInitCounter == 0)
+ {
+ DLT_REGISTER_CONTEXT(gPclDLTContext,"PCL","Ctx for PCL Logging");
- DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("pclInitLibrary => App:"), DLT_STRING(appName),
- DLT_STRING("- init counter: "), DLT_UINT(gPclInitCounter) );
+ DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("pclInitLibrary => App:"), DLT_STRING(appName),
+ DLT_STRING("- init counter: "), DLT_UINT(gPclInitCounter) );
- // do check if there are remaining shared memory and semaphores for local app
- checkLocalArtefacts("/dev/shm/", appName);
- //checkGroupArtefacts("/dev/shm", "group_");
+ // do check if there are remaining shared memory and semaphores for local app
+ checkLocalArtefacts("/dev/shm/", appName);
+ //checkGroupArtefacts("/dev/shm", "group_");
- rval = private_pclInitLibrary(appName, shutdownMode);
+ rval = private_pclInitLibrary(appName, shutdownMode);
+ }
+ else
+ {
+ DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("pclInitLibrary - App:"), DLT_STRING(gAppId),
+ DLT_STRING("- ONLY INCREMENT init counter: "), DLT_UINT(gPclInitCounter) );
+ }
+
+ gPclInitCounter++; // increment after private init, otherwise atomic access is too early
}
else
{
- DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("pclInitLibrary - App:"), DLT_STRING(gAppId),
- DLT_STRING("- ONLY INCREMENT init counter: "), DLT_UINT(gPclInitCounter) );
+ DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pclInitLibrary - appName NULL"));
+ rval = EPERS_COMMON;
}
- gPclInitCounter++; // increment after private init, otherwise atomic access is too early
pthread_mutex_unlock(&gInitMutex);
}
else
@@ -236,16 +251,36 @@ int pclInitLibrary(const char* appName, int shutdownMode)
static int private_pclInitLibrary(const char* appName, int shutdownMode)
{
+ // no need for NULL ptr check for appName, already done in calling function
+
int rval = 1;
- char blacklistPath[PERS_ORG_MAX_LENGTH_PATH_FILENAME] = {0};
+ char blacklistPath[PERS_ORG_MAX_LENGTH_PATH_FILENAME] = {0};
gShutdownMode = shutdownMode;
-#if USE_APPCHECK
- doInitAppcheck(appName); // check if we have a trusted application
-#endif
+ strncpy(gAppId, appName, PERS_RCT_MAX_LENGTH_RESPONSIBLE); // assign application name
+ gAppId[PERS_RCT_MAX_LENGTH_RESPONSIBLE-1] = '\0';
+ if(strcmp(appName, gNsmAppId) != 0) // check for NodeStateManager
+ {
+ // get and fd to the app folder, needed to call syncfs when cmd CMD_LC_PREPARE_SHUTDOWN is called
+ // (commit buffer cache to disk)
+ // only if not NSM ==> if NSM ha an handle to the folder, it may interfere with PAS installation sequence
+ memset(gAppFolder, 0, PERS_ORG_MAX_LENGTH_PATH_FILENAME-1);
+ snprintf(gAppFolder, PERS_ORG_MAX_LENGTH_PATH_FILENAME, "/Data/mnt-c/%s/", appName);
+ gAppFolder[PERS_ORG_MAX_LENGTH_PATH_FILENAME-1] = '\0';
+
+ gSyncFd = open(gAppFolder, O_RDONLY);
+ if(gSyncFd == -1)
+ {
+ DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("Failed to open syncfd:"), DLT_STRING(strerror(errno)));
+ }
+ }
+ else
+ {
+ gIsNodeStateManager = 1;
+ }
#if USE_FILECACHE
DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("Using the filecache!!!"));
@@ -266,7 +301,6 @@ static int private_pclInitLibrary(const char* appName, int shutdownMode)
return EPERS_DBUS_MAINLOOP;
}
-
if(gShutdownMode != PCL_SHUTDOWN_TYPE_NONE)
{
if(register_lifecycle(shutdownMode) == -1) // register for lifecycle dbus messages
@@ -297,8 +331,9 @@ static int private_pclInitLibrary(const char* appName, int shutdownMode)
init_key_handle_array();
- strncpy(gAppId, appName, PERS_RCT_MAX_LENGTH_RESPONSIBLE); // assign application name
- gAppId[PERS_RCT_MAX_LENGTH_RESPONSIBLE-1] = '\0';
+#if USE_APPCHECK
+ doInitAppcheck(appName); // check if we have a trusted application
+#endif
pers_unlock_access();
@@ -392,6 +427,9 @@ static int private_pclDeinitLibrary(void)
pfcDeinitCache();
#endif
+ if(gIsNodeStateManager == 0)
+ close(gSyncFd);
+
return rval;
}
diff --git a/src/persistence_client_library_backup_filelist.c b/src/persistence_client_library_backup_filelist.c
index 0896dc5..19cd22a 100644
--- a/src/persistence_client_library_backup_filelist.c
+++ b/src/persistence_client_library_backup_filelist.c
@@ -239,6 +239,11 @@ int pclCreateFile(const char* path, int chached)
char thePath[PERS_ORG_MAX_LENGTH_PATH_FILENAME] = {0};
int numTokens = 0, i = 0, validPath = 1, handle = -1;
+ if (path == NULL)
+ {
+ return handle;
+ }
+
strncpy(thePath, path, PERS_ORG_MAX_LENGTH_PATH_FILENAME);
thePath[PERS_ORG_MAX_LENGTH_PATH_FILENAME-1] = '\0'; // Ensures 0-Termination
@@ -348,26 +353,20 @@ int pclVerifyConsistency(const char* origPath, const char* backupPath, const cha
}
// 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
}
+ close(fdBackup);
}
else
{
handle = -1;
}
- close(fdBackup);
}
// *************************************************
// there is ONLY a checksum file
@@ -398,11 +397,6 @@ int pclVerifyConsistency(const char* origPath, const char* backupPath, const cha
}
// else case: checksum matches ==> keep original file ==> nothing to do
}
- else
- {
- close(handle);
- handle = -1; // error: file corrupt
- }
}
else
{
@@ -430,20 +424,15 @@ int pclVerifyConsistency(const char* origPath, const char* backupPath, const cha
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
}
+ close(fdBackup);
}
else
{
- close(fdBackup);
handle = -1; // error: file corrupt
}
}
@@ -482,6 +471,11 @@ int pclCreateBackup(const char* dstPath, int srcfd, const char* csumPath, const
{
int dstFd = 0, csfd = 0, readSize = -1;
+ if ((dstPath == NULL) || (csumPath == NULL))
+ {
+ return readSize;
+ }
+
if(access(dstPath, F_OK) != 0)
{
int handle = -1;
@@ -491,7 +485,10 @@ int pclCreateBackup(const char* dstPath, int srcfd, const char* csumPath, const
pathToCreate[PERS_ORG_MAX_LENGTH_PATH_FILENAME-1] = '\0'; // Ensures 0-Termination
handle = pclCreateFile(pathToCreate, 0);
- close(handle); // don't need the open file
+ if (handle != -1)
+ {
+ close(handle); // don't need the open file
+ }
}
// create checksum file and and write checksum
diff --git a/src/persistence_client_library_data_organization.c b/src/persistence_client_library_data_organization.c
index db26ef5..7fd9ace 100644
--- a/src/persistence_client_library_data_organization.c
+++ b/src/persistence_client_library_data_organization.c
@@ -30,6 +30,11 @@ unsigned int gPclInitCounter = 0;
/// flag to indicate if PCL has registered to PAS
int gPasRegistered = 0;
+int gSyncFd = -1;
+
+int gIsNodeStateManager = 0;
+
+
int(* gChangeNotifyCallback)(pclNotification_s * notifyStruct);
/// character lookup table used for parsing configuration files
diff --git a/src/persistence_client_library_data_organization.h b/src/persistence_client_library_data_organization.h
index 429b77a..e83023d 100644
--- a/src/persistence_client_library_data_organization.h
+++ b/src/persistence_client_library_data_organization.h
@@ -267,6 +267,11 @@ const char* getSharedPublicWtPathKey(void);
*/
const char* getLocalCacheFilePath(void);
+/// file descriptor used to call syncfs to commit buffer cache to disk
+extern int gSyncFd;
+
+/// flag to didicate if the lib is used by the NodeStateManager (appid)
+extern int gIsNodeStateManager;
/// application id
diff --git a/src/persistence_client_library_dbus_cmd.c b/src/persistence_client_library_dbus_cmd.c
index 18b5f74..7c881df 100644
--- a/src/persistence_client_library_dbus_cmd.c
+++ b/src/persistence_client_library_dbus_cmd.c
@@ -249,7 +249,8 @@ void process_prepare_shutdown(unsigned int complete)
}
}
- sync(); // finally make sure data will be written back to the memory device.s
+ if(gIsNodeStateManager == 0)
+ syncfs(gSyncFd); // finally make sure to commit buffer cache to disk
}