From nobody@FreeBSD.org  Tue May  1 13:48:49 2007
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52])
	by hub.freebsd.org (Postfix) with ESMTP id F011716A401
	for <freebsd-gnats-submit@FreeBSD.org>; Tue,  1 May 2007 13:48:49 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [69.147.83.33])
	by mx1.freebsd.org (Postfix) with ESMTP id E26D313C480
	for <freebsd-gnats-submit@FreeBSD.org>; Tue,  1 May 2007 13:48:49 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.13.1/8.13.1) with ESMTP id l41Dmn6x031283
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 1 May 2007 13:48:49 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.13.1/8.13.1/Submit) id l41DhmfE020416;
	Tue, 1 May 2007 13:43:48 GMT
	(envelope-from nobody)
Message-Id: <200705011343.l41DhmfE020416@www.freebsd.org>
Date: Tue, 1 May 2007 13:43:48 GMT
From: Colin Petrie<cpetrie@xcalibre.co.uk>
To: freebsd-gnats-submit@FreeBSD.org
Subject: 'route get' returns wrong exit code if no match
X-Send-Pr-Version: www-3.0

>Number:         112303
>Category:       bin
>Synopsis:       [patch] route(8): 'route get' returns wrong exit code if no match
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    remko
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue May 01 13:50:02 GMT 2007
>Closed-Date:    Sat Mar 29 13:44:53 UTC 2008
>Last-Modified:  Sat Mar 29 13:50:07 UTC 2008
>Originator:     Colin Petrie
>Release:        6.2-RELEASE
>Organization:
>Environment:
FreeBSD xxx.xxx.xxx 6.2-RELEASE FreeBSD 6.2-RELEASE #1: Mon Mar 26 18:27:24 BST 2007     root@xxx.xxx.xxx:/usr/src/sys/i386/compile/CUSTOM  i386

>Description:
When using 'route get' to display the routing table entry for an IP
address, if there is no matching table entry, the command outputs an
error to STDERR, but exits with a exit code of 0.

Given that the message is output to STDERR, this would suggest that the
route command considers this to be an error, therefore should it not exit
with a non-zero exit code?
>How-To-Repeat:
# route get www.google.com
   route to: lm-in-f147.google.com
destination: 66.102.8.0
       mask: 255.255.254.0
    gateway: tr1
  interface: vlan401
      flags: <UP,GATEWAY,DONE,PROTO1>
 recvpipe  sendpipe  ssthresh  rtt,msec    rttvar  hopcount      mtu     expire
       0         0         0         0         0         0      1500         0 
# echo $?
0

# route get 192.168.1.1
route: writing to routing socket: No such process
# echo $?
0


>Fix:

>Release-Note:
>Audit-Trail:

From: bruce@cran.org.uk
To: bug-followup@freebsd.org
Cc: cpetrie@xcalibre.co.uk
Subject: Re: bin/112303: route(8): 'route get' returns wrong exit code if no match
Date: Sat, 15 Mar 2008 01:02:14 +0000

 --fUYQa+Pmc3FrFX/N
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 
 In route.c in newroute() there's a call to exit(0) if the command was
 'get'.  Since rtmsg() always gets called and returns 0 on success and -1
 on failure, it's possible to exit with a suitable exit code by calling
 exit(ret != 0) instead, as is done at the end of newroute().
 
 --
 Bruce
 
 --fUYQa+Pmc3FrFX/N
 Content-Type: text/x-diff; charset=us-ascii
 Content-Disposition: attachment; filename="route.c.diff"
 
 --- route_old.c	2008-03-15 00:42:34.000000000 +0000
 +++ route.c	2008-03-15 00:40:41.000000000 +0000
 @@ -748,7 +748,7 @@
  			break;
  	}
  	if (*cmd == 'g')
 -		exit(0);
 +		exit(ret != 0);
  	if (!qflag) {
  		oerrno = errno;
  		(void) printf("%s %s %s", cmd, ishost? "host" : "net", dest);
 
 --fUYQa+Pmc3FrFX/N--
Responsible-Changed-From-To: freebsd-bugs->remko 
Responsible-Changed-By: remko 
Responsible-Changed-When: Sat Mar 22 12:26:47 UTC 2008 
Responsible-Changed-Why:  
I'll take it. 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/112303: commit references a PR
Date: Sat, 22 Mar 2008 12:50:49 +0000 (UTC)

 remko       2008-03-22 12:50:44 UTC
 
   FreeBSD src repository
 
   Modified files:
     sbin/route           route.c 
   Log:
   In route.c in newroute() there's a call to exit(0) if the command was
   'get'. Since rtmsg() always gets called and returns 0 on success and -1
   on failure, it's possible to exit with a suitable exit code by calling
   exit(ret != 0) instead, as is done at the end of newroute().
   
   PR:             bin/112303
   Submitted by:   bruce@cran.org.uk
   MFC after:      1 week
   
   Revision  Changes    Path
   1.84      +1 -1      src/sbin/route/route.c
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: open->closed 
State-Changed-By: remko 
State-Changed-When: Sat Mar 29 13:44:52 UTC 2008 
State-Changed-Why:  
Committed. Thanks! 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/112303: commit references a PR
Date: Sat, 29 Mar 2008 13:43:42 +0000 (UTC)

 remko       2008-03-29 13:43:37 UTC
 
   FreeBSD src repository
 
   Modified files:        (Branch: RELENG_7)
     sbin/route           route.c 
   Log:
   MFC rev 1.84 route.c
   
     In route.c in newroute() there's a call to exit(0) if the command was
     'get'. Since rtmsg() always gets called and returns 0 on success and -1
     on failure, it's possible to exit with a suitable exit code by calling
     exit(ret != 0) instead, as is done at the end of newroute().
   
     PR:           bin/112303
     Submitted by: bruce@cran.org.uk
     MFC after:    1 week
   
   Approved by:    imp (mentor, implicit)
   
   Revision  Changes    Path
   1.81.2.2  +1 -1      src/sbin/route/route.c
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/112303: commit references a PR
Date: Sat, 29 Mar 2008 13:44:41 +0000 (UTC)

 remko       2008-03-29 13:44:36 UTC
 
   FreeBSD src repository
 
   Modified files:        (Branch: RELENG_6)
     sbin/route           route.c 
   Log:
   MFC rev 1.84 route.c
   
     In route.c in newroute() there's a call to exit(0) if the command was
     'get'. Since rtmsg() always gets called and returns 0 on success and -1
     on failure, it's possible to exit with a suitable exit code by calling
     exit(ret != 0) instead, as is done at the end of newroute().
   
     PR:           bin/112303
     Submitted by: bruce@cran.org.uk
     MFC after:    1 week
   
   Approved by:    imp (mentor, implicit)
   
   Revision  Changes    Path
   1.79.2.3  +1 -1      src/sbin/route/route.c
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 
>Unformatted:
