From patchwork Fri Jul 18 14:14:18 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 33863 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pa0-f70.google.com (mail-pa0-f70.google.com [209.85.220.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id EB20520CA0 for ; Fri, 18 Jul 2014 14:14:58 +0000 (UTC) Received: by mail-pa0-f70.google.com with SMTP id lf10sf28106364pab.5 for ; Fri, 18 Jul 2014 07:14:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe:content-type :content-transfer-encoding; bh=14DkYcdg1NmnF/jHgr74MB6Xx2Fa2Yeub/92xEZAc9g=; b=inePe0BeNqPQ00uHErtysssaIzbMU+YmtlI6mVSYIkyBm+vM2Owy5e5ORvck/tv8Ow OOmYMKW+LwTIyd1/xFWbHW9cDDvNzafznjJqnWZv1xwazN9mqXVRfWu5ScC2/cr7OaHE 0cU/Q2HkapU7+hMgBzI9ffo4v6gY2YJkU7CKk2/2R0mtITqfRZ3BpRrCeW4VYaEgKykR TR8f9+T7LcMdR0JWvE/35IcdeOdil2ppaRASxz2yn847kCs19HrQJr5p50VQpNdR+R90 cWfuZZHsBBV6390zR4f/oIDDQK7pZBQW1pth2m5TY8Pi662GY2ZTTTZfvM0V31N2EtFl Y6Qw== X-Gm-Message-State: ALoCoQnxvUJkr/rUwxiiw0HhI6yViVSOlOBMb65ppg2vNQEbrigl+J0BjC2ALEkorUQbJCuZ0wFT X-Received: by 10.66.222.138 with SMTP id qm10mr2523186pac.9.1405692898250; Fri, 18 Jul 2014 07:14:58 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.50.30.102 with SMTP id r6ls329697igh.44.canary; Fri, 18 Jul 2014 07:14:58 -0700 (PDT) X-Received: by 10.66.159.34 with SMTP id wz2mr5445731pab.96.1405692898113; Fri, 18 Jul 2014 07:14:58 -0700 (PDT) Received: from mail-vc0-f180.google.com (mail-vc0-f180.google.com [209.85.220.180]) by mx.google.com with ESMTPS id mg6si5826186vec.35.2014.07.18.07.14.48 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 18 Jul 2014 07:14:48 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.180 as permitted sender) client-ip=209.85.220.180; Received: by mail-vc0-f180.google.com with SMTP id ij19so7335435vcb.25 for ; Fri, 18 Jul 2014 07:14:48 -0700 (PDT) X-Received: by 10.52.248.146 with SMTP id ym18mr5401044vdc.8.1405692887163; Fri, 18 Jul 2014 07:14:47 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.37.5 with SMTP id tc5csp14721vcb; Fri, 18 Jul 2014 07:14:46 -0700 (PDT) X-Received: by 10.68.222.136 with SMTP id qm8mr3140439pbc.92.1405692884626; Fri, 18 Jul 2014 07:14:44 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y3si6089123pbw.183.2014.07.18.07.14.43; Fri, 18 Jul 2014 07:14:43 -0700 (PDT) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1945984AbaGROOa (ORCPT + 25 others); Fri, 18 Jul 2014 10:14:30 -0400 Received: from mail-ig0-f169.google.com ([209.85.213.169]:38802 "EHLO mail-ig0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935132AbaGROOZ (ORCPT ); Fri, 18 Jul 2014 10:14:25 -0400 Received: by mail-ig0-f169.google.com with SMTP id r2so973023igi.0 for ; Fri, 18 Jul 2014 07:14:25 -0700 (PDT) X-Received: by 10.50.66.133 with SMTP id f5mr4948758igt.38.1405692864904; Fri, 18 Jul 2014 07:14:24 -0700 (PDT) Received: from localhost.localdomain (c-24-245-18-91.hsd1.mn.comcast.net. [24.245.18.91]) by mx.google.com with ESMTPSA id ga11sm6234171igd.8.2014.07.18.07.14.23 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 18 Jul 2014 07:14:24 -0700 (PDT) From: Alex Elder To: akpm@linux-foundation.org Cc: kay@vrfy.org, pmladek@suse.cz, bp@suse.de, john.stultz@linaro.org, jack@suse.cz, linux-kernel@vger.kernel.org Subject: [PATCH v3 6/7] printk: insert newline in devkmsg_read() Date: Fri, 18 Jul 2014 09:14:18 -0500 Message-Id: <1405692859-32500-7-git-send-email-elder@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1405692859-32500-1-git-send-email-elder@linaro.org> References: <1405692859-32500-1-git-send-email-elder@linaro.org> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: elder@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.180 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , If a log record has LOG_PREFIX set, its predecessor record should be terminated if it was marked LOG_CONT. In devkmsg_read(), this condition was being ignored, which would lead to such records showing up combined when reading /dev/kmsg. Fix this oversight. We should similarly insert a newline in msg_print_text() in this case, to avoid formatted records getting merged. Suggested-by: Petr Mládek Signed-off-by: Alex Elder --- kernel/printk/printk.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index a5c6427..abb129c 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -575,6 +575,7 @@ static ssize_t devkmsg_read(struct file *file, char __user *buf, char cont; size_t len; ssize_t ret; + bool insert_newline; if (!user) return -EBADF; @@ -626,7 +627,10 @@ static ssize_t devkmsg_read(struct file *file, char __user *buf, else cont = '-'; - len = sprintf(user->buf, "%u,%llu,%llu,%c;", + /* Insert a newline if the previous line was not terminated properly */ + insert_newline = (user->prev & LOG_CONT) && (msg->flags & LOG_PREFIX); + len = sprintf(user->buf, "%s%u,%llu,%llu,%c;", + insert_newline ? "\n" : "", (msg->facility << 3) | msg->level, user->seq, ts_usec, cont); user->prev = msg->flags; @@ -999,10 +1003,12 @@ static size_t msg_print_text(const struct printk_log *msg, enum log_flags prev, { const char *text = log_text(msg); size_t text_size = msg->text_len; + size_t len = 0; + bool insert_newline; bool prefix = true; bool newline = true; - size_t len = 0; + insert_newline = (prev & LOG_CONT) && (msg->flags & LOG_PREFIX); if ((prev & LOG_CONT) && !(msg->flags & LOG_PREFIX)) prefix = false; @@ -1023,9 +1029,13 @@ static size_t msg_print_text(const struct printk_log *msg, enum log_flags prev, if (buf) { if (print_prefix(msg, syslog, NULL) + - text_len + 1 >= size - len) + text_len + 2 >= size - len) break; + if (insert_newline) { + insert_newline = false; + buf[len++] = '\n'; + } if (prefix) len += print_prefix(msg, syslog, buf + len); memcpy(buf + len, text, text_len); @@ -1034,6 +1044,8 @@ static size_t msg_print_text(const struct printk_log *msg, enum log_flags prev, buf[len++] = '\n'; } else { /* SYSLOG_ACTION_* buffer size only calculation */ + if (insert_newline) + len++; if (prefix) len += print_prefix(msg, syslog, NULL); len += text_len;