From nobody@FreeBSD.org  Wed Dec 29 19:20:12 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 87AB9106564A
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 29 Dec 2010 19:20:12 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (unknown [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id 779688FC0A
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 29 Dec 2010 19:20:12 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.4/8.14.4) with ESMTP id oBTJKCmI034209
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 29 Dec 2010 19:20:12 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.4/8.14.4/Submit) id oBTJKCCI034208;
	Wed, 29 Dec 2010 19:20:12 GMT
	(envelope-from nobody)
Message-Id: <201012291920.oBTJKCCI034208@red.freebsd.org>
Date: Wed, 29 Dec 2010 19:20:12 GMT
From: douglas steinwand <dzs-pr@dzs.fx.org>
To: freebsd-gnats-submit@FreeBSD.org
Subject: wake(8) should use sysexits.h
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         153527
>Category:       bin
>Synopsis:       [patch] wake(8) should use sysexits.h
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    jh
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Dec 29 19:30:10 UTC 2010
>Closed-Date:    Wed May 16 18:15:08 UTC 2012
>Last-Modified:  Wed May 16 18:15:08 UTC 2012
>Originator:     douglas steinwand
>Release:        FreeBSD 8.1
>Organization:
>Environment:
FreeBSD paris.fx.org 8.1-RELEASE-p1 FreeBSD 8.1-RELEASE-p1 #23: Sat Oct  9 09:33:09 PDT 2010     root@paris.fx.org:/usr/obj/usr/src/sys/PARIS8  amd64

>Description:
The /usr/sbin/wake utility exits success (0) if an error occurs, for example if run by an unprivileged user or an unknown host is specified:

  $ wake foo bar; echo "exit=$?"
  wake: no bpf: Permission denied
  wake: error sending Wake on LAN frame over foo to bar

  exit=0

This causes problems when the utility is called from a shell script or other environment which expects a meaningful exit value. 
>How-To-Repeat:
Run wake(8) utility with an error condition.
>Fix:
The attached patch applies to FreeBSD 8.1 (src/usr.sbin/wake/wake.c,v 1.3.2.1.4.1)

Patch attached with submission follows:

--- usr.sbin/wake/wake.c.orig	2010-10-09 09:31:39.904356000 -0700
+++ usr.sbin/wake/wake.c	2010-12-29 10:59:54.646423552 -0800
@@ -41,6 +41,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <sysexits.h>
 
 #define	_PATH_BPF	"/dev/bpf"
 
@@ -63,7 +64,7 @@
 {
 
 	(void)fprintf(stderr, "usage: wake interface lladdr...\n");
-	exit(1);
+	exit(EX_USAGE);
 }
 
 static int
@@ -166,13 +167,16 @@
 main(int argc, char *argv[])
 {
 	int n;
+	int rv = EX_OK;
 
 	if (argc < 3)
 		usage();
 
 	for (n = 2; n < argc; n++)
-		if (wake(argv[1], argv[n]))
+		if (wake(argv[1], argv[n])) {
 			warnx("error sending Wake on LAN frame over %s to %s",
 			    argv[1], argv[n]);
-	return (0);
+			rv = EX_IOERR;
+		}
+	return (rv);
 }


>Release-Note:
>Audit-Trail:

From: Bruce Cran <bruce@cran.org.uk>
To: douglas steinwand <dzs-pr@dzs.fx.org>
Cc: freebsd-gnats-submit@FreeBSD.org
Subject: Re: bin/153527: wake(8) should use sysexits.h
Date: Thu, 30 Dec 2010 15:35:11 +0000

 On Wed, 29 Dec 2010 19:20:12 GMT
 douglas steinwand <dzs-pr@dzs.fx.org> wrote:
 
 > >Synopsis:       wake(8) should use sysexits.h
 
 wake(8) should not use sysexits.h since style(9) no longer recommends
 it - it should instead exit with 1 or 0.
 
 >   $ wake foo bar; echo "exit=$?"
 >   wake: no bpf: Permission denied
 >   wake: error sending Wake on LAN frame over foo to bar
 > 
 >   exit=0
 
 This seems to have been fixed in HEAD but not in 8-STABLE.
 
 -- 
 Bruce Cran

From: douglas steinwand <dzs-pr@dzs.fx.org>
To: freebsd-gnats-submit@freebsd.org
Cc:  
Subject: Re: bin/153527: wake(8) should use sysexits.h
Date: Thu, 30 Dec 2010 09:12:16 -0800

 On Thu, Dec 30, 2010 at 07:35, Bruce Cran <bruce@cran.org.uk> wrote:
 > wake(8) should not use sysexits.h since style(9) no longer recommends
 > it - it should instead exit with 1 or 0.
 
 The sysexits(3) manpage in FreeBSD 8.1 still seems relevant.
 
 
 > This seems to have been fixed in HEAD but not in 8-STABLE.
 
 HEAD looks better, but a missing hostname [from get_ether()] exits 0
 with a message on STDERR. Other utilities [like ping(8)] return a
 non-zero result in that case.
 
 thanks,
  - doug

From: Bruce Cran <bruce@cran.org.uk>
To: dzs-pr@dzs.fx.org, bug-followup@freebsd.org
Cc:  
Subject: Re: bin/153527: wake(8) should use sysexits.h
Date: Thu, 30 Dec 2010 18:00:01 +0000

 On Thu, 30 Dec 2010 09:10:33 -0800
 douglas steinwand <dzs-pr@dzs.fx.org> wrote:
 
 > The sysexits(3) manpage in FreeBSD 8.1 still seems relevant.
 
 It is, but its use is discouraged now - see
 http://svn.freebsd.org/viewvc/base/head/share/man/man9/style.9 for the
 history - e.g. "Revert r184509: don't encourage the use of sysexits.h
 with err() and errx(),, as there seems to be a general preference
 against this practice."
 
 -- 
 Bruce Cran
