From 2b409c9bc73a333373d58dd4f8a0fd77537da29c Mon Sep 17 00:00:00 2001 From: Mark Salyzyn Date: Thu, 28 Apr 2016 16:06:24 -0700 Subject: [PATCH] liblog: O_CLOEXEC flag on opens (cherry pick from commit 78786da116064e6a2b7bb768e1eb77f3804eace4) Bug: 28455828 Change-Id: Ic00101a6192aab7271cb0c3461e249a77d7f29ed --- liblog/event_tag_map.c | 2 +- liblog/logprint.c | 2 +- liblog/pmsg_reader.c | 4 ++-- liblog/pmsg_writer.c | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/liblog/event_tag_map.c b/liblog/event_tag_map.c index 64d872a25..3cb04cf47 100644 --- a/liblog/event_tag_map.c +++ b/liblog/event_tag_map.c @@ -73,7 +73,7 @@ LIBLOG_ABI_PUBLIC EventTagMap* android_openEventTagMap(const char* fileName) if (newTagMap == NULL) return NULL; - fd = open(fileName, O_RDONLY); + fd = open(fileName, O_RDONLY | O_CLOEXEC); if (fd < 0) { fprintf(stderr, "%s: unable to open map '%s': %s\n", OUT_TAG, fileName, strerror(errno)); diff --git a/liblog/logprint.c b/liblog/logprint.c index 9b60d4aeb..c8457f4bf 100644 --- a/liblog/logprint.c +++ b/liblog/logprint.c @@ -1042,7 +1042,7 @@ static void convertMonotonic(struct timespec *result, * Anything in the Android Logger before the dmesg logging span will * be highly suspect regarding the monotonic time calculations. */ - FILE *p = popen("/system/bin/dmesg", "r"); + FILE *p = popen("/system/bin/dmesg", "re"); if (p) { char *line = NULL; size_t len = 0; diff --git a/liblog/pmsg_reader.c b/liblog/pmsg_reader.c index 5695e8ae5..f5e91c85a 100644 --- a/liblog/pmsg_reader.c +++ b/liblog/pmsg_reader.c @@ -151,13 +151,13 @@ static int pmsgRead(struct android_log_logger_list *logger_list, memset(log_msg, 0, sizeof(*log_msg)); if (transp->context.fd <= 0) { - int fd = open("/sys/fs/pstore/pmsg-ramoops-0", O_RDONLY); + int fd = open("/sys/fs/pstore/pmsg-ramoops-0", O_RDONLY | O_CLOEXEC); if (fd < 0) { return -errno; } if (fd == 0) { /* Argggg */ - fd = open("/sys/fs/pstore/pmsg-ramoops-0", O_RDONLY); + fd = open("/sys/fs/pstore/pmsg-ramoops-0", O_RDONLY | O_CLOEXEC); close(0); if (fd < 0) { return -errno; diff --git a/liblog/pmsg_writer.c b/liblog/pmsg_writer.c index 9cd3c48ff..2ba31fab1 100644 --- a/liblog/pmsg_writer.c +++ b/liblog/pmsg_writer.c @@ -54,7 +54,7 @@ LIBLOG_HIDDEN struct android_log_transport_write pmsgLoggerWrite = { static int pmsgOpen() { if (pmsgLoggerWrite.context.fd < 0) { - pmsgLoggerWrite.context.fd = TEMP_FAILURE_RETRY(open("/dev/pmsg0", O_WRONLY)); + pmsgLoggerWrite.context.fd = TEMP_FAILURE_RETRY(open("/dev/pmsg0", O_WRONLY | O_CLOEXEC)); } return pmsgLoggerWrite.context.fd;