[prev in list] [next in list] [prev in thread] [next in thread] 

List:       git-commits-head
Subject:    syslog: fill buffer with more than a single message for SYSLOG_ACTION_READ
From:       "Linux Kernel Mailing List" <linux-kernel () vger ! kernel ! org>
Date:       2012-06-30 18:23:31
Message-ID: 20120630182331.67AAC3403F1 () ra ! kernel ! org
[Download RAW message or body]

Gitweb:     http://git.kernel.org/linus/;a=commit;h=116e90b23f74d303e8d607c7a7d54f60f14ab9f2
Commit:     116e90b23f74d303e8d607c7a7d54f60f14ab9f2
Parent:     6fda135c908d0f38a0167adcbd71094572e3059b
Author:     Jan Beulich <JBeulich@suse.com>
AuthorDate: Fri Jun 22 16:36:09 2012 +0100
Committer:  Greg Kroah-Hartman <gregkh@linuxfoundation.org>
CommitDate: Tue Jun 26 12:37:36 2012 -0700

    syslog: fill buffer with more than a single message for SYSLOG_ACTION_READ
    
    The recent changes to the printk buffer management resulted in
    SYSLOG_ACTION_READ to only return a single message, whereas previously
    the buffer would get filled as much as possible. As, when too small to
    fit everything, filling it to the last byte would be pretty ugly with
    the new code, the patch arranges for as many messages as possible to
    get returned in a single invocation. User space tools in at least all
    SLES versions depend on the old behavior.
    
    This at once addresses the issue attempted to get fixed with commit
    b56a39ac263e5b8cafedd551a49c2105e68b98c2 ("printk: return -EINVAL if
    the message len is bigger than the buf size"), and since that commit
    widened the possibility for losing a message altogether, the patch
    here assumes that this other commit would get reverted first
    (otherwise the patch here won't apply).
    
    Furthermore, this patch also addresses the problem dealt with in
    commit 4a77a5a06ec66ed05199b301e7c25f42f979afdc ("printk: use mutex
    lock to stop syslog_seq from going wild"), so I'd recommend reverting
    that one too (albeit there's no direct collision between the two).
    
    Signed-off-by: Jan Beulich <jbeulich@suse.com>
    Acked-by: Kay Sievers <kay@vrfy.org>
    Cc: Yuanhan Liu <yuanhan.liu@linux.intel.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 kernel/printk.c |   51 +++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 37 insertions(+), 14 deletions(-)

diff --git a/kernel/printk.c b/kernel/printk.c
index ff05361..cdfba44 100644
--- a/kernel/printk.c
+++ b/kernel/printk.c
@@ -862,26 +862,49 @@ static int syslog_print(char __user *buf, int size)
 {
 	char *text;
 	struct log *msg;
-	int len;
+	int len = 0;
 
 	text = kmalloc(LOG_LINE_MAX, GFP_KERNEL);
 	if (!text)
 		return -ENOMEM;
 
-	raw_spin_lock_irq(&logbuf_lock);
-	if (syslog_seq < log_first_seq) {
-		/* messages are gone, move to first one */
-		syslog_seq = log_first_seq;
-		syslog_idx = log_first_idx;
-	}
-	msg = log_from_idx(syslog_idx);
-	len = msg_print_text(msg, true, text, LOG_LINE_MAX);
-	syslog_idx = log_next(syslog_idx);
-	syslog_seq++;
-	raw_spin_unlock_irq(&logbuf_lock);
+	while (size > 0) {
+		size_t n;
+
+		raw_spin_lock_irq(&logbuf_lock);
+		if (syslog_seq < log_first_seq) {
+			/* messages are gone, move to first one */
+			syslog_seq = log_first_seq;
+			syslog_idx = log_first_idx;
+		}
+		if (syslog_seq == log_next_seq) {
+			raw_spin_unlock_irq(&logbuf_lock);
+			break;
+		}
+		msg = log_from_idx(syslog_idx);
+		n = msg_print_text(msg, true, text, LOG_LINE_MAX);
+		if (n <= size) {
+			syslog_idx = log_next(syslog_idx);
+			syslog_seq++;
+		} else
+			n = 0;
+		raw_spin_unlock_irq(&logbuf_lock);
+
+		if (!n)
+			break;
 
-	if (len > 0 && copy_to_user(buf, text, len))
-		len = -EFAULT;
+		len += n;
+		size -= n;
+		buf += n;
+		n = copy_to_user(buf - n, text, n);
+
+		if (n) {
+			len -= n;
+			if (!len)
+				len = -EFAULT;
+			break;
+		}
+	}
 
 	kfree(text);
 	return len;
--
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic