From patchwork Mon Jul 21 13:02:36 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 33965 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ie0-f199.google.com (mail-ie0-f199.google.com [209.85.223.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 0A42F20672 for ; Mon, 21 Jul 2014 13:04:19 +0000 (UTC) Received: by mail-ie0-f199.google.com with SMTP id tr6sf59804446ieb.6 for ; Mon, 21 Jul 2014 06:04:19 -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=E2r7PfV600eEbhgc5eqLJ9f3L9g7paPCyMR7ZXi7cK8=; b=cU8GdAEsVWL53LVRR43HCmVGVrEqbQHg/3OIsbf0ndc4MHxWaz/kc771QGC7xf+pXB vkFBs7ItHarXy7A+AHVnR+L3RYqetCmS0HY7cYR4p1XTpkMJrZjJCTBkj2agwCeZZWMg wpkZhpeMFUpEEvKThvZTBWoHv4UnyH7m9crFOOF08ER7CLGKowQp8ucGeCqjS2EPMsRl ApDk14au90NDfHRHUaNsbYptPmJvsu0UoF3Tf77JVA0jlTZ4RYJtp/73KOjZQ9M/yxsB /QvP27+MJzWID6gnA1CIPdArU/1rzNdPBGN33JFohDm4WCqZe01yjhgd9o873PThJgd2 hDnA== X-Gm-Message-State: ALoCoQkTwcRpIwqTnISJ7xggWtHbxwjwPdcNdNlz+EOreQmqF9LEOJ72S9qUQjpcLhC/wd7Gr/PJ X-Received: by 10.42.119.148 with SMTP id b20mr3678185icr.33.1405947859353; Mon, 21 Jul 2014 06:04:19 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.38.51 with SMTP id s48ls1996291qgs.64.gmail; Mon, 21 Jul 2014 06:04:19 -0700 (PDT) X-Received: by 10.52.253.140 with SMTP id aa12mr24533884vdd.11.1405947859163; Mon, 21 Jul 2014 06:04:19 -0700 (PDT) Received: from mail-vc0-f179.google.com (mail-vc0-f179.google.com [209.85.220.179]) by mx.google.com with ESMTPS id gt8si11232963vdc.53.2014.07.21.06.04.16 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 21 Jul 2014 06:04:16 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.179 as permitted sender) client-ip=209.85.220.179; Received: by mail-vc0-f179.google.com with SMTP id hq11so10356429vcb.24 for ; Mon, 21 Jul 2014 06:04:16 -0700 (PDT) X-Received: by 10.220.118.136 with SMTP id v8mr11270487vcq.50.1405947856915; Mon, 21 Jul 2014 06:04:16 -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 tc5csp110430vcb; Mon, 21 Jul 2014 06:04:16 -0700 (PDT) X-Received: by 10.68.65.69 with SMTP id v5mr1968707pbs.156.1405947855911; Mon, 21 Jul 2014 06:04:15 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id pi7si7108219pdb.355.2014.07.21.06.04.15 for ; Mon, 21 Jul 2014 06:04:15 -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 S1755198AbaGUNEM (ORCPT + 13 others); Mon, 21 Jul 2014 09:04:12 -0400 Received: from mail-ie0-f178.google.com ([209.85.223.178]:40782 "EHLO mail-ie0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753118AbaGUNCk (ORCPT ); Mon, 21 Jul 2014 09:02:40 -0400 Received: by mail-ie0-f178.google.com with SMTP id tp5so6800903ieb.9 for ; Mon, 21 Jul 2014 06:02:40 -0700 (PDT) X-Received: by 10.42.154.132 with SMTP id q4mr13097338icw.4.1405947759959; Mon, 21 Jul 2014 06:02:39 -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 ri8sm38580163igc.0.2014.07.21.06.02.39 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 21 Jul 2014 06:02:39 -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 v5 2/7] printk: insert newline for truncated records Date: Mon, 21 Jul 2014 08:02:36 -0500 Message-Id: <1405947761-26004-3-git-send-email-elder@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1405947761-26004-1-git-send-email-elder@linaro.org> References: <1405947761-26004-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.179 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 Mladek --- 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;