From owner-freebsd-current@freebsd.org Thu Mar 9 00:20:00 2017 Return-Path: Delivered-To: freebsd-current@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 C69C6D013FC for ; Thu, 9 Mar 2017 00:20:00 +0000 (UTC) (envelope-from truckman@FreeBSD.org) Received: from gw.catspoiler.org (unknown [IPv6:2602:304:b010:ef20::f2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "gw.catspoiler.org", Issuer "gw.catspoiler.org" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id A72B21DED; Thu, 9 Mar 2017 00:20:00 +0000 (UTC) (envelope-from truckman@FreeBSD.org) Received: from FreeBSD.org (mousie.catspoiler.org [192.168.101.2]) by gw.catspoiler.org (8.15.2/8.15.2) with ESMTP id v290Jlpk004822; Wed, 8 Mar 2017 16:19:51 -0800 (PST) (envelope-from truckman@FreeBSD.org) Message-Id: <201703090019.v290Jlpk004822@gw.catspoiler.org> Date: Wed, 8 Mar 2017 16:19:47 -0800 (PST) From: Don Lewis Subject: Re: I/O semantics of pipe and FIFO. To: dteske@freebsd.org cc: alfred@freebsd.org, julian@elischer.org, freebsd-current@freebsd.org In-Reply-To: MIME-Version: 1.0 Content-Type: TEXT/plain; charset=iso-8859-13 Content-Transfer-Encoding: 8BIT X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 09 Mar 2017 00:20:00 -0000 On 8 Mar, Devin Teske wrote: > Problem we had found was: > > Executing dd with a closed stdout and stderr would cause the summary > messages printed at the end to go into the destination output file. > > For example, > > dd if=/dev/zero of=/tmp/foo bs=1m count=1 > > Works fine, but the following: > > dd if=/dev/zero of=/tmp/foo bs=1m count=1 >&- 2>&- > > Will cause the summary statistics of dd to appear in /tmp/foo instead > of on the console. > > The issue is that the summary statistics are send to fd1, which if you > close down stdout and stdin, fd1 is actually the output file since it > got the lowest file descriptor available when open(2) was called on > the output file. > > This was never fixed because it was deemed ´silly developer, don˙t > close stdout and stderr before invoking ddˇ. > > The argument has been made by Jilles T. that it is generally a bad > idea to close down any of the standard file descriptors because it > cannot be predicted how a particular UNIX utility will react (e.g., in > the case of dd, causing a simple printf(3) to go to an unexpected > location). Shades of: - From our Harris VOS system. JOBCNTRL ER 2211 : IT'S NOT NICE TO FOOL POP! >he 2211 YOU JUST TRIED TO FAKE-OUT MOTHER NATURE, AND SHE CAUGHT YOU! SUPER- VULCAN NOW HAS YOUR NAME ON HIS ENEMY LIST, AND YOU CAN BE CERTAIN THAT FUTURE ATTEMPTS TO RESOURCE LFN 0,3,OR 6 WILL RESULT IN YOUR BEING ABORTED, SPINDLED, MANGLED, FOLDED, PUNCHED, DELETED, AND DEALLOCATED.