From nobody@FreeBSD.org  Sun Mar 14 23:30:45 2010
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 5EAEC1065672
	for <freebsd-gnats-submit@FreeBSD.org>; Sun, 14 Mar 2010 23:30:45 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id 4DA708FC14
	for <freebsd-gnats-submit@FreeBSD.org>; Sun, 14 Mar 2010 23:30:45 +0000 (UTC)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.3/8.14.3) with ESMTP id o2ENUi2B065608
	for <freebsd-gnats-submit@FreeBSD.org>; Sun, 14 Mar 2010 23:30:44 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.3/8.14.3/Submit) id o2ENUimQ065607;
	Sun, 14 Mar 2010 23:30:44 GMT
	(envelope-from nobody)
Message-Id: <201003142330.o2ENUimQ065607@www.freebsd.org>
Date: Sun, 14 Mar 2010 23:30:44 GMT
From: Alexander Best <alexbestms@wwu.de>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [libstand] [patch] make assert.c use abort(3) instead of exit(3)
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         144749
>Category:       kern
>Synopsis:       [libstand] [patch] make assert.c use abort(3) instead of exit(3)
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    jhb
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sun Mar 14 23:40:06 UTC 2010
>Closed-Date:    Wed Apr 14 17:19:26 UTC 2010
>Last-Modified:  Wed Apr 14 17:19:26 UTC 2010
>Originator:     Alexander Best
>Release:        9.0-CURRENT
>Organization:
>Environment:
FreeBSD otaku 9.0-CURRENT FreeBSD 9.0-CURRENT #8 r205019M: Thu Mar 11 21:03:33 CET 2010     root@otaku:/usr/obj/usr/src/sys/ARUNDEL  amd64
>Description:
gcc complaints about the use of exit() in assert.c:

/usr/src/lib/libstand/assert.c:43: warning: implicit declaration of function
'exit'

the attached patch replaces exit() (which is used illegally anyway, because no integer argument is being supplied) with abort().

assert.c uses stand.h which conflicts with stdlib.h. so this patch also defines abort() in stand.h being an external function.

cheers.
alex
>How-To-Repeat:
cd /usr/src/lib/libstand && make
>Fix:


Patch attached with submission follows:

Index: lib/libstand/assert.c
===================================================================
--- lib/libstand/assert.c	(revision 205121)
+++ lib/libstand/assert.c	(working copy)
@@ -40,5 +40,5 @@
 	else
 		printf("Assertion failed: (%s), function %s, file %s, line "
 		    "%d.\n", expression, func, file, line);
-	exit();
+	abort();
 }
Index: lib/libstand/stand.h
===================================================================
--- lib/libstand/stand.h	(revision 205121)
+++ lib/libstand/stand.h	(working copy)
@@ -265,6 +265,7 @@
 extern char	*optarg;			/* getopt(3) external variables */
 extern int	optind, opterr, optopt, optreset;
 extern int	getopt(int, char * const [], const char *);
+extern void	abort(void);
 
 /* pager.c */
 extern void	pager_open(void);


>Release-Note:
>Audit-Trail:

From: Bruce Evans <brde@optusnet.com.au>
To: Alexander Best <alexbestms@wwu.de>
Cc: freebsd-gnats-submit@FreeBSD.org, freebsd-bugs@FreeBSD.org
Subject: Re: misc/144749: [libstand] [patch] make assert.c use abort(3)
 instead of exit(3)
