diff options
author | Hwankyu Jhun <h.jhun@samsung.com> | 2020-06-24 07:33:45 +0900 |
---|---|---|
committer | Hwankyu Jhun <h.jhun@samsung.com> | 2020-06-24 07:53:33 +0900 |
commit | 4ec25e48dc1c0abc206176e6832bfb1ea8f6126b (patch) | |
tree | 581296476f3ee5607e3d1e56305a9403605e727e | |
parent | 9996f39b1d9d581fcb810dc0b031613637cd2f5d (diff) | |
download | launchpad-4ec25e48dc1c0abc206176e6832bfb1ea8f6126b.tar.gz launchpad-4ec25e48dc1c0abc206176e6832bfb1ea8f6126b.tar.bz2 launchpad-4ec25e48dc1c0abc206176e6832bfb1ea8f6126b.zip |
Fix SMACK error
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>
-rw-r--r-- | src/common/src/launchpad_common.c | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/src/common/src/launchpad_common.c b/src/common/src/launchpad_common.c index fdb2455..1521634 100644 --- a/src/common/src/launchpad_common.c +++ b/src/common/src/launchpad_common.c @@ -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; |