From nobody@FreeBSD.org  Mon Sep  8 19:31:45 2008
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 9C8DB1065670
	for <freebsd-gnats-submit@FreeBSD.org>; Mon,  8 Sep 2008 19:31: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 8F29B8FC19
	for <freebsd-gnats-submit@FreeBSD.org>; Mon,  8 Sep 2008 19:31:45 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.2/8.14.2) with ESMTP id m88JVjqe066667
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 8 Sep 2008 19:31:45 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.2/8.14.1/Submit) id m88JVjMs066666;
	Mon, 8 Sep 2008 19:31:45 GMT
	(envelope-from nobody)
Message-Id: <200809081931.m88JVjMs066666@www.freebsd.org>
Date: Mon, 8 Sep 2008 19:31:45 GMT
From: Bruce Cran <bruce@cran.org.uk>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [patch] style(9) is inconsistent regarding usage of sysexits(3)
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         127219
>Category:       docs
>Synopsis:       [patch] style(9) is inconsistent regarding usage of sysexits(3)
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    rwatson
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          doc-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Sep 08 19:40:01 UTC 2008
>Closed-Date:    Sun Feb 01 18:47:39 UTC 2009
>Last-Modified:  Sun Feb 01 18:47:39 UTC 2009
>Originator:     Bruce Cran
>Release:        7.0-RELEASE-p3
>Organization:
>Environment:
FreeBSD tau.draftnet 7.0-RELEASE-p3 FreeBSD 7.0-RELEASE-p3 #1: Mon Aug  4 00:11:11 BST 2008     brucec@tau.draftnet:/usr/obj/usr/src/sys/MYKERNEL  amd64
>Description:
style(9) is inconsistent regarding the usage of sysexits(3): at one point it says

Exits should be 0 on success, or according to the predefined values in sysexits(3).

But in a later example:

 Use err(3) or warn(3), do not roll your own.

             if ((four = malloc(sizeof(struct foo))) == NULL)
                     err(1, (char *)NULL);
             if ((six = (int *)overflow()) == NULL)
                     errx(1, "number overflowed");
             return (eight);
     }

err and errx exit with a code of 1, which is incorrect according to the previous statement.  Better exit codes might be EX_OSERR and EX_DATAERR.

Also, the cast of NULL to char * isn't required.
>How-To-Repeat:
man 9 style
>Fix:


Patch attached with submission follows:

--- /usr/src/share/man/man9/style.9	2007-01-28 20:51:04.000000000 +0000
+++ style.9	2008-09-08 20:20:31.000000000 +0100
@@ -716,9 +716,9 @@
 do not roll your own.
 .Bd -literal
 	if ((four = malloc(sizeof(struct foo))) == NULL)
-		err(1, (char *)NULL);
+		err(EX_OSERR, NULL);
 	if ((six = (int *)overflow()) == NULL)
-		errx(1, "number overflowed");
+		errx(EX_DATAERR, "number overflowed");
 	return (eight);
 }
 .Ed


>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->analyzed 
State-Changed-By: rwatson 
State-Changed-When: Fri Oct 31 14:44:13 UTC 2008 
State-Changed-Why:  
This seems reasonable. 


Responsible-Changed-From-To: freebsd-doc->rwatson 
Responsible-Changed-By: rwatson 
Responsible-Changed-When: Fri Oct 31 14:44:13 UTC 2008 
Responsible-Changed-Why:  
Grab ownership as I'll commit this. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=127219 

From: Robert Watson <rwatson@FreeBSD.ogr>
To: freebsd-gnats-submit@FreeBSD.org
Cc:  
Subject: Re: docs/127219: svn commit: r184509 - head/share/man/man9 (fwd)
Date: Fri, 31 Oct 2008 15:17:16 +0000 (GMT)

 ---------- Forwarded message ----------
 Date: Fri, 31 Oct 2008 14:47:15 +0000 (UTC)
 From: Robert Watson <rwatson@FreeBSD.org>
 To: src-committers@freebsd.org, svn-src-all@freebsd.org,
      svn-src-head@freebsd.org
 Subject: svn commit: r184509 - head/share/man/man9
 
 Author: rwatson
 Date: Fri Oct 31 14:47:15 2008
 New Revision: 184509
 URL: http://svn.freebsd.org/changeset/base/184509
 
 Log:
    In style(9) examples of err() and errx(), use sysexits(3) errors rather
    than returning 1.
 
    Submitted by:	Bruce Cran <bruce at cran dot org dot uk>
    MFC after:	3 days
 
 Modified:
    head/share/man/man9/style.9
 
 Modified: head/share/man/man9/style.9
 ==============================================================================
 --- head/share/man/man9/style.9	Fri Oct 31 14:40:21 2008	(r184508)
 +++ head/share/man/man9/style.9	Fri Oct 31 14:47:15 2008	(r184509)
 @@ -716,9 +716,9 @@ or
   do not roll your own.
   .Bd -literal
   	if ((four = malloc(sizeof(struct foo))) == NULL)
 -		err(1, (char *)NULL);
 +		err(EX_OSERR, NULL);
   	if ((six = (int *)overflow()) == NULL)
 -		errx(1, "number overflowed");
 +		errx(EX_DATAERR, "number overflowed");
   	return (eight);
   }
   .Ed
State-Changed-From-To: analyzed->patched 
State-Changed-By: rwatson 
State-Changed-When: Fri Oct 31 15:20:33 UTC 2008 
State-Changed-Why:  
Committed to head; placed in patched state until MFC. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=127219 
State-Changed-From-To: patched->closed 
State-Changed-By: rwatson 
State-Changed-When: Sun Feb 1 18:47:06 UTC 2009 
State-Changed-Why:  
As with docs/127220, it turns out that the proposed patch does not 
capture the preferred code style, so I've backed it out. 


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