Date: Tue, 16 Mar 2010 02:06:55 +1100 (EST)

 On Sun, 14 Mar 2010, Alexander Best wrote:
 
 >> Description:
 > gcc complaints about the use of exit() in assert.c:
 >
 > /usr/src/lib/libstand/assert.c:43: warning: implicit declaration of function
 > 'exit'
 
 It's not clear where this should be declared, or even it must exist.
 exit() might be supplied by the application, but if not then it doesn't
 exist and it is invalid for assert() to call it.  libstand(3) of course
 doesn't document either exit() or the need to supply it to support
 assert().
 
 > the attached patch replaces exit() (which is used illegally anyway, because no integer argument is being supplied) with abort().
 
 The use might be legal, since libstand is freestanding so its exit might be
 unrelated to the Standard C exit.  However, most or all implementations of 
 exit() in /sys/boot take an arg.
 
 > assert.c uses stand.h which conflicts with stdlib.h. so this patch also defines abort() in stand.h being an external function.
 
 abort() certainly is not required to exist, and in fact doesn't exist for
 any application in /sys/boot, so this change would mainly break most boot
 code at link time.
 
 libstand is independent of libc, so it is a bug for anything in it or
 any application that uses it to include <stdlib.h>.  In libstand and
 /sys/boot, this bug seems to be present only in ficl (the include is
 ifdefed in only some places in ficl but in all places in libstand).
 
 A nearby function that doesn't exist is atexit().  This is only
 called from ifdefed out code in zalloc_malloc.c.
 
 >
 > cheers.
 > alex
 >> How-To-Repeat:
 > cd /usr/src/lib/libstand && make
 >> Fix:
 >
 >
 > Patch attached with submission follows:
 >
 > Index: lib/libstand/assert.c
 > ===================================================================
 > --- lib/libstand/assert.c	(revision 205121)
 > +++ lib/libstand/assert.c	(working copy)
 > @@ -40,5 +40,5 @@
 > 	else
 > 		printf("Assertion failed: (%s), function %s, file %s, line "
 > 		    "%d.\n", expression, func, file, line);
 
 It would be nice to fix the style bug in this (use of C90 string
 concatenation to obfuscate the message).  This style bug os missing in
 the libc version.
 
 > -	exit();
 > +	abort();
 > }
 > Index: lib/libstand/stand.h
 > ===================================================================
 > --- lib/libstand/stand.h	(revision 205121)
 > +++ lib/libstand/stand.h	(working copy)
 > @@ -265,6 +265,7 @@
 > extern char	*optarg;			/* getopt(3) external variables */
 > extern int	optind, opterr, optopt, optreset;
 > extern int	getopt(int, char * const [], const char *);
 > +extern void	abort(void);
 
 Further unsorting of the declarations.
 
 Note that exit() is of a different nature than getopt() -- it is
 supplied by the application (if it exists), while getopt() is supplied
 by libstand.  So there should be a separate section to declare exit() and
 any other function that must be supplied by the application.
 
 >
 > /* pager.c */
 > extern void	pager_open(void);
 
 ISTR that there were once similar problems declaring main().  When it
 wasn't declared explicitly, gcc -Wmumble used to warn about this.  So
 someone "fixed" this by declaring it in a standard header.  But it
 cannot be declared in a standard header since it has more than one
 valid parameter list ((void), and the usual (argc, argv), and maybe
 more).
 
 Bruce

From: Alexander Best <alexbestms@wwu.de>
To: <bug-followup@FreeBSD.org>
Cc:  
Subject: Re: kern/144749: [libstand] [patch] make assert.c use abort(3)
 instead of exit(3)
