From nick@van-laarhoven.org  Fri Aug 25 20:05:22 2006
Return-Path: <nick@van-laarhoven.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id E315816A4F6
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 25 Aug 2006 20:05:21 +0000 (UTC)
	(envelope-from nick@van-laarhoven.org)
Received: from smtp-1.orange.nl (smtp-1.orange.nl [193.252.22.241])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 4D26E43D7D
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 25 Aug 2006 20:05:01 +0000 (GMT)
	(envelope-from nick@van-laarhoven.org)
Received: from uitsmijter.van-laarhoven.org (ap-zvhz-13f05.adsl.wanadoo.nl [81.69.93.5])
	by mwinf6008.orange.nl (SMTP Server) with ESMTP id 2D940700008D
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 25 Aug 2006 22:05:00 +0200 (CEST)
Received: (qmail 39050 invoked from network); 25 Aug 2006 20:04:59 -0000
Received: from 10.66.0.146 by uitsmijter.van-laarhoven.org (envelope-from <nick@van-laarhoven.org>, uid 82) with qmail-scanner-1.25 
 (clamdscan: 0.88.2/1459. f-prot: 4.6.6/3.16.14. spamassassin: 3.1.1.  
 Clear:RC:1(10.66.0.146):. 
 Processed in 0.050598 secs); 25 Aug 2006 20:04:59 -0000
Received: from unknown (HELO van-laarhoven.org) (nick@10.66.0.146)
  by uitsmijter.van-laarhoven.org with SMTP; 25 Aug 2006 20:04:59 -0000
Received: (nullmailer pid 9189 invoked by uid 1001);
	Fri, 25 Aug 2006 20:04:59 -0000
Message-Id: <1156536299.544558.9188.nullmailer@van-laarhoven.org>
Date: Fri, 25 Aug 2006 22:04:59 +0200
From: Nick Hibma <nick@van-laarhoven.org>
Reply-To: Nick Hibma <nick@van-laarhoven.org>
To: FreeBSD-gnats-submit@freebsd.org
Subject: fsck_ufs crashes if no console at all (in libc)
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         102515
>Category:       bin
>Synopsis:       [libc] fsck_ufs crashes if no console at all
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Aug 25 20:10:20 GMT 2006
>Closed-Date:    Mon Apr 22 10:26:17 UTC 2013
>Last-Modified:  Mon Apr 22 10:26:17 UTC 2013
>Originator:     Nick Hibma
>Release:        FreeBSD 6.1-STABLE i386
>Organization:
AnyWi Technologies
>Environment:
System: FreeBSD hind.van-laarhoven.org 6.1-STABLE FreeBSD 6.1-STABLE #19: Thu Aug 17 16:31:39 CEST 2006 toor@hind.van-laarhoven.org:/usr/src/sys/i386/compile/HIND i386

Headless Soekris (no graphics hardware), without serial console:

	hint.sio.0.flags="0x00"

and all getty ttys (ttyd0 and ttyv?) switched off.

>Description:

fsck_ffs (fsck_ufs) crashes in libc in this configuration on boot. This
failure stops the boot process, and wants to drop you into a shell. But because
there is no console the /etc/rc script immediately resumes the boot process, but
this time as fastboot instead of autoboot, skipping the disk checks; and the
crash, but the disk doesn't get checked that way (is mounted read-only, so that
is not that big an issue).

This leads to a duplicated execution of memory disk creation in rc.initdiskless
which is my real problem: It wastes 14mb of my 64Mb of memory!

Backtrace:
#0  0x08054841 in ?? ()
#1  0x28150c98 in __gdtoa_locks () from /lib/libc.so.6
#2  0xbfbfedc0 in ?? ()
#3  0xbfbfe358 in ?? ()
#4  0x280b1ea3 in freopen () from /lib/libc.so.6
#5  0x08055108 in ?? ()
...
#215 0x00000000 in ?? ()
#216 0x2805f405 in dlsym () from /libexec/ld-elf.so.1
#217 0x0804eada in ?? ()
...
#223 0x09a6322b in ?? ()
#224 0x2809d7ba in ?? () from /lib/libc.so.6
#225 0x2807d598 in ?? ()
#226 0x28099b28 in ?? () from /lib/libc.so.6
#227 0x00000000 in ?? ()
#228 0xbfbfea38 in ?? ()
#229 0x2805f5e3 in dlinfo () from /libexec/ld-elf.so.1
#230 0x08049252 in ?? ()
...
#233 0xbfbfecdc in ?? ()
---Type <return> to continue, or q <return> to quit---
#234 0x00000010 in ?? ()
#235 0x080561d0 in __divdi3 ()
#236 0x00000003 in ?? ()

>How-To-Repeat:

# fsck -f / < /dev/console
** /dev/ad0s1a
fsck: /dev/ad0s1a: Floating point exception: 8
# fsck -f /
** /dev/ad0s1a
<<produces normal result which I did not capture>>

on a machine without a console (see above for how to reproduce). Image to test
this with can be generated if needed, or access to machine can be given.
(Read-only image mounted in multi-user mode, don't know whether ).
>Fix:

Several options:

A)
	Change statements calling fsck in /etc/rc.d/fsck from
		fsck -F -p
	to
		fsck -F -p </dev/null

	(perhaps in bgfsck too? I've disabled background fsck)

B)
	Have rc.initdiskless create the mdmfs only during autoboot, not during
	fastboot.

C)
	Fix libc to be able to cope with undefined file descriptors (or whatever
	it is that is crashing libc).

IMHO B and C should be done. A) is just mentioned to help people work around the
problem.
>Release-Note:
>Audit-Trail:

From: Nick Hibma <nick@van-laarhoven.org>
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/102515: [libc] fsck_ufs crashes if no console at all
Date: Tue, 26 Feb 2013 23:44:45 +0100

 The real fix for this is to provide a decent console to it (null =
 console). But a quick band-aid is to use init from HEAD (the sources =
 compile without changes in 8.3-RELEASE).This version of init handles the =
 lack of a /dev/console device more gracefully by opening /dev/null or a =
 log file if /dev/console is not available.
 
 Nick=
State-Changed-From-To: open->closed 
State-Changed-By: n_hibma 
State-Changed-When: Mon Apr 22 10:23:09 UTC 2013 
State-Changed-Why:  
Fixed in r232977 and r233945 in HEAD and r247004 in FBSD9: 

Init will now open /dev/null if no console at all, so this fsck should now have 
a valid file descriptor on stdout/stderr/stdin. 


http://www.freebsd.org/cgi/query-pr.cgi?pr=102515 
>Unformatted:
