From owner-svn-src-all@freebsd.org Thu Dec 31 04:10:42 2015 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 9BAD2A57ADC; Thu, 31 Dec 2015 04:10:42 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from mail104.syd.optusnet.com.au (mail104.syd.optusnet.com.au [211.29.132.246]) by mx1.freebsd.org (Postfix) with ESMTP id 671BD1F08; Thu, 31 Dec 2015 04:10:42 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from c211-30-166-197.carlnfd1.nsw.optusnet.com.au (c211-30-166-197.carlnfd1.nsw.optusnet.com.au [211.30.166.197]) by mail104.syd.optusnet.com.au (Postfix) with ESMTPS id 70938422065; Thu, 31 Dec 2015 15:10:32 +1100 (AEDT) Date: Thu, 31 Dec 2015 15:10:32 +1100 (EST) From: Bruce Evans X-X-Sender: bde@besplex.bde.org cc: "Jonathan T. Looney" , src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: Re: svn commit: r292955 - head/lib/libmd In-Reply-To: <20151231115651.R995@besplex.bde.org> Message-ID: <20151231143314.Y1520@besplex.bde.org> References: <201512301804.tBUI4oGp065466@repo.freebsd.org> <20151231115651.R995@besplex.bde.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Optus-CM-Score: 0 X-Optus-CM-Analysis: v=2.1 cv=R4L+YolX c=1 sm=1 tr=0 a=KA6XNC2GZCFrdESI5ZmdjQ==:117 a=PO7r1zJSAAAA:8 a=9cW_t1CCXrUA:10 a=JzwRw_2MAAAA:8 a=kj9zAlcOel0A:10 a=nkSGdXzS_FKU9MRdIc0A:9 a=CjuIK1q_8ugA:10 X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 31 Dec 2015 04:10:42 -0000 On Thu, 31 Dec 2015, Bruce Evans wrote: > > wc /proc/0/* works. md5 works like wc using a hack to avoid calling this > broken function. E.g., > > for i in $(ls /proc/0/*); do echo -n "$i: "; md5 <$i; done # gives > > /proc/0/cmdline: 3c5896b1ac441f4998f052e2126e8d20 > /proc/0/ctl: d41d8cd98f00b204e9800998ecf8427e > /proc/0/etype: 674441960ca1ba2de08ad4e50c9fde98 > /proc/0/rlimit: 67d6ad67b412e1bceb7cb508a3492197 > /proc/0/status: 3ccc3067b97c3232ea2dbcb64c458fd4 Further examples: md5 # on terminal input works correctly by not using MDXFileChunk(). md5 /dev/stdin # on the same terminal input produces the d41d8cd98f00b204e9800998ecf8427e garbage using MDXFileChunk(). truss shows that lseek() is broken too -- MDXFileChunk() tries it and it succeeds on the unseekable file /dev/stdin. Bugs in this area are common. E.g., lseek() on named pipes was broken so that it succeeded, by rearranging the plumbing use fileops more or less and not attaching lseek right. cat | md5 # on the same terminal input works correctly by not using MDXFileChunk(). cat | md5 /dev/stdin # on the same terminal input doesn't work correctly, but it fails better than without the pipe. Now a seek error occurs and is reported as "md5: /dev/stdin: Illegal seek" (I can't see where it is reported). Then md5 exits. Then cat waits to read input. Then cat fails to write output and is killed by SIGPIPE. So md5 handled the seek error in a fail-safe though incorrect way. One correct way is to fall back to the working code, but it is better to just use that without an lseek check. It is a bug that [l]stat() on /dev/stdin sees the device file and not the actual stdin file. md5 can't work around this except by not using stat(). Bruce