redirect stderr/stdout to dlog before app launching 24/184224/1 accepted/tizen/4.0/unified/20180717.143258 submit/tizen_4.0/20180717.020222
authorWoongsuk Cho <ws77.cho@samsung.com>
Mon, 16 Jul 2018 11:09:44 +0000 (20:09 +0900)
committerWoongsuk Cho <ws77.cho@samsung.com>
Mon, 16 Jul 2018 11:09:44 +0000 (20:09 +0900)
Change-Id: I97b08fbc844c23a61e7d3509c3679f9ad8239835

NativeLauncher/inc/utils.h
NativeLauncher/launcher/dotnet/dotnet_launcher.cc
NativeLauncher/util/utils.cc

index ac3816e..d2293ac 100644 (file)
@@ -44,5 +44,6 @@ std::string joinStrings(const std::vector<std::string>& strings, const char* con
 typedef std::function<void (const char*, const char*)> FileReader;
 void scanFilesInDir(const char* directory, FileReader reader, unsigned int depth);
 
+int redirectFD();
 int runLoggingThread();
 #endif /* __UTILS_H__ */
index ba9de8a..a2b42ca 100644 (file)
@@ -333,6 +333,11 @@ int CoreRuntime::launch(const char* appId, const char* root, const char* path, i
                return 1;
        }
 
+       if (redirectFD() < 0) {
+               _ERR("Fail to redirect FD");
+                return 1;
+       }
+
        if (pluginSetAppInfo)
                pluginSetAppInfo(appId, path);
 
index dfb4cc8..b902783 100644 (file)
@@ -322,36 +322,50 @@ static void *stdlog(void*)
     return 0;
 }
 
+int redirectFD()
+{
+       if (__pfd[1] < 0) {
+               _DBG("fail to create pipe for logging");
+               return -1;
+       }
+    // stdout
+    if (dup2(__pfd[1], 1) == -1) {
+               _DBG("fail to duplicate fd to stdout");
+               return -1;
+    }
+
+    // stderr
+    if (dup2(__pfd[1], 2) == -1) {
+               _DBG("fail to duplicate fd to stderr");
+               return-1;
+       }
+
+       return 0;
+}
+
 int runLoggingThread()
 {
     if (setvbuf(stdout, NULL, _IOLBF, 0) < 0) {
                _DBG("fail to make stdout line-buffered");
-               return 0;
+               return -1;
     }
 
     if (setvbuf(stderr, NULL, _IONBF, 0) < 0) {
                _DBG("make stderr unbuffered");
-               return 0;
+               return -1;
        }
 
     /* create the pipe and redirect stdout and stderr */
     if (pipe(__pfd) < 0) {
                _DBG("fail to create pipe for logging");
-               return 0;
-    }
-
-    if (dup2(__pfd[1], fileno(stdout)) == -1) {
-               _DBG("fail to duplicate fd to stdout");
-               return 0;
+               return -1;
     }
 
-    if (dup2(__pfd[1], fileno(stderr)) == -1) {
-               _DBG("fail to duplicate fd to stderr");
-               return 0;
+       if (redirectFD() < 0) {
+               _DBG("fail to redirect FD");
+        return -1;
        }
 
-       close(__pfd[1]);
-
     /* spawn the logging thread */
     if (pthread_create(&loggingThread, 0, stdlog, 0) != 0) {
                _DBG("fail to create pthread");