From patchwork Tue Jul 22 12:13:45 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 34085 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-vc0-f197.google.com (mail-vc0-f197.google.com [209.85.220.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 15D9120672 for ; Tue, 22 Jul 2014 12:14:07 +0000 (UTC) Received: by mail-vc0-f197.google.com with SMTP id ij19sf24247880vcb.0 for ; Tue, 22 Jul 2014 05:14:06 -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=mG8+SHLnF6QOxKoTq7MuUhW6kn5HaTI52LdxQ1zvRHg=; b=Qyo3I60pYRyRKu9PBwd7LhuVPoMC0oA4cUqX9PvWycij4D2D7XcS/IGUcdoNYnCFGa X3KieHDrmRyfItGrO0wHF2VFpJ9E6dDIaDB0HDjI8fMr7O3So+yIP4FPLbMQqRobjs0u eAPsDWUAiuaV6WkkTj/k9a7BpBwTvhG/gN8I8Ahh12QX/XePeFZUffEdYVSahyYMRZhV y9FbY2Nzm2Zp5sake2+ofDUZQKZTTvYuYVUUjqTi929j1GBUHb04NlDh0/bG4hNxj5GL DW/OSPn+5Bug3ZmmMcL0xM3beUATlvgXp5nnd8P386Z+A0u1rgN4EpF5cXS6wOUexto0 0tkg== X-Gm-Message-State: ALoCoQk/MYmoHuIxM0S4mrtj3OJZGiZR3xUY1Bl4JbeA8K/PgN7IZEbf6Ii1gDFQ9Hca/l+JnTMU X-Received: by 10.224.46.3 with SMTP id h3mr15816907qaf.1.1406031246815; Tue, 22 Jul 2014 05:14:06 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.88.85 with SMTP id s79ls81668qgd.22.gmail; Tue, 22 Jul 2014 05:14:06 -0700 (PDT) X-Received: by 10.52.239.6 with SMTP id vo6mr18348862vdc.59.1406031246719; Tue, 22 Jul 2014 05:14:06 -0700 (PDT) Received: from mail-vc0-f171.google.com (mail-vc0-f171.google.com [209.85.220.171]) by mx.google.com with ESMTPS id r1si337822vcx.25.2014.07.22.05.14.06 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 22 Jul 2014 05:14:06 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.171 as permitted sender) client-ip=209.85.220.171; Received: by mail-vc0-f171.google.com with SMTP id hq11so13201461vcb.30 for ; Tue, 22 Jul 2014 05:14:06 -0700 (PDT) X-Received: by 10.52.244.138 with SMTP id xg10mr33380858vdc.40.1406031246636; Tue, 22 Jul 2014 05:14:06 -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 tc5csp190730vcb; Tue, 22 Jul 2014 05:14:06 -0700 (PDT) X-Received: by 10.68.112.225 with SMTP id it1mr22364761pbb.23.1406031245643; Tue, 22 Jul 2014 05:14:05 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h9si103639pdn.499.2014.07.22.05.14.04 for ; Tue, 22 Jul 2014 05:14:04 -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 S1755374AbaGVMNw (ORCPT + 12 others); Tue, 22 Jul 2014 08:13:52 -0400 Received: from mail-ie0-f174.google.com ([209.85.223.174]:60502 "EHLO mail-ie0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755332AbaGVMNt (ORCPT ); Tue, 22 Jul 2014 08:13:49 -0400 Received: by mail-ie0-f174.google.com with SMTP id rp18so8032112iec.33 for ; Tue, 22 Jul 2014 05:13:48 -0700 (PDT) X-Received: by 10.50.18.82 with SMTP id u18mr15794410igd.46.1406031228469; Tue, 22 Jul 2014 05:13:48 -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 tp4sm21112991igb.9.2014.07.22.05.13.47 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 22 Jul 2014 05:13:48 -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 v6 2/7] printk: insert newline for truncated records Date: Tue, 22 Jul 2014 07:13:45 -0500 Message-Id: <1406031230-18107-3-git-send-email-elder@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1406031230-18107-1-git-send-email-elder@linaro.org> References: <1406031230-18107-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.171 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 Reviewed-by: Petr Mládek --- kernel/printk/printk.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index ffc9928..9f11eab 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; @@ -625,7 +626,10 @@ static ssize_t devkmsg_read(struct file *file, char __user *buf, ((user->prev & LOG_CONT) && !(msg->flags & LOG_PREFIX))) 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; @@ -1013,6 +1017,12 @@ static size_t msg_print_text(const struct printk_log *msg, enum log_flags prev, newline = false; } + if ((prev & LOG_CONT) && (msg->flags & LOG_PREFIX) && len < size) { + if (buf) + buf[len++] = '\n'; + else + len++; + } do { const char *next = memchr(text, '\n', text_size); size_t text_len;