#include "common/tools.h"
#include <app_manager.h>
+#include <mutex>
#include <pkgmgr-info.h>
#include <privilegemgr/privilege_manager.h>
#include <sys/stat.h>
PlatformResult CheckAccess(const std::vector<std::string>& privileges) {
ScopeLogger();
+ /*
+ * This lock is crucial to avoid concurrent access of static variables in this function and
+ * in AccessControlImpl class.
+ * Concurrent access is likely in web service apps. If multiple are running, each of them is executed in
+ * a thread of the same process.
+ */
+ static std::mutex check_access_mutex;
+ const std::lock_guard<std::mutex> lock{check_access_mutex};
+
// Local cache of mapped privilege strings. This routine can be called many times, especially
// during application launch, generating a high overhead of retrieving mapped privileges from
// the underlying databases. This is especially the case since the same mappings can end up