Date: Sun, 21 Mar 2010 11:27:53 +0100 (CET)

   This is a MIME encoded multipart message.
 
 --+permail-20100321102753f0889e84000028d8-a_best01+
 Content-Type: text/plain; charset=us-ascii
 Content-Transfer-Encoding: 7bit
 
 John Baldwin proposed the following change:
 
 -- 
 Alexander Best
 
 --+permail-20100321102753f0889e84000028d8-a_best01+
 Content-Type: message/rfc822; charset=us-ascii
 Content-Description: Re: [patch] small fix to stop gcc warning for
  lib/libstand/assert.c (fwd)
 
 Return-Path: <jhb@freebsd.org>
 X-Original-To: alexbestms@wwu.de
 Delivered-To: a_best01@UNI-MUENSTER.DE
 Received: from zivm-relay3.uni-muenster.de (ZIVM-RELAY3.UNI-MUENSTER.DE [128.176.192.19])
 	by ZIVMAILSTORE1.UNI-MUENSTER.DE (Postfix) with ESMTP id E6D1D30C938
 	for <alexbestms@wwu.de>; Mon, 15 Mar 2010 17:05:33 +0100 (CET)
 X-IronPort-Anti-Spam-Filtered: true
 X-IronPort-Anti-Spam-Result: AokEAAL4nUtBehEqgWdsb2JhbACacRUBARYkIrlIhHsE
 X-IronPort-AV: E=Sophos;i="4.49,644,1262559600"; 
    d="scan'208";a="28469430"
 Received: from cyrus.watson.org ([65.122.17.42])
   by zivm-wwu3.uni-muenster.de with ESMTP; 15 Mar 2010 17:05:33 +0100
 Received: from bigwig.baldwin.cx (66.111.2.69.static.nyinternet.net [66.111.2.69])
 	by cyrus.watson.org (Postfix) with ESMTPSA id 84DF546B8C;
 	Mon, 15 Mar 2010 12:05:31 -0400 (EDT)
 Received: from zion.baldwin.cx (pool-98-109-181-99.nwrknj.fios.verizon.net [98.109.181.99])
 	by bigwig.baldwin.cx (Postfix) with ESMTPA id 8CEB48A021;
 	Mon, 15 Mar 2010 12:05:30 -0400 (EDT)
 From: John Baldwin <jhb@freebsd.org>
 To: freebsd-hackers@freebsd.org
 Subject: Re: [patch] small fix to stop gcc warning for lib/libstand/assert.c
 Date: Mon, 15 Mar 2010 11:32:18 -0400
 User-Agent: KMail/1.12.4 (FreeBSD/7.3-PRERELEASE; KDE/4.3.4; i386; ; )
 Cc: Alexander Best <alexbestms@wwu.de>
 References: <permail-20100313135219f7e55a9d00006340-a_best01@message-id.uni-muenster.de>
 In-Reply-To: <permail-20100313135219f7e55a9d00006340-a_best01@message-id.uni-muenster.de>
 MIME-Version: 1.0
 Content-Type: Text/Plain;
   charset="iso-8859-15"
 Content-Transfer-Encoding: 7bit
 Message-Id: <201003151132.18617.jhb@freebsd.org>
 X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.0.1 (bigwig.baldwin.cx); Mon, 15 Mar 2010 12:05:30 -0400 (EDT)
 X-Virus-Scanned: clamav-milter 0.95.1 at bigwig.baldwin.cx
 X-Virus-Status: Clean
 X-Spam-Status: No, score=-3.0 required=4.2 tests=AWL,BAYES_00,
 	FH_HOST_EQ_VERIZON_P,RDNS_DYNAMIC autolearn=no version=3.2.5
 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on bigwig.baldwin.cx
 X-UID: 1391                                                  
 Status: RO
 Content-Length: 1360
 
 On Saturday 13 March 2010 08:52:19 am Alexander Best wrote:
 > hello,
 > 
 > this patch fixes the following gcc warning:
 > 
 > /usr/src/lib/libstand/assert.c:43: warning: implicit declaration of
 >  function 'exit'
 > 
 > by using abort() instead of exit() (which is illegal anyway). looking at
 > lib/libc/gen/assert.c abort() seems save to use instead of exit().
 
 There is no abort() in libstand or any of the boot code.  If you built a full 
 world with this change you should have gotten a link error for /boot/loader.  
 exit() is required by the boot code however (see sys/boot/common/panic.c).  
 The use of exit() instead of abort() here is on purpose.  This is the fix I 
 would use.  I would not add 'exit()' to <stand.h> as it is not an interface 
 that libstand provides, but one that it requires from the environment it is 
 linked with.
 
 Index: assert.c
 ===================================================================
 --- assert.c    (revision 204953)
 +++ assert.c    (working copy)
 @@ -31,6 +31,8 @@
 
  #include "stand.h"
 
 +void   exit(int);
 +
  void
  __assert(const char *func, const char *file, int line, const char 
 *expression)
  {
 @@ -40,5 +42,5 @@
         else
                 printf("Assertion failed: (%s), function %s, file %s, line "
                     "%d.\n", expression, func, file, line);
 -       exit();
 +       exit(1);
  }
 
 -- 
 John Baldwin
 
 --+permail-20100321102753f0889e84000028d8-a_best01+--

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/144749: commit references a PR
Date: Tue, 30 Mar 2010 19:08:20 +0000 (UTC)

 Author: jhb
 Date: Tue Mar 30 19:07:41 2010
 New Revision: 205900
 URL: http://svn.freebsd.org/changeset/base/205900
 
 Log:
   Use panic() (which the environment is required to provide to libstand) to
   implement assert() instead of relying on a non-required exit().  The exit()
   invocation also did not match the semantics of the exit() routine that
   current boot environments happen to require.
   
   PR:		kern/144749
   Discussed with:	bde
   MFC after:	1 week
 
 Modified:
   head/lib/libstand/assert.c
 
 Modified: head/lib/libstand/assert.c
 ==============================================================================
 --- head/lib/libstand/assert.c	Tue Mar 30 19:06:54 2010	(r205899)
 +++ head/lib/libstand/assert.c	Tue Mar 30 19:07:41 2010	(r205900)
 @@ -35,10 +35,10 @@ void
  __assert(const char *func, const char *file, int line, const char *expression)
  {
  	if (func == NULL)
 -		printf("Assertion failed: (%s), file %s, line %d.\n",
 +		panic("Assertion failed: (%s), file %s, line %d.\n",
  		    expression, file, line);
  	else
 -		printf("Assertion failed: (%s), function %s, file %s, line "
 -		    "%d.\n", expression, func, file, line);
 -	exit();
 +		panic(
 +		    "Assertion failed: (%s), function %s, file %s, line %d.\n",
 +		    expression, func, file, line);
  }
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: open->patched 
State-Changed-By: jhb 
State-Changed-When: Tue Mar 30 19:54:43 UTC 2010 
State-Changed-Why:  
Fixed in HEAD. 


Responsible-Changed-From-To: freebsd-bugs->jhb 
Responsible-Changed-By: jhb 
Responsible-Changed-When: Tue Mar 30 19:54:43 UTC 2010 
Responsible-Changed-Why:  
Fixed in HEAD. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=144749 
State-Changed-From-To: patched->closed 
State-Changed-By: jhb 
State-Changed-When: Wed Apr 14 17:18:48 UTC 2010 
State-Changed-Why:  
Fix merged to 7. 

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