Remove debug pipe for candidate process accepted/tizen/unified/20200811.050502 submit/tizen/20200811.005032
authorWoongsuk Cho <ws77.cho@samsung.com>
Mon, 10 Aug 2020 07:15:00 +0000 (16:15 +0900)
committer조웅석/Common Platform Lab(SR)/Principal Engineer/삼성전자 <ws77.cho@samsung.com>
Mon, 10 Aug 2020 23:22:45 +0000 (08:22 +0900)
The debug pipe created in the candidate process has a "User" label.
As a result, smack deny occurs when app process try to access the debug pipe.
Also, since debugging is performed only in standalone mode, the debug pipe does not be used in the candidate process

NativeLauncher/launcher/lib/core_runtime.cc

index 8795ac3..2a39b0a 100644 (file)
@@ -17,6 +17,7 @@
 
 #include <dlfcn.h>
 #include <signal.h>
+#include <dirent.h>
 
 #include <string>
 #include <fstream>
@@ -223,6 +224,31 @@ static std::string readSelfPath()
        return "";
 }
 
+static void removeDebugPipe()
+{
+       DIR *dir;
+       struct dirent* entry;
+       char debugPipeFiles[PATH_MAX];;
+       sprintf(debugPipeFiles, "/tmp/clr-debug-pipe-%d-", getpid());
+
+       dir = opendir("/tmp");
+       if (dir == nullptr) {
+               _ERR("Fail to open /tmp directory");
+               return;
+       }
+
+       while ((entry = readdir(dir)) != nullptr) {
+               std::string path = concatPath("/tmp", entry->d_name);
+               if (path.find(debugPipeFiles) != std::string::npos) {
+                       if (!removeFile(path)) {
+                               _ERR("Fail to remove file (%s)", path.c_str());
+                       }
+               }
+       }
+
+       closedir(dir);
+}
+
 void preload()
 {
        typedef void (*PreloadDelegate)();
@@ -425,6 +451,13 @@ int CoreRuntime::initialize(const char* appType, LaunchMode launchMode)
 
                // preload libraries and manage dlls for optimizing startup time
                preload();
+
+               // The debug pipe created in the candidate process has a "User" label.
+               // As a result, smack deny occurs when app process try to access the debug pipe.
+               // Also, since debugging is performed only in standalone mode,
+               // the debug pipe doesnot be used in the candidate process.
+               // So, to avoid smack deny error, delete unused debug pipe files.
+               removeDebugPipe();
        }
 
        __initialized = true;