aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2016-10-09 15:16:57 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2016-10-09 15:23:40 -0400
commitbfd8d3f23b51018388be0411ccbc2d56277fe294 (patch)
tree2dcf9d0557488349f4753838b6c689986dcf536c
parent5e467652ffefb84b1159d5d8fda665c48e5fd840 (diff)
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>
-rw-r--r--kernel/printk/printk.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index f6fe60d725dd..170d3a8040f4 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -783,6 +783,8 @@ static ssize_t devkmsg_write(struct kiocb *iocb, struct iov_iter *from)
783 return ret; 783 return ret;
784} 784}
785 785
786static void cont_flush(void);
787
786static ssize_t devkmsg_read(struct file *file, char __user *buf, 788static ssize_t devkmsg_read(struct file *file, char __user *buf,
787 size_t count, loff_t *ppos) 789 size_t count, loff_t *ppos)
788{ 790{
@@ -798,6 +800,7 @@ static ssize_t devkmsg_read(struct file *file, char __user *buf,
798 if (ret) 800 if (ret)
799 return ret; 801 return ret;
800 raw_spin_lock_irq(&logbuf_lock); 802 raw_spin_lock_irq(&logbuf_lock);
803 cont_flush();
801 while (user->seq == log_next_seq) { 804 while (user->seq == log_next_seq) {
802 if (file->f_flags & O_NONBLOCK) { 805 if (file->f_flags & O_NONBLOCK) {
803 ret = -EAGAIN; 806 ret = -EAGAIN;
@@ -860,6 +863,7 @@ static loff_t devkmsg_llseek(struct file *file, loff_t offset, int whence)
860 return -ESPIPE; 863 return -ESPIPE;
861 864
862 raw_spin_lock_irq(&logbuf_lock); 865 raw_spin_lock_irq(&logbuf_lock);
866 cont_flush();
863 switch (whence) { 867 switch (whence) {
864 case SEEK_SET: 868 case SEEK_SET:
865 /* the first record */ 869 /* the first record */
@@ -898,6 +902,7 @@ static unsigned int devkmsg_poll(struct file *file, poll_table *wait)
898 poll_wait(file, &log_wait, wait); 902 poll_wait(file, &log_wait, wait);
899 903
900 raw_spin_lock_irq(&logbuf_lock); 904 raw_spin_lock_irq(&logbuf_lock);
905 cont_flush();
901 if (user->seq < log_next_seq) { 906 if (user->seq < log_next_seq) {
902 /* return error when data has vanished underneath us */ 907 /* return error when data has vanished underneath us */
903 if (user->seq < log_first_seq) 908 if (user->seq < log_first_seq)
@@ -1284,6 +1289,7 @@ static int syslog_print(char __user *buf, int size)
1284 size_t skip; 1289 size_t skip;
1285 1290
1286 raw_spin_lock_irq(&logbuf_lock); 1291 raw_spin_lock_irq(&logbuf_lock);
1292 cont_flush();
1287 if (syslog_seq < log_first_seq) { 1293 if (syslog_seq < log_first_seq) {
1288 /* messages are gone, move to first one */ 1294 /* messages are gone, move to first one */
1289 syslog_seq = log_first_seq; 1295 syslog_seq = log_first_seq;
@@ -1343,6 +1349,7 @@ static int syslog_print_all(char __user *buf, int size, bool clear)
1343 return -ENOMEM; 1349 return -ENOMEM;
1344 1350
1345 raw_spin_lock_irq(&logbuf_lock); 1351 raw_spin_lock_irq(&logbuf_lock);
1352 cont_flush();
1346 if (buf) { 1353 if (buf) {
1347 u64 next_seq; 1354 u64 next_seq;
1348 u64 seq; 1355 u64 seq;
@@ -1504,6 +1511,7 @@ int do_syslog(int type, char __user *buf, int len, int source)
1504 /* Number of chars in the log buffer */ 1511 /* Number of chars in the log buffer */
1505 case SYSLOG_ACTION_SIZE_UNREAD: 1512 case SYSLOG_ACTION_SIZE_UNREAD:
1506 raw_spin_lock_irq(&logbuf_lock); 1513 raw_spin_lock_irq(&logbuf_lock);
1514 cont_flush();
1507 if (syslog_seq < log_first_seq) { 1515 if (syslog_seq < log_first_seq) {
1508 /* messages are gone, move to first one */ 1516 /* messages are gone, move to first one */
1509 syslog_seq = log_first_seq; 1517 syslog_seq = log_first_seq;
@@ -3016,6 +3024,7 @@ void kmsg_dump(enum kmsg_dump_reason reason)
3016 dumper->active = true; 3024 dumper->active = true;
3017 3025
3018 raw_spin_lock_irqsave(&logbuf_lock, flags); 3026 raw_spin_lock_irqsave(&logbuf_lock, flags);
3027 cont_flush();
3019 dumper->cur_seq = clear_seq; 3028 dumper->cur_seq = clear_seq;
3020 dumper->cur_idx = clear_idx; 3029 dumper->cur_idx = clear_idx;
3021 dumper->next_seq = log_next_seq; 3030 dumper->next_seq = log_next_seq;
@@ -3106,6 +3115,7 @@ bool kmsg_dump_get_line(struct kmsg_dumper *dumper, bool syslog,
3106 bool ret; 3115 bool ret;
3107 3116
3108 raw_spin_lock_irqsave(&logbuf_lock, flags); 3117 raw_spin_lock_irqsave(&logbuf_lock, flags);
3118 cont_flush();
3109 ret = kmsg_dump_get_line_nolock(dumper, syslog, line, size, len); 3119 ret = kmsg_dump_get_line_nolock(dumper, syslog, line, size, len);
3110 raw_spin_unlock_irqrestore(&logbuf_lock, flags); 3120 raw_spin_unlock_irqrestore(&logbuf_lock, flags);
3111 3121
@@ -3148,6 +3158,7 @@ bool kmsg_dump_get_buffer(struct kmsg_dumper *dumper, bool syslog,
3148 goto out; 3158 goto out;
3149 3159
3150 raw_spin_lock_irqsave(&logbuf_lock, flags); 3160 raw_spin_lock_irqsave(&logbuf_lock, flags);
3161 cont_flush();
3151 if (dumper->cur_seq < log_first_seq) { 3162 if (dumper->cur_seq < log_first_seq) {
3152 /* messages are gone, move to first available one */ 3163 /* messages are gone, move to first available one */
3153 dumper->cur_seq = log_first_seq; 3164 dumper->cur_seq = log_first_seq;