Responsible-Changed-From-To: freebsd-bugs->jh 
Responsible-Changed-By: jh 
Responsible-Changed-When: Fri Feb 24 07:20:59 UTC 2012 
Responsible-Changed-Why:  
Take. 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/153527: commit references a PR
Date: Fri, 24 Feb 2012 07:54:23 +0000 (UTC)

 Author: jh
 Date: Fri Feb 24 07:54:08 2012
 New Revision: 232102
 URL: http://svn.freebsd.org/changeset/base/232102
 
 Log:
   Exit with proper status when wake() fails.
   
   PR:		bin/153527
   Submitted by:	Douglas Steinwand
   MFC after:	2 weeks
 
 Modified:
   head/usr.sbin/wake/wake.c
 
 Modified: head/usr.sbin/wake/wake.c
 ==============================================================================
 --- head/usr.sbin/wake/wake.c	Fri Feb 24 07:49:55 2012	(r232101)
 +++ head/usr.sbin/wake/wake.c	Fri Feb 24 07:54:08 2012	(r232102)
 @@ -183,7 +183,7 @@ send_wakeup(int bpf, struct ether_addr c
  int
  main(int argc, char *argv[])
  {
 -	int bpf, n;
 +	int bpf, n, rval;
  	char ifname[IF_NAMESIZE];
  
  	if (argc < 2)
 @@ -204,10 +204,13 @@ main(int argc, char *argv[])
  
  	if (n >= argc)
  		usage();
 -	for (; n < argc; n++)
 -		if (wake(bpf, argv[n]))
 +	rval = 0;
 +	for (; n < argc; n++) {
 +		if (wake(bpf, argv[n]) != 0) {
 +			rval = 1;
  			warn("Cannot send Wake on LAN frame over `%s' to `%s'",
  			    ifname, argv[n]);
 -
 -	return (0);
 +		}
 +	}
 +	exit(rval);
  }
 _______________________________________________
 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: jh 
State-Changed-When: Fri Feb 24 08:05:54 UTC 2012 
State-Changed-Why:  
Head version of wake(8) should exit with proper status after r232102. 
Thanks for your submission! 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/153527: commit references a PR
Date: Sat, 10 Mar 2012 08:28:19 +0000 (UTC)

 Author: jh
 Date: Sat Mar 10 08:27:37 2012
 New Revision: 232775
 URL: http://svn.freebsd.org/changeset/base/232775
 
 Log:
   MFC r232102: Exit with proper status when wake() fails.
   
   PR:		bin/153527
 
 Modified:
   stable/9/usr.sbin/wake/wake.c
 Directory Properties:
   stable/9/usr.sbin/wake/   (props changed)
 
 Modified: stable/9/usr.sbin/wake/wake.c
 ==============================================================================
 --- stable/9/usr.sbin/wake/wake.c	Sat Mar 10 08:25:49 2012	(r232774)
 +++ stable/9/usr.sbin/wake/wake.c	Sat Mar 10 08:27:37 2012	(r232775)
 @@ -183,7 +183,7 @@ send_wakeup(int bpf, struct ether_addr c
  int
  main(int argc, char *argv[])
  {
 -	int bpf, n;
 +	int bpf, n, rval;
  	char ifname[IF_NAMESIZE];
  
  	if (argc < 2)
 @@ -204,10 +204,13 @@ main(int argc, char *argv[])
  
  	if (n >= argc)
  		usage();
 -	for (; n < argc; n++)
 -		if (wake(bpf, argv[n]))
 +	rval = 0;
 +	for (; n < argc; n++) {
 +		if (wake(bpf, argv[n]) != 0) {
 +			rval = 1;
  			warn("Cannot send Wake on LAN frame over `%s' to `%s'",
  			    ifname, argv[n]);
 -
 -	return (0);
 +		}
 +	}
 +	exit(rval);
  }
 _______________________________________________
 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"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/153527: commit references a PR
Date: Wed, 16 May 2012 17:26:25 +0000 (UTC)

 Author: jh
 Date: Wed May 16 17:26:14 2012
 New Revision: 235509
 URL: http://svn.freebsd.org/changeset/base/235509
 
 Log:
   MFC r232102: Exit with proper status when wake() fails.
   
   PR:		bin/153527
 
 Modified:
   stable/8/usr.sbin/wake/wake.c
 Directory Properties:
   stable/8/usr.sbin/wake/   (props changed)
 
 Modified: stable/8/usr.sbin/wake/wake.c
 ==============================================================================
 --- stable/8/usr.sbin/wake/wake.c	Wed May 16 15:53:38 2012	(r235508)
 +++ stable/8/usr.sbin/wake/wake.c	Wed May 16 17:26:14 2012	(r235509)
 @@ -165,14 +165,17 @@ send_wakeup(int bpf, struct ether_addr c
  int
  main(int argc, char *argv[])
  {
 -	int n;
 +	int n, rval;
  
  	if (argc < 3)
  		usage();
  
 -	for (n = 2; n < argc; n++)
 -		if (wake(argv[1], argv[n]))
 +	for (n = 2; n < argc; n++) {
 +		if (wake(argv[1], argv[n])) {
 +			rval = 1;
  			warnx("error sending Wake on LAN frame over %s to %s",
  			    argv[1], argv[n]);
 -	return (0);
 +		}
 +	}
 +	exit(rval);
  }
 _______________________________________________
 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: patched->closed 
State-Changed-By: jh 
State-Changed-When: Wed May 16 18:15:07 UTC 2012 
State-Changed-Why:  
Fixed in head, stable/9 and stable/8. 

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