Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 311790
b: refs/heads/master
c: eb02dac
h: refs/heads/master
v: v3
  • Loading branch information
Kay Sievers authored and Greg Kroah-Hartman committed Jul 9, 2012
1 parent 2b744ff commit a15bcd8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 68b6507dc554ba015b5ed5e13b1ed4993cdf4024
refs/heads/master: eb02dac93708f581c99858a19162af8ca2b6bfcb
28 changes: 20 additions & 8 deletions trunk/kernel/printk.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ static DEFINE_RAW_SPINLOCK(logbuf_lock);
/* the next printk record to read by syslog(READ) or /proc/kmsg */
static u64 syslog_seq;
static u32 syslog_idx;
static size_t syslog_partial;

/* index and sequence number of the first record stored in the buffer */
static u64 log_first_seq;
Expand Down Expand Up @@ -890,40 +891,49 @@ static int syslog_print(char __user *buf, int size)

while (size > 0) {
size_t n;
size_t skip;

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;
syslog_partial = 0;
}
if (syslog_seq == log_next_seq) {
raw_spin_unlock_irq(&logbuf_lock);
break;
}

skip = syslog_partial;
msg = log_from_idx(syslog_idx);
n = msg_print_text(msg, true, text, LOG_LINE_MAX);
if (n <= size) {
if (n - syslog_partial <= size) {
/* message fits into buffer, move forward */
syslog_idx = log_next(syslog_idx);
syslog_seq++;
n -= syslog_partial;
syslog_partial = 0;
} else if (!len){
/* partial read(), remember position */
n = size;
syslog_partial += n;
} else
n = 0;
raw_spin_unlock_irq(&logbuf_lock);

if (!n)
break;

len += n;
size -= n;
buf += n;
n = copy_to_user(buf - n, text, n);

if (n) {
len -= n;
if (copy_to_user(buf, text + skip, n)) {
if (!len)
len = -EFAULT;
break;
}

len += n;
size -= n;
buf += n;
}

kfree(text);
Expand Down Expand Up @@ -1107,6 +1117,7 @@ int do_syslog(int type, char __user *buf, int len, bool from_file)
/* messages are gone, move to first one */
syslog_seq = log_first_seq;
syslog_idx = log_first_idx;
syslog_partial = 0;
}
if (from_file) {
/*
Expand All @@ -1129,6 +1140,7 @@ int do_syslog(int type, char __user *buf, int len, bool from_file)
idx = log_next(idx);
seq++;
}
error -= syslog_partial;
}
raw_spin_unlock_irq(&logbuf_lock);
break;
Expand Down

0 comments on commit a15bcd8

Please sign in to comment.