Fix SMACK error 72/236972/3
authorHwankyu Jhun <h.jhun@samsung.com>
Tue, 23 Jun 2020 22:33:45 +0000 (07:33 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Tue, 23 Jun 2020 22:53:33 +0000 (07:53 +0900)
When calling sd_journal_stream_fd() is failed, the child process used
the fds of the parent. It causes SMACK errors.
To prevent SMACK errors, the child process uses "/dev/null" for standard I/O
redirection if calling sd_journal_stream_fd() is failed.

Change-Id: Ia1816c552c8d417317d031d3945c9f89a86edb40
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/common/src/launchpad_common.c

index fdb2455..1521634 100644 (file)
@@ -952,12 +952,22 @@ static int __redirect_stdout(const char *ident)
        if (fd < 0) {
                if (fd != -ENOENT)
                        _W("sd_journal_stream_fd() is failed. error(%d)", fd);
-               return fd;
+               fd = open(PATH_DEV_NULL, O_WRONLY | O_NOCTTY);
+               if (fd < 0) {
+                       ret = -errno;
+                       _E("open(%s) is failed. errno(%d)",
+                                       PATH_DEV_NULL, errno);
+                       close(STDOUT_FILENO);
+                       return ret;
+               }
        }
 
        ret = dup2(fd, STDOUT_FILENO);
-       if (ret < 0)
-               _W("dup(%d, 1) is failed. errno(%d)", fd, errno);
+       if (ret < 0) {
+               ret = -errno;
+               _E("dup(%d, 1) is failed. errno(%d)", fd, errno);
+               close(STDOUT_FILENO);
+       }
 
        close(fd);
        return ret;
@@ -972,12 +982,22 @@ static int __redirect_stderr(const char *ident)
        if (fd < 0) {
                if (fd != -ENOENT)
                        _W("sd_journal_stream_fd() is failed. error(%d)", fd);
-               return fd;
+               fd = open(PATH_DEV_NULL, O_WRONLY | O_NOCTTY);
+               if (fd < 0) {
+                       ret = -errno;
+                       _E("open(%s) is failed. errno(%d)",
+                                       PATH_DEV_NULL, errno);
+                       close(STDERR_FILENO);
+                       return ret;
+               }
        }
 
        ret = dup2(fd, STDERR_FILENO);
-       if (ret < 0)
-               _W("dup(%d, 2) is failed. errno(%d)", fd, errno);
+       if (ret < 0) {
+               ret = -errno;
+               _E("dup(%d, 2) is failed. errno(%d)", fd, errno);
+               close(STDERR_FILENO);
+       }
 
        close(fd);
        return ret;