From owner-svn-src-all@freebsd.org Tue Dec 11 22:42:05 2018 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 23DF41318B33; Tue, 11 Dec 2018 22:42:05 +0000 (UTC) (envelope-from devin@shxd.cx) Received: from shxd.cx (mail.shxd.cx [64.201.244.140]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id BB8997219E; Tue, 11 Dec 2018 22:42:04 +0000 (UTC) (envelope-from devin@shxd.cx) Received: from [76.77.180.168] (port=64831 helo=eskarina.lan) by shxd.cx with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.77 (FreeBSD)) (envelope-from ) id 1gWqj5-000Gl2-JF; Tue, 11 Dec 2018 14:42:03 -0800 Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 11.5 \(3445.9.1\)) Subject: Re: svn commit: r341803 - head/libexec/rc From: Devin Teske In-Reply-To: Date: Tue, 11 Dec 2018 14:42:02 -0800 Cc: Devin Teske , src-committers , svn-src-all@freebsd.org, svn-src-head@freebsd.org Content-Transfer-Encoding: quoted-printable Message-Id: <917251B0-00E0-47E2-B6FB-568EDB9ED781@FreeBSD.org> References: <201812110138.wBB1cp1p006660@repo.freebsd.org> <2a76b295-b2da-3015-c201-dbe0ec63ca5a@FreeBSD.org> <98481565-CDD7-4301-B86B-072D5B984AF7@FreeBSD.org> To: cem@freebsd.org X-Mailer: Apple Mail (2.3445.9.1) Sender: devin@shxd.cx X-Rspamd-Queue-Id: BB8997219E X-Spamd-Bar: ---- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-4.98 / 15.00]; REPLY(-4.00)[]; NEURAL_HAM_SHORT(-0.98)[-0.977,0] X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 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: Tue, 11 Dec 2018 22:42:05 -0000 > On Dec 11, 2018, at 1:54 PM, Conrad Meyer wrote: >=20 > On Tue, Dec 11, 2018 at 12:35 PM Devin Teske = wrote: >>> On Dec 11, 2018, at 11:57 AM, Conrad Meyer wrote: >>> Is there any interest in a tee(2)-like syscall? >>>=20 >>=20 >> Linux has vmsplice(2). I know jmg@ also expressed interest in having = a >> vmsplice in FreeBSD. >=20 > Sure; they're related. See also splice(2). But tee(2) is probably > the one that would be most useful here. >=20 >> As for sh not being able to read more than a single byte at a time = because >> it could be reading from a pipe, what if it read into a buffer and = returned >> a line from the buffer. A subsequent read would return more data from = the >> buffer, ad nauseam until the buffer runs out -- in which case another = chunk >> is read to augment the data. >>=20 >> This buffer could be expunged when stdin collapses (e.g., when the = sub- >> shell completes. >=20 > Yeah, this is basically what "buffered input" means. An example of > the problem with the naive solution is the scenario Warner pasted a > few emails ago. Take: >=20 > foo | (read bar; baz) >=20 > (Where 'baz' is not a built-in.) To implement this correctly with > buffered 'read,' you have to somehow flush any input in the buffer > beyond the end of the first line to the pipe that will be baz's stdin, > as well as with the remaining contents of the pipe from foo (which > may be indefinite). That is what I suggested above as (A). >=20 > One big caveat is that you basically have to spawn a thread or process > to keep feeding the input from the first pipe to the magical implicit > pipe. This overhead can be avoided readily in most scenarios if only > the 'read' command is buffered. Also, the described (read bar; baz) > sub-program is a fairly odd construction, and the feeding isn't needed > if no non-builtin programs after 'read' will access stdin. >=20 > If it helps paint a more concrete picture, imagine 'foo' as 'yes' and > 'baz' as 'pv > /dev/null' or something (i.e., indefinite data source, > indefinite data sink). Thanks, this definitely illustrates the trouble. In that case, would it be appropriate to say that: blah | while read x; do ...; done Is always more efficiently written as: IFS=3D$'\n' for x in $( blah ); do ...; done ? --=20 Devin=