Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp627710img; Thu, 21 Mar 2019 05:47:18 -0700 (PDT) X-Google-Smtp-Source: APXvYqyqh0eL3jfs3z5kEH7exQagyLtwlYUax6IKBJgdVe+nMVqvj8OvfXj4kFAFPP8AjnP0ARut X-Received: by 2002:a63:4342:: with SMTP id q63mr3142304pga.6.1553172438241; Thu, 21 Mar 2019 05:47:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553172438; cv=none; d=google.com; s=arc-20160816; b=BvlBc2IBHlkSdlPDewzOabEw+EbyLE8DfUxGudtfsaKGfFTapX0ssU1pg0HA2ujqyK NNQWVX1R0NETGXi8dcNHsuBobZ9Y3+MnCfFx51PBUpD15zqJj61ZAS5F+vVmVaNzK5cS z4/R/tWcBJFDUaj8y0E+z6QO27uQnqwqSu/R6nAFqGYyqgLhtTwrgS5wdP16AdRQq4w/ a6RrmWo+7KqhvlxxOxhnRSlA5dI7LfxJm0jQLfRLS8bO1BKcZMy5zyYGfuT7V/V8ElBe RVAUs3PKCXLDKs+JxzckVnn8lcrjXhzCOrJqqZbXBlJ7iwA5gtXXCRyjwVgdumI4XDyL +1JQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=ViJWh9ZrwWvIKoJ44rN4qMVeBwgakDCxTdLutMxByS8=; b=R5v/52PmLSZGipU3UxxV8EB10KFlwOAVVYLAhTO+RhrTRQAMBOFQkqv+VBptMTm+eW bnaguqqH7tTY+NwNZF8Bm8LXm9Eq1s4B1AJLKrOAPIPtHMur33oNd+jtuQn5NH/QFsIm esIik969LVSsx6UPmIFJ03TN4QQ0Bq3YrUf7o3dxUCzKGzjdb8VC79iVWD2BRhfg+PUg 4+MhJzbRYq2TqvgDfRKEc1d88WV1rPfaXX3ZtJvc5VyDF8J39AEoaCaMBdE6twdbqqCj og9/jiH0VleNIJSZE981exy88E75mjSmL2IWOKPxTJsXMvx98+223LW4XCCZXA8dc+Ar 9mUQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f66si4712855plb.261.2019.03.21.05.47.00; Thu, 21 Mar 2019 05:47:18 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728223AbfCUMp4 (ORCPT + 99 others); Thu, 21 Mar 2019 08:45:56 -0400 Received: from avasout02.plus.net ([212.159.14.17]:56870 "EHLO avasout02.plus.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728049AbfCUMpz (ORCPT ); Thu, 21 Mar 2019 08:45:55 -0400 X-Greylist: delayed 450 seconds by postgrey-1.27 at vger.kernel.org; Thu, 21 Mar 2019 08:45:55 EDT Received: from deneb ([80.229.24.9]) by smtp with ESMTP id 6wxihzn5H2SW56wxjhK9e7; Thu, 21 Mar 2019 12:38:24 +0000 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.3 cv=NtavjPVJ c=1 sm=1 tr=0 a=E/9URZZQ5L3bK/voZ0g0HQ==:117 a=E/9URZZQ5L3bK/voZ0g0HQ==:17 a=jpOVt7BSZ2e4Z31A5e1TngXxSK0=:19 a=kj9zAlcOel0A:10 a=NTGMnVQrEZIA:10 a=-An2I_7KAAAA:8 a=CCpqsmhAAAAA:8 a=q6MwtBc8aigTzGVEUL4A:9 a=CjuIK1q_8ugA:10 a=Sq34B_EcNBM9_nrAYB9S:22 a=ul9cdbp4aOFLsgKbc677:22 Received: from mac by deneb with local (Exim 4.89) (envelope-from ) id 1h6wxi-0001db-8t; Thu, 21 Mar 2019 12:38:22 +0000 Date: Thu, 21 Mar 2019 12:38:22 +0000 From: Mike Crowe To: Alexander Sverdlin Cc: linux-kernel@vger.kernel.org, Andrew Morton , Arnd Bergmann , Kay Sievers , Greg Kroah-Hartman Subject: Re: kmsg: lseek errors confuse glibc's dprintf Message-ID: <20190321123822.npfxumj2gwlwkxlf@mcrowe.com> References: <20150115173132.GA7486@mcrowe.com> <20190321104726.3c570c41e5757611a13c23ca@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190321104726.3c570c41e5757611a13c23ca@gmail.com> User-Agent: NeoMutt/20170113 (1.7.2) X-CMAE-Envelope: MS4wfDsl0i2Sw2eLevf/cEFsrs7B6Xa7cAKgbOBT1ohV7GeIFZRJLD9AmhroT3NG9Im4EHuJ0GYR56Za1aIsiJb/bKiDJIox2ACaqtnYhTVmWy6p1zRQr792 szFRdYcGV0zwqj/aOaNfFpBgMkuv455NjPo/ldQ1YO4evKWFHvdNWS3w Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thursday 21 March 2019 at 10:47:26 +0100, Alexander Sverdlin wrote: > Hello Mike and all, > > On Thu, 15 Jan 2015 17:31:32 +0000 > Mike Crowe wrote: > > > glibc's dprintf implementation does not work correctly with /dev/kmsg file > > descriptors because glibc treats receiving EBADF and EINVAL from lseek when > > trying to determine the current file position as errors. See > > https://sourceware.org/bugzilla/show_bug.cgi?id=17830 > > we need to conclude on this issue. This is a real bug which is ignored > for 4 years now. Mike, would you like to re-send a formal patch? > I can do it as well, preserving a link to your original patch/report. > In case you'd like to post it yourself, I can be a tester and/or > provide a reproducer. Hi Alexander, I'm sorry for dropping the ball on this. I think I was travelling at the time. :( Thank you for picking it up. I don't mind rebasing my patch once I know which of my two solutions is preferred. It seems that the -ESPIPE one is the current favourite. Thanks. > > >>From what I can tell prior to Kay Sievers printk record commit > > e11fea92e13fb91c50bacca799a6131c81929986, calling lseek(fd, 0, SEEK_CUR) > > with such a file descriptor would not return an error. > > > > Prior to Kay's change, Arnd Bergmann's commit > > 6038f373a3dc1f1c26496e60b6c40b164716f07e seemed to go to some lengths to > > preserve the successful return code rather than returning (the perhaps more > > logical) -ESPIPE. > > > > glibc is happy with either a successful return or -ESPIPE. > > > > For maximum compatibility it seems that success should be returned but > > given Kay's new seek interface perhaps this isn't helpful. > > > > This patch ensures that such a seek succeeds: > > > > diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c > > index 02d6b6d..b3ff6f0 100644 > > --- a/kernel/printk/printk.c > > +++ b/kernel/printk/printk.c > > @@ -693,7 +693,7 @@ static loff_t devkmsg_llseek(struct file *file, loff_t offset, int whence) > > loff_t ret = 0; > > > > if (!user) > > - return -EBADF; > > + return (whence == SEEK_CUR) ? 0 : -EBADF; > > if (offset) > > return -ESPIPE; > > > > @@ -718,6 +718,11 @@ static loff_t devkmsg_llseek(struct file *file, loff_t offset, int whence) > > user->idx = log_next_idx; > > user->seq = log_next_seq; > > break; > > + case SEEK_CUR: > > + /* For compatibility with userspace requesting the > > + * current file position. */ > > + ret = 0; > > + break; > > default: > > ret = -EINVAL; > > } > > > > (although it could be argued that the !user case should return -ESPIPE > > rather than EBADF since the file descriptor _is_ valid.) > > > > and this patch causes a failure that glibc is prepared to accept: > > > > diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c > > index 02d6b6d..f6b0c93 100644 > > --- a/kernel/printk/printk.c > > +++ b/kernel/printk/printk.c > > @@ -693,7 +693,7 @@ static loff_t devkmsg_llseek(struct file *file, loff_t offset, int whence) > > loff_t ret = 0; > > > > if (!user) > > - return -EBADF; > > + return -ESPIPE; > > if (offset) > > return -ESPIPE; > > > > @@ -718,6 +718,11 @@ static loff_t devkmsg_llseek(struct file *file, loff_t offset, int whence) > > user->idx = log_next_idx; > > user->seq = log_next_seq; > > break; > > + case SEEK_CUR: > > + /* For compatibility with userspace expecting SEEK_CUR > > + * to not yield EINVAL. */ > > + ret = -ESPIPE; > > + break; > > default: > > ret = -EINVAL; > > } > > > > Either makes dprintf work, but is either the right solution? Mike.