Check stdout fds redirection 48/260648/4
authorHwankyu Jhun <h.jhun@samsung.com>
Wed, 30 Jun 2021 07:25:22 +0000 (16:25 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Mon, 5 Jul 2021 22:52:42 +0000 (07:52 +0900)
Before executing an application, the child process checks whether the
stdout and stderr fds are redirected or not. If it's not, the child
process tries to redirect stdout and stderr to dlog fd.
And then, the child process tries to redirect stdout and stderr to
journal stream fd if it's failed.

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

index 5a8e0f55b85590fa9e9625fdf30e506c60b875c2..fb3d5cac2d1cebe67bfbfe6f4331202dcaf52492 100644 (file)
@@ -54,6 +54,7 @@ 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(DLOG_REDIRECT_STDOUT_DEPS REQUIRED dlog-redirect-stdout)
 PKG_CHECK_MODULES(ECORE_DEPS REQUIRED ecore)
 PKG_CHECK_MODULES(ECORE_CORE_DEPS REQUIRED ecore-core)
 PKG_CHECK_MODULES(ELEMENTARY_DEPS REQUIRED elementary)
index 3fa46c62ca615b6ddf630babf81f2ee715d2a4d2..38e1109e79a377b28b15e6412509711f09542d36 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 70732ff8cf2448bca2c6db012bd55dbb8b253600..b0af4fe93247313da2db0b6744568a99e88a88c1 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 61cb98cde826b3299c85525b68126312f1732c0d..16ec220d6c495394d99d1f268bcfc9006f9480f6 100644 (file)
@@ -41,6 +41,8 @@
 #include <sys/prctl.h>
 #include <dbus/dbus.h>
 #include <vconf.h>
+#include <dlog.h>
+#include <dlog-redirect-stdout.h>
 
 #include "launchpad_common.h"
 #include "launchpad_types.h"
@@ -957,6 +959,17 @@ static int __redirect_stdout(const char *ident)
        int ret;
        int fd;
 
+       if (dlog_is_log_fd(STDOUT_FILENO)) {
+               _W("STDOUT_FILENO is using dlog fd");
+               return 0;
+       }
+
+       ret = dlog_connect_fd(LOG_ID_APPS, STDOUT_FILENO, "STDOUT", DLOG_WARN);
+       if (ret == 0) {
+               _W("STDOUT_FILENO redirection is successful");
+               return 0;
+       }
+
        fd = sd_journal_stream_fd(ident, LOG_INFO, 0);
        if (fd < 0) {
                if (fd != -ENOENT)
@@ -987,6 +1000,17 @@ static int __redirect_stderr(const char *ident)
        int ret;
        int fd;
 
+       if (dlog_is_log_fd(STDERR_FILENO)) {
+               _W("STDERR_FILENO is using dlog fd");
+               return 0;
+       }
+
+       ret = dlog_connect_fd(LOG_ID_APPS, STDERR_FILENO, "STDERR", DLOG_ERROR);
+       if (ret == 0) {
+               _W("STDERR_FILENO redirection is successful");
+               return 0;
+       }
+
        fd = sd_journal_stream_fd(ident, LOG_WARNING, 0);
        if (fd < 0) {
                if (fd != -ENOENT)
index d43ea341cbe0a09b360a894dc5d2a8a2bbf9b824..053920b511075cd11d0fb9672caab6dd8cad292d 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