From owner-freebsd-i386@FreeBSD.ORG Thu Oct 20 04:10:58 2005 Return-Path: X-Original-To: freebsd-i386@FreeBSD.org Delivered-To: freebsd-i386@FreeBSD.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 99A8316A41F for ; Thu, 20 Oct 2005 04:10:58 +0000 (GMT) (envelope-from bde@zeta.org.au) Received: from mailout2.pacific.net.au (mailout2.pacific.net.au [61.8.0.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id C32CC43D8E for ; Thu, 20 Oct 2005 04:10:46 +0000 (GMT) (envelope-from bde@zeta.org.au) Received: from mailproxy1.pacific.net.au (mailproxy1.pacific.net.au [61.8.0.86]) by mailout2.pacific.net.au (8.13.4/8.13.4/Debian-3) with ESMTP id j9K4AjCJ013005; Thu, 20 Oct 2005 14:10:45 +1000 Received: from katana.zip.com.au (katana.zip.com.au [61.8.7.246]) by mailproxy1.pacific.net.au (8.13.4/8.13.4/Debian-3) with ESMTP id j9K4AhSJ005130; Thu, 20 Oct 2005 14:10:44 +1000 Date: Thu, 20 Oct 2005 14:10:43 +1000 (EST) From: Bruce Evans X-X-Sender: bde@delplex.bde.org To: HASHI Hiroaki In-Reply-To: <200510180933.j9I9XtQu026284@freefall.freebsd.org> Message-ID: <20051020140624.U99622@delplex.bde.org> References: <200510180933.j9I9XtQu026284@freefall.freebsd.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Cc: freebsd-i386@FreeBSD.org Subject: Re: i386/87208: /dev/cuad[0/1] bad file descriptor error during mgetty read X-BeenThere: freebsd-i386@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: I386-specific issues for FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 20 Oct 2005 04:10:58 -0000 On Tue, 18 Oct 2005, HASHI Hiroaki wrote: > In this case, mgetty open a /dev/cuad? and dup(2) to stdin. > > int fd; > > fd = open(devname, O_RDWR | O_NDELAY | O_NOCTTY ); > > /* make new fd == stdin if it isn't already */ > > if (fd > 0) > { > (void) close(0); > ---> if (dup(fd) != 0) > { > lprintf( L_FATAL, "mod: cannot make %s stdin", devname ); > return ERROR; > } > } > > Bad dup() was not return descriptor 0. > > Is this a dup(3)'s bug? > (or imcompatible change?) Looks like a bug in dup(2). dup(2) is documented to return the "lowest numbered descriptor not in use by the process", and the close(0) should ensure that descriptor 0 is not in use. The only visible bug in mgetty is that it ignores errors in close(0); this breaks mainly the error reporting. Bruce