Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp1114614ybh; Thu, 12 Mar 2020 17:37:04 -0700 (PDT) X-Google-Smtp-Source: ADFU+vue8RdvzQSU9Ay+EMgjOHL2YcReTyveXPNNCz3WuJkpOZvok9RsyDu9J2fAYx+zP3uYJblc X-Received: by 2002:a54:4501:: with SMTP id l1mr5005483oil.33.1584059824190; Thu, 12 Mar 2020 17:37:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584059824; cv=none; d=google.com; s=arc-20160816; b=wJbedLQdtwDYq13Tqsj9RksvVC/kECQ5VWm78d9mpVy571zy6/a5gmyvQAV/nXBZMd 5Y0btvdvipMgWdFtsJcG8BUillztTwS3ki2ajd486SavTCHBYKobif/UL7K5HUZ1UDOW eSDslHrtPrXP84DdbwkP6FlbNc6zEgPCPO7BNE4/eLDX0METyDSSMmEJZ1qjQW6MKhVH yCtEhyd2JDET63KfM/0G+4Davl482s2gJ2vDa+PVtQUwd4OJEs+Kh0Xl+Jm/NSBX9ZzV lkPlyS4A7Era/sCL41E3T38LF7mrnpVmgauivUAZbhmBwRIZjbQuOiXA0Aysa5BXSmhm 7SDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=zevsMC0uowAKEZtQLATwyqk885Y78IJeVZqy5nvGUjY=; b=WS2wo1WFDNFsmzuCtFSCSWb5teTB5Ml0HZfKYZN8j8TNt0cxtWAjtsNgIiFlFxIKWd siVyhAtv4E9f6NdMqbWoE307NZFTezFs0H65g242sidDNaSG7V1j5Q8lC1Qozc85dUza IBGgzRk9LmJoYW2E612hBQ6mLz1gteyUeFZWPyjhVjNWhFsDUUsNzK2A3I054/ubIUdK jjzrqcLgR6cny73eGN+tm/qwESMoAbaONqaD4EoYo1KHGgZQIOSNnhZwy0yA04XvHexL S/KQ5DlVgT+PcYDH526/iU8YXS89I/TydaorYmRJqq/FX2VLAms973+VV7i7o7ac/E4L E8fw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=CTGbH6It; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a185si3622570oii.252.2020.03.12.17.36.50; Thu, 12 Mar 2020 17:37:04 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=CTGbH6It; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726971AbgCMAfp (ORCPT + 99 others); Thu, 12 Mar 2020 20:35:45 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:42238 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726898AbgCMAfp (ORCPT ); Thu, 12 Mar 2020 20:35:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584059744; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=zevsMC0uowAKEZtQLATwyqk885Y78IJeVZqy5nvGUjY=; b=CTGbH6ItRUldNME4Pe3Kiy9LW19wcgZLHsM0qUICc4Y5cW5ej1tHM34WKMJ87JY+bg3Sbo QHCTl5EmwUmnfosCe9MvGl+BPvGLt1YNM+rhO8JWAuG2Q33k6NYbUS8jm2fHtpiYnozVqe qmmmEczlny3AK8RatW02RyluoW9PnC8= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-257-JKPR12MkNUy4Gv_xan9-CA-1; Thu, 12 Mar 2020 20:35:40 -0400 X-MC-Unique: JKPR12MkNUy4Gv_xan9-CA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DE5EA107ACC7; Fri, 13 Mar 2020 00:35:38 +0000 (UTC) Received: from localhost (ovpn-121-102.rdu2.redhat.com [10.10.121.102]) by smtp.corp.redhat.com (Postfix) with ESMTP id C667F60C63; Fri, 13 Mar 2020 00:35:35 +0000 (UTC) From: Bruno Meneguele To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: pmladek@suse.com, sergey.senozhatsky@gmail.com, rostedt@goodmis.org, Bruno Meneguele Subject: [PATCH] kernel/printk: add kmsg SEEK_CUR handling Date: Thu, 12 Mar 2020 21:35:33 -0300 Message-Id: <20200313003533.2203429-1-bmeneg@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Userspace libraries, e.g. glibc's dprintf(), expect the default return va= lue for invalid seek situations: -ESPIPE, but when the IO was over /dev/kmsg = the current state of kernel code was returning the generic case of an -EINVAL= . Hence, userspace programs were not behaving as expected or documented. With this patch we add SEEK_CUR case returning the expected value and als= o a simple mention of it in kernel's documentation for those relying on that = for guidance. Signed-off-by: Bruno Meneguele --- Documentation/ABI/testing/dev-kmsg | 2 ++ kernel/printk/printk.c | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/Documentation/ABI/testing/dev-kmsg b/Documentation/ABI/testi= ng/dev-kmsg index f307506eb54c..8533d28e6fda 100644 --- a/Documentation/ABI/testing/dev-kmsg +++ b/Documentation/ABI/testing/dev-kmsg @@ -56,6 +56,8 @@ Description: The /dev/kmsg character device node provid= es userspace access seek after the last record available at the time the last SYSLOG_ACTION_CLEAR was issued. =20 + While SEEK_CUR sets -ESPIPE (invalid seek) to errno. + The output format consists of a prefix carrying the syslog prefix including priority and facility, the 64 bit message sequence number and the monotonic timestamp in microseconds, diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index ad4606234545..d02606723d2d 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -963,6 +963,10 @@ static loff_t devkmsg_llseek(struct file *file, loff= _t offset, int whence) user->idx =3D log_next_idx; user->seq =3D log_next_seq; break; + case SEEK_CUR: + /* return the default errno for invalid seek */ + ret =3D -ESPIPE; + break; default: ret =3D -EINVAL; } --=20 2.24.1