Skip to content

Commit bfd8d3f

Browse files
committed
printk: make reading the kernel log flush pending lines
That will mean that any possible subsequent continuation will now be broken up onto a line of its own (since reading the log has finalized the beginning og the line), but if user space has activated system logging (or if there's a kernel message dump going on) that is the right thing to do. And now that we actually get the continuation flags _right_ for this all, the user space logger that is reading the kernel messages can actually see the continuation marker. Not that anybody seems to really bother with it (or care), but in theory user space can do its own message stitching. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 5e46765 commit bfd8d3f

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

‎kernel/printk/printk.c‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,8 @@ static ssize_t devkmsg_write(struct kiocb *iocb, struct iov_iter *from)
783783
return ret;
784784
}
785785

786+
static void cont_flush(void);
787+
786788
static ssize_t devkmsg_read(struct file *file, char __user *buf,
787789
size_t count, loff_t *ppos)
788790
{
@@ -798,6 +800,7 @@ static ssize_t devkmsg_read(struct file *file, char __user *buf,
798800
if (ret)
799801
return ret;
800802
raw_spin_lock_irq(&logbuf_lock);
803+
cont_flush();
801804
while (user->seq == log_next_seq) {
802805
if (file->f_flags & O_NONBLOCK) {
803806
ret = -EAGAIN;
@@ -860,6 +863,7 @@ static loff_t devkmsg_llseek(struct file *file, loff_t offset, int whence)
860863
return -ESPIPE;
861864

862865
raw_spin_lock_irq(&logbuf_lock);
866+
cont_flush();
863867
switch (whence) {
864868
case SEEK_SET:
865869
/* the first record */
@@ -898,6 +902,7 @@ static unsigned int devkmsg_poll(struct file *file, poll_table *wait)
898902
poll_wait(file, &log_wait, wait);
899903

900904
raw_spin_lock_irq(&logbuf_lock);
905+
cont_flush();
901906
if (user->seq < log_next_seq) {
902907
/* return error when data has vanished underneath us */
903908
if (user->seq < log_first_seq)
@@ -1284,6 +1289,7 @@ static int syslog_print(char __user *buf, int size)
12841289
size_t skip;
12851290

12861291
raw_spin_lock_irq(&logbuf_lock);
1292+
cont_flush();
12871293
if (syslog_seq < log_first_seq) {
12881294
/* messages are gone, move to first one */
12891295
syslog_seq = log_first_seq;
@@ -1343,6 +1349,7 @@ static int syslog_print_all(char __user *buf, int size, bool clear)
13431349
return -ENOMEM;
13441350

13451351
raw_spin_lock_irq(&logbuf_lock);
1352+
cont_flush();
13461353
if (buf) {
13471354
u64 next_seq;
13481355
u64 seq;
@@ -1504,6 +1511,7 @@ int do_syslog(int type, char __user *buf, int len, int source)
15041511
/* Number of chars in the log buffer */
15051512
case SYSLOG_ACTION_SIZE_UNREAD:
15061513
raw_spin_lock_irq(&logbuf_lock);
1514+
cont_flush();
15071515
if (syslog_seq < log_first_seq) {
15081516
/* messages are gone, move to first one */
15091517
syslog_seq = log_first_seq;
@@ -3016,6 +3024,7 @@ void kmsg_dump(enum kmsg_dump_reason reason)
30163024
dumper->active = true;
30173025

30183026
raw_spin_lock_irqsave(&logbuf_lock, flags);
3027+
cont_flush();
30193028
dumper->cur_seq = clear_seq;
30203029
dumper->cur_idx = clear_idx;
30213030
dumper->next_seq = log_next_seq;
@@ -3106,6 +3115,7 @@ bool kmsg_dump_get_line(struct kmsg_dumper *dumper, bool syslog,
31063115
bool ret;
31073116

31083117
raw_spin_lock_irqsave(&logbuf_lock, flags);
3118+
cont_flush();
31093119
ret = kmsg_dump_get_line_nolock(dumper, syslog, line, size, len);
31103120
raw_spin_unlock_irqrestore(&logbuf_lock, flags);
31113121

@@ -3148,6 +3158,7 @@ bool kmsg_dump_get_buffer(struct kmsg_dumper *dumper, bool syslog,
31483158
goto out;
31493159

31503160
raw_spin_lock_irqsave(&logbuf_lock, flags);
3161+
cont_flush();
31513162
if (dumper->cur_seq < log_first_seq) {
31523163
/* messages are gone, move to first available one */
31533164
dumper->cur_seq = log_first_seq;

0 commit comments

Comments
 (0)