Redirect stdout to dlog 42/256142/8
authorHwankyu Jhun <h.jhun@samsung.com>
Tue, 30 Mar 2021 05:19:24 +0000 (14:19 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Thu, 1 Apr 2021 01:57:30 +0000 (10:57 +0900)
Before executing an application, the child process redirects stdout &
stderr to dlog fd using connect_dlog() function.
If stdout redirection is failed, the child process tries to redirect
stdout to journal stream.

Change-Id: I356a9fbb18504933e41ab1dddf67b65ddacc47db
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
CMakeLists.txt
packaging/launchpad.spec
src/app-defined-loader/CMakeLists.txt
src/launchpad-loader/CMakeLists.txt
src/launchpad-process-pool/CMakeLists.txt
src/lib/common/src/launchpad_common.c
src/lib/launchpad/CMakeLists.txt

index 5a8e0f5..063cd75 100644 (file)
@@ -54,8 +54,9 @@ PKG_CHECK_MODULES(BUNDLE_DEPS REQUIRED bundle)
 PKG_CHECK_MODULES(BUXTON2_DEPS REQUIRED buxton2)
 PKG_CHECK_MODULES(DBUS_DEPS REQUIRED dbus-1)
 PKG_CHECK_MODULES(DLOG_DEPS REQUIRED dlog)
-PKG_CHECK_MODULES(ECORE_DEPS REQUIRED ecore)
+PKG_CHECK_MODULES(DLOG_REDIRECT_STDOUT_DEPS REQUIRED dlog-redirect-stdout)
 PKG_CHECK_MODULES(ECORE_CORE_DEPS REQUIRED ecore-core)
+PKG_CHECK_MODULES(ECORE_DEPS REQUIRED ecore)
 PKG_CHECK_MODULES(ELEMENTARY_DEPS REQUIRED elementary)
 PKG_CHECK_MODULES(GIO_DEPS REQUIRED gio-2.0)
 PKG_CHECK_MODULES(INIPARSER_DEPS REQUIRED iniparser)
index b342780..e69df09 100644 (file)
@@ -17,6 +17,7 @@ BuildRequires:  pkgconfig(bundle)
 BuildRequires:  pkgconfig(gio-2.0)
 BuildRequires:  pkgconfig(ecore)
 BuildRequires:  pkgconfig(dlog)
+BuildRequires:  pkgconfig(dlog-redirect-stdout)
 BuildRequires:  pkgconfig(libsystemd)
 BuildRequires:  pkgconfig(elementary)
 BuildRequires:  pkgconfig(vconf)
index a7fa8bb..d588f4d 100644 (file)
@@ -29,6 +29,7 @@ APPLY_PKG_CONFIG(${TARGET_APP_DEFINED_LOADER} PUBLIC
   BUNDLE_DEPS
   DBUS_DEPS
   DLOG_DEPS
+  DLOG_REDIRECT_STDOUT_DEPS
   ECORE_DEPS
   ECORE_CORE_DEPS
   GIO_DEPS
index 091bba7..b768262 100644 (file)
@@ -24,6 +24,7 @@ ENDIF(_TIZEN_FEATURE_PRELINK)
 
 APPLY_PKG_CONFIG(${TARGET_LAUNCHPAD_LOADER} PUBLIC
   DLOG_DEPS
+  DLOG_REDIRECT_STDOUT_DEPS
   ECORE_DEPS
   ELEMENTARY_DEPS
   SECURITY_MANAGER_DEPS
index 70732ff..b0af4fe 100644 (file)
@@ -28,6 +28,7 @@ APPLY_PKG_CONFIG(${TARGET_LAUNCHPAD_PROCESS_POOL} PUBLIC
   BUNDLE_DEPS
   DBUS_DEPS
   DLOG_DEPS
+  DLOG_REDIRECT_STDOUT_DEPS
   GIO_DEPS
   INIPARSER_DEPS
   LIBCAP_DEPS
index 7c4ab6f..47f5857 100644 (file)
@@ -41,6 +41,7 @@
 #include <sys/prctl.h>
 #include <dbus/dbus.h>
 #include <vconf.h>
+#include <dlog-redirect-stdout.h>
 
 #include "launchpad_common.h"
 #include "launchpad_types.h"
@@ -954,9 +955,18 @@ static int __redirect_stdin(void)
 
 static int __redirect_stdout(const char *ident)
 {
+       char buf[512];
        int ret;
        int fd;
 
+       setbuf(stdout, NULL);
+       snprintf(buf, sizeof(buf), "STDOUT_%s", ident);
+       ret = connect_dlog(LOG_ID_MAIN, STDOUT_FILENO, buf, DLOG_INFO);
+       if (ret != 0)
+               _W("connect_dlog() is failed. error(%d)", ret);
+       else
+               return 0;
+
        fd = sd_journal_stream_fd(ident, LOG_INFO, 0);
        if (fd < 0) {
                if (fd != -ENOENT)
@@ -984,9 +994,18 @@ static int __redirect_stdout(const char *ident)
 
 static int __redirect_stderr(const char *ident)
 {
+       char buf[512];
        int ret;
        int fd;
 
+       setbuf(stderr, NULL);
+       snprintf(buf, sizeof(buf), "STDERR_%s", ident);
+       ret = connect_dlog(LOG_ID_MAIN, STDERR_FILENO, buf, DLOG_WARN);
+       if (ret != 0)
+               _W("connect_dlog() is failed. error(%d)", ret);
+       else
+               return 0;
+
        fd = sd_journal_stream_fd(ident, LOG_WARNING, 0);
        if (fd < 0) {
                if (fd != -ENOENT)
@@ -1010,7 +1029,6 @@ static int __redirect_stderr(const char *ident)
 
        close(fd);
        return ret;
-
 }
 
 int _setup_stdio(const char *ident)
index d43ea34..053920b 100644 (file)
@@ -18,6 +18,7 @@ APPLY_PKG_CONFIG(${TARGET_LAUNCHPAD} PUBLIC
   BUXTON2_DEPS
   DBUS_DEPS
   DLOG_DEPS
+  DLOG_REDIRECT_STDOUT_DEPS
   LIBCAP_DEPS
   LIBSYSTEMD_DEPS
   LIBTZPLATFORM_CONFIG_DEPS