logger: return amount of data written to stdio
authorŁukasz Stelmach <l.stelmach@samsung.com>
Tue, 13 Apr 2021 10:24:38 +0000 (12:24 +0200)
committerKarol Lewandowski <k.lewandowsk@samsung.com>
Thu, 22 Apr 2021 13:29:06 +0000 (15:29 +0200)
Return amount of data written by a process to a logger via STDIO
interface.

Change-Id: I9c77a312d09f3d796a7ec64d5909af193bcc8bc2
Signed-off-by: Łukasz Stelmach <l.stelmach@samsung.com>
drivers/staging/android/logger.c

index 680ec1a..3347706 100644 (file)
@@ -592,7 +592,7 @@ static ssize_t logger_write_iter(struct kiocb *iocb, struct iov_iter *from)
        /* Prepend messages from STDOUT and STDERR with a tag and prio */
        if (from_stdio) {
                char *p;
-               size_t chunk_len = 0;
+               size_t chunk_len = 0, c = 0;
                /* -2 : priority byte and tag terminating '\0' */
                size_t max_payload = LOGGER_ENTRY_MAX_PAYLOAD - writer->tag_len - 2;
 
@@ -624,30 +624,31 @@ static ssize_t logger_write_iter(struct kiocb *iocb, struct iov_iter *from)
                if (writer->b_owner != current && writer->b_off)
                        flush_thread_data(file);
 
+               count = 0;
                /* -1 : leave space for message terminating '\0' */
-               count = min_t(size_t, iov_iter_count(from),
-                             max_payload - writer->b_off - 1);
+               c = min_t(size_t, iov_iter_count(from),
+                         max_payload - writer->b_off - 1);
 
                do {
 
-                       if (copy_from_iter(writer->buffer + writer->b_off, count, from) != count) {
+                       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, count, '\n');
+                       p = strnrchr(writer->buffer + writer->b_off, c, '\n');
                        if (p) {
                                *p++ = '\0';
                                chunk_len = p - writer->buffer;
                        } else {
-                               writer->buffer[writer->b_off + count++] = '\0';
-                               p = &writer->buffer[writer->b_off + count];
+                               writer->buffer[writer->b_off + c++] = '\0';
+                               p = &writer->buffer[writer->b_off + c];
                                chunk_len = p - writer->buffer;
 
                                BUG_ON(chunk_len > max_payload);
                                if (chunk_len < max_payload ) {
-                                       writer->b_off = writer->b_off + count - 1;
+                                       writer->b_off = writer->b_off + c - 1;
                                        continue;
                                }
 
@@ -659,13 +660,13 @@ static ssize_t logger_write_iter(struct kiocb *iocb, struct iov_iter *from)
                        write_log_data(log, &header, writer, chunk_len);
 
                        /* move the remaining part of the message */
-                       memmove(writer->buffer, p, writer->b_off + count - chunk_len);
+                       memmove(writer->buffer, p, writer->b_off + c - chunk_len);
 
                        /* new b_off points where the rimainder of the string ends */
-                       writer->b_off = writer->b_off + count - chunk_len;
+                       writer->b_off = writer->b_off + c - chunk_len;
                        writer->buffer[writer->b_off] = '\0';
 
-               } while ((count = min_t(size_t, iov_iter_count(from), max_payload - 1)));
+               } while ((c = min_t(size_t, iov_iter_count(from), max_payload - 1)));
 
                /* save for remaining unfinished line */
                writer->b_header = header;