Bug 127219

Summary: [patch] style(9) is inconsistent regarding usage of sysexits(3)
Product: Documentation Reporter: Rebecca Cran <bcran>
Component: Books & ArticlesAssignee: Robert Watson <rwatson>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: Latest   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
file.diff none

Description Rebecca Cran freebsd_committer freebsd_triage 2008-09-08 20:40:01 UTC
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.

Fix: Patch attached with submission follows:
How-To-Repeat: man 9 style
Comment 1 Robert Watson freebsd_committer freebsd_triage 2008-10-31 14:44:13 UTC
State Changed
From-To: open->analyzed

This seems reasonable. 


Comment 2 Robert Watson freebsd_committer freebsd_triage 2008-10-31 14:44:13 UTC
Responsible Changed
From-To: freebsd-doc->rwatson

Grab ownership as I'll commit this.
Comment 3 _account_created_by_error freebsd_committer freebsd_triage 2008-10-31 15:17:16 UTC
---------- 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
Comment 4 Robert Watson freebsd_committer freebsd_triage 2008-10-31 15:20:33 UTC
State Changed
From-To: analyzed->patched

Committed to head; placed in patched state until MFC.
Comment 5 Robert Watson freebsd_committer freebsd_triage 2009-02-01 18:47:06 UTC
State Changed
From-To: patched->closed

As with docs/127220, it turns out that the proposed patch does not 
capture the preferred code style, so I've backed it out.