util/utils.cc
util/plugin_manager.cc
util/path_manager.cc
+ util/log_manager.cc
)
ADD_LIBRARY(${DOTNET_LAUNCHER_UTIL} SHARED ${${DOTNET_LAUNCHER_UTIL}_SOURCE_FILES})
SET_TARGET_PROPERTIES(${DOTNET_LAUNCHER_UTIL} PROPERTIES COMPILE_FLAGS "-fPIC")
--- /dev/null
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __LOG_MANAGER_H__
+#define __LOG_MANAGER_H__
+
+int initializeLogManager();
+int redirectFD();
+int runLoggingThread();
+
+#endif /* __LOG_MANAGER_H__ */
*/
void scanFilesInDir(const std::string& directory, FileReader reader, unsigned int depth);
-/**
- * @brief start logging thread to bypass stderr and stdout to dlog
- * @return return 0 when success, otherwise return negative value.
- */
-int runLoggingThread();
#endif /* __UTILS_H__ */
#include "dotnet_launcher.h"
#include "plugin_manager.h"
#include "path_manager.h"
+#include "log_manager.h"
#define PLUGIN_PATH "/usr/share/dotnet.tizen/lib/libdotnet_plugin.so"
__initialized(false)
{
_DBG("Constructor called!!");
-
- if (runLoggingThread() < 0) {
- _ERR("Failed to create logging thread");
- }
}
CoreRuntime::~CoreRuntime()
return -1;
}
+ if (initializeLogManager() < 0) {
+ _ERR("Failed to initnialize LogManager");
+ return -1;
+ }
+
+ if (redirectFD() < 0) {
+ _ERR("Failed to redirect FD");
+ return -1;
+ }
+
+ if (runLoggingThread() < 0) {
+ _ERR("Failed to create and run logging thread to redicrect log");
+ return -1;
+ }
+
std::string libCoreclr(concatPath(getRuntimeDir(), "libcoreclr.so"));
__coreclrLib = dlopen(libCoreclr.c_str(), RTLD_NOW | RTLD_LOCAL);
return -1;
}
+ // launchpad override stdout and stderr to journalctl before launch application.
+ // we have to re-override that to input pipe for logging thread.
+ if (redirectFD() < 0) {
+ _ERR("Failed to redirect FD");
+ return -1;
+ }
+
pluginSetAppInfo(appId, path);
int fd2 = open(root, O_DIRECTORY);
--- /dev/null
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <pthread.h>
+
+#include "log.h"
+#include "log_manager.h"
+
+static int __pfd[2];
+static pthread_t loggingThread;
+
+static void *stdlog(void*)
+{
+ ssize_t readSize;
+ char buf[1024];
+
+ 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]);
+ close(__pfd[1]);
+
+ return 0;
+}
+
+int initializeLogManager()
+{
+ if (setvbuf(stdout, NULL, _IOLBF, 0) < 0) {
+ _DBG("fail to make stdout line-buffered");
+ return -1;
+ }
+
+ if (setvbuf(stderr, NULL, _IONBF, 0) < 0) {
+ _DBG("make stderr unbuffered");
+ return -1;
+ }
+
+ /* create the pipe and redirect stdout and stderr */
+ if (pipe(__pfd) < 0) {
+ _DBG("fail to create pipe for logging");
+ return -1;
+ }
+
+ 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()
+{
+ /* spawn the logging thread */
+ if (pthread_create(&loggingThread, 0, stdlog, 0) != 0) {
+ _DBG("fail to create pthread");
+ return -1;
+ }
+
+ if (pthread_detach(loggingThread) != 0) {
+ _DBG("fail to detach pthread");
+ return -1;
+ }
+
+ return 0;
+}
+
* limitations under the License.
*/
-#include <stdio.h>
#include <dirent.h>
#include <sys/stat.h>
#include <unistd.h>
#include <limits.h>
#include <strings.h>
-#include <pthread.h>
#include <cstdlib>
#include <cstring>
#include "utils.h"
#include "path_manager.h"
-#include "log.h"
-
-static pthread_t loggingThread;
static bool iCompare(const std::string& a, int aOffset, const std::string& b, int bOffset, int length)
{
closedir(dir);
}
-static int __pfd[2];
-
-static void *stdlog(void*)
-{
- ssize_t readSize;
- char buf[1024];
-
- 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 -1;
- }
-
- if (setvbuf(stderr, NULL, _IONBF, 0) < 0) {
- _DBG("make stderr unbuffered");
- return -1;
- }
-
- /* create the pipe and redirect stdout and stderr */
- if (pipe(__pfd) < 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;
- }
-
- close(__pfd[1]);
-
- /* spawn the logging thread */
- if (pthread_create(&loggingThread, 0, stdlog, 0) != 0) {
- _DBG("fail to create pthread");
- return -1;
- }
-
- if (pthread_detach(loggingThread) != 0) {
- _DBG("fail to detach pthread");
- return -1;
- }
-
- return 0;
-}
-