summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWoongsuk Cho <ws77.cho@samsung.com>2018-06-26 21:07:50 +0900
committerWoongsuk Cho <ws77.cho@samsung.com>2018-06-26 21:07:50 +0900
commit9400928e9f620218d860b5fb886aacb0eb9d73f0 (patch)
tree3c65b5a686fbdc203c82e8b51f46e6c7f0d49657
parent3ce4107099d1f109aa47bd42db28c9de54ac5735 (diff)
downloadlauncher-9400928e9f620218d860b5fb886aacb0eb9d73f0.tar.gz
launcher-9400928e9f620218d860b5fb886aacb0eb9d73f0.tar.bz2
launcher-9400928e9f620218d860b5fb886aacb0eb9d73f0.zip
Change-Id: Ibbca507d26570acc5c1588aafef31ca1ecf72160
-rw-r--r--NativeLauncher/launcher/dotnet/dotnet_launcher.cc8
-rw-r--r--NativeLauncher/util/utils.cc46
2 files changed, 29 insertions, 25 deletions
diff --git a/NativeLauncher/launcher/dotnet/dotnet_launcher.cc b/NativeLauncher/launcher/dotnet/dotnet_launcher.cc
index 52e0af6..ba9de8a 100644
--- a/NativeLauncher/launcher/dotnet/dotnet_launcher.cc
+++ b/NativeLauncher/launcher/dotnet/dotnet_launcher.cc
@@ -100,6 +100,10 @@ CoreRuntime::CoreRuntime() :
pluginFinalize(nullptr),
fd(0)
{
+ if (runLoggingThread() < 0) {
+ _ERR("Failed to create logging thread");
+ }
+
#define __XSTR(x) #x
#define __STR(x) __XSTR(x)
@@ -319,10 +323,6 @@ void CoreRuntime::dispose()
int CoreRuntime::launch(const char* appId, const char* root, const char* path, int argc, char* argv[])
{
- if (runLoggingThread() < 0) {
- _ERR("Failed to create logging thread");
- }
-
if (path == nullptr) {
_ERR("executable path is null");
return 1;
diff --git a/NativeLauncher/util/utils.cc b/NativeLauncher/util/utils.cc
index 3d14f00..dfb4cc8 100644
--- a/NativeLauncher/util/utils.cc
+++ b/NativeLauncher/util/utils.cc
@@ -298,12 +298,32 @@ void scanFilesInDir(const char* directory, FileReader reader, unsigned int depth
closedir(dir);
}
+static int __pfd[2];
+
static void *stdlog(void*)
{
- int pfd[2];
ssize_t readSize;
char buf[1024];
+ _DBG("### Logger thread is created");
+
+ while ((readSize = read(__pfd[0], buf, sizeof buf - 1)) > 0) {
+ if (buf[readSize - 1] == '\n') {
+ --readSize;
+ }
+
+ buf[readSize] = 0;
+
+ _LOGX("%s", buf);
+ }
+
+ close(__pfd[0]);
+
+ return 0;
+}
+
+int runLoggingThread()
+{
if (setvbuf(stdout, NULL, _IOLBF, 0) < 0) {
_DBG("fail to make stdout line-buffered");
return 0;
@@ -315,39 +335,23 @@ static void *stdlog(void*)
}
/* create the pipe and redirect stdout and stderr */
- if (pipe(pfd) < 0) {
+ if (pipe(__pfd) < 0) {
_DBG("fail to create pipe for logging");
return 0;
}
- if (dup2(pfd[1], fileno(stdout)) == -1) {
+ if (dup2(__pfd[1], fileno(stdout)) == -1) {
_DBG("fail to duplicate fd to stdout");
return 0;
}
- if (dup2(pfd[1], fileno(stderr)) == -1) {
+ if (dup2(__pfd[1], fileno(stderr)) == -1) {
_DBG("fail to duplicate fd to stderr");
return 0;
}
- close(pfd[1]);
-
- while ((readSize = read(pfd[0], buf, sizeof buf - 1)) > 0) {
- if (buf[readSize - 1] == '\n') {
- --readSize;
- }
-
- buf[readSize] = 0;
-
- _LOGX("%s", buf);
- }
-
- close(pfd[0]);
-
- return 0;
-}
+ close(__pfd[1]);
-int runLoggingThread() {
/* spawn the logging thread */
if (pthread_create(&loggingThread, 0, stdlog, 0) != 0) {
_DBG("fail to create pthread");