From owner-svn-src-all@freebsd.org Tue Dec 11 21:55:17 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 D7EEC1317368; Tue, 11 Dec 2018 21:55:16 +0000 (UTC) (envelope-from cse.cem@gmail.com) Received: from mail-io1-f45.google.com (mail-io1-f45.google.com [209.85.166.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 73B9A704A6; Tue, 11 Dec 2018 21:55:16 +0000 (UTC) (envelope-from cse.cem@gmail.com) Received: by mail-io1-f45.google.com with SMTP id x6so13120801ioa.9; Tue, 11 Dec 2018 13:55:16 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:reply-to :from:date:message-id:subject:to:cc; bh=oEkqyaJVoWoNFbm0g91ypoDVrptSLeOTu9ol6XZesz4=; b=LzvSb8KkoHVI1gAiGjxv1L/NnmoNC+77fCF1yJp9Twg3UGEwvjVjSqyEGaa3DPvgnN 6KrZfyD3Tjz9CH5kgHDw46z1bSSsyL/gs3F6P84kKlYV8yjVX+8qxT5A7wWBxc/p4ikq dIuFP2LTDW5gjxgR+FD1ZchhLydBR2lJXoSlhfcCiXXlpxPvRBEARR4xXvH9i3RUTXt9 Sp7wkA5pEvx9JjCHBXvNgJotJKGLeKBaxPuixoKHWl9Tx7V12RS5QJcv1IblX3uncmmF Ki3k9fFhhEI4ip5Q4F0vG6d4ftI6M83EDtKuNnZfTj8BP+3Akt34yP94Wx3tu2TKdWMD fO3w== X-Gm-Message-State: AA+aEWaQ22RQJMraS8ueF2nBRWdTx/tbw++IjOaLZZXYX5a4pNbul8uH 4FrosdD6arw7anxfNjm7urI9mXve X-Google-Smtp-Source: AFSGD/XSJQ5N0Ww99KdADvXf00XRVkXLLXiCwwrVIn6sTU4+9o2iDxEt1o8emAmsWCTVkqwPWyQPgQ== X-Received: by 2002:a6b:6111:: with SMTP id v17mr15626902iob.107.1544565309769; Tue, 11 Dec 2018 13:55:09 -0800 (PST) Received: from mail-it1-f180.google.com (mail-it1-f180.google.com. [209.85.166.180]) by smtp.gmail.com with ESMTPSA id 194sm2072768itl.32.2018.12.11.13.55.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Dec 2018 13:55:09 -0800 (PST) Received: by mail-it1-f180.google.com with SMTP id m8so11969805itk.0; Tue, 11 Dec 2018 13:55:09 -0800 (PST) X-Received: by 2002:a24:5411:: with SMTP id t17mr3632243ita.32.1544565309264; Tue, 11 Dec 2018 13:55:09 -0800 (PST) MIME-Version: 1.0 References: <201812110138.wBB1cp1p006660@repo.freebsd.org> <2a76b295-b2da-3015-c201-dbe0ec63ca5a@FreeBSD.org> <98481565-CDD7-4301-B86B-072D5B984AF7@FreeBSD.org> In-Reply-To: Reply-To: cem@freebsd.org From: Conrad Meyer Date: Tue, 11 Dec 2018 13:54:58 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: svn commit: r341803 - head/libexec/rc To: Devin Teske Cc: src-committers , svn-src-all@freebsd.org, svn-src-head@freebsd.org Content-Type: text/plain; charset="UTF-8" X-Rspamd-Queue-Id: 73B9A704A6 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.982,0]; TAGGED_FROM(0.00)[] 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 21:55:17 -0000 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? > > > > Linux has vmsplice(2). I know jmg@ also expressed interest in having a > vmsplice in FreeBSD. Sure; they're related. See also splice(2). But tee(2) is probably the one that would be most useful here. > 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. > > This buffer could be expunged when stdin collapses (e.g., when the sub- > shell completes. 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: foo | (read bar; baz) (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). 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. 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). Best, Conrad