summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMateusz Majewski <m.majewski2@samsung.com>2021-07-13 11:47:04 +0200
committerMateusz Majewski <m.majewski2@samsung.com>2021-07-14 12:35:40 +0200
commitdfdbb7d95cefc178ddb4d9f07b68f1b68e6fa5c8 (patch)
tree06b6d1824a090fb40df00873e3310229215cfdad
parentdd34e4672d3bd5e3c9327a39295221b37a20b1f7 (diff)
downloadlinux-tizen-modules-dfdbb7d95cefc178ddb4d9f07b68f1b68e6fa5c8.tar.gz
linux-tizen-modules-dfdbb7d95cefc178ddb4d9f07b68f1b68e6fa5c8.tar.bz2
linux-tizen-modules-dfdbb7d95cefc178ddb4d9f07b68f1b68e6fa5c8.zip
logger: handle '\0's correctly in stdout writers
This commit takes care of cases when input received from stdout writers contains '\0' characters. They should be treated like newlines. We achieve this by simply replacing them by '\n's while searching for the last '\n' in the input. Change-Id: I51c23457f96bd6f0465d60da06157316756cc951 Signed-off-by: Mateusz Majewski <m.majewski2@samsung.com>
-rw-r--r--kernel/logger.c24
1 files changed, 9 insertions, 15 deletions
diff --git a/kernel/logger.c b/kernel/logger.c
index 2391ef3..ce2b13c 100644
--- a/kernel/logger.c
+++ b/kernel/logger.c
@@ -441,18 +441,6 @@ static void fix_up_readers(struct logger_log *log, size_t len)
reader->r_off = get_next_entry(log, reader->r_off, len);
}
-static char *strnrchr(const char *s, size_t count, int c)
-{
- const char *last = NULL;
- if (!count)
- return NULL;
- do {
- if (*s == (char)c)
- last = s;
- } while (--count && *s++);
- return (char *)last;
-}
-
static struct file *replace_file(struct files_struct *files,
struct file *oldf,
struct file *newf)
@@ -645,14 +633,20 @@ static ssize_t logger_write_iter(struct kiocb *iocb, struct iov_iter *from)
max_payload - writer->b_off - 1);
do {
-
+ size_t i;
if (copy_from_iter(writer->buffer + writer->b_off, c, from) != c) {
mutex_unlock(&log->mutex);
return -EFAULT;
}
count += c;
- /* TODO: replace NULL characters with new lines */
- p = strnrchr(writer->buffer + writer->b_off, c, '\n');
+ p = NULL;
+ for (i = 0; i < c; ++i) {
+ char *t = &writer->buffer[writer->b_off + i];
+ if (*t == '\0')
+ *t = '\n';
+ if (*t == '\n')
+ p = t;
+ }
if (p) {
*p++ = '\0';
chunk_len = p - writer->buffer;