Create aul directories 37/309037/2
authorHwankyu Jhun <h.jhun@samsung.com>
Thu, 4 Apr 2024 05:51:39 +0000 (14:51 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Thu, 4 Apr 2024 06:28:28 +0000 (15:28 +0900)
Currently, amd can run before creating aul directories by systemd-tempfiles.
In this case, amd has crashed. When attempting to access the '.amd.db',
the operation fails because the directory does not exist, which causes
the crash. When doing the AMD initialization, it is necessary to check whether
the required directory exists and perform the creation operation if it doesn't.

Change-Id: I3a36b9cffa778d8a97f8b2aff7c9035adde1667e
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/lib/amd_main.cc

index bce5fdbc761c54a035f1e5c89d56e43c7ea6f6e6..634f75adc9908721bd58350662ac0ca438e45760 100644 (file)
@@ -70,6 +70,10 @@ namespace {
 
 constexpr const char PATH_AMD_MOD[] = "/usr/share/amd/mod";
 constexpr const char PATH_AMD_READY[] = "/run/.amd_ready";
+constexpr const char PATH_AUL_APPS[] = "/run/aul/apps";
+constexpr const char PATH_AUL_DBSPACE[] = "/run/aul/dbspace";
+constexpr const char PATH_AUL_LOG[] = "/run/aul/log";
+constexpr const char PATH_AUL_RPCPORT[] = "/run/aul/rpcport";
 constexpr const char AMD_MOD_INIT[] = "AMD_MOD_INIT";
 constexpr const char AMD_MOD_FINI[] = "AMD_MOD_FINI";
 
@@ -172,10 +176,27 @@ class PluginManager {
   std::list<std::unique_ptr<Plugin>> plugin_list_;
 };
 
+void CheckAndCreateDirectory(const char* path) {
+  if (access(path, F_OK) != 0) {
+    if (mkdir(path, 1777) != 0)
+      _E("mkdir() is failed. path(%s), errno(%d)", path, errno);
+    else
+      _D("path(%s) is created successfully", path);
+  }
+}
+
+void CreateAulDirectories() {
+  CheckAndCreateDirectory(PATH_AUL_APPS);
+  CheckAndCreateDirectory(PATH_AUL_DBSPACE);
+  CheckAndCreateDirectory(PATH_AUL_LOG);
+  CheckAndCreateDirectory(PATH_AUL_RPCPORT);
+}
+
 }  // namespace
 
 static int Initialize() {
   _W("AMD_INIT");
+  CreateAulDirectories();
   _config_init();
   _logger_init();
   _unix_signal_init();