From nobody@FreeBSD.org  Wed Sep 13 02:54:11 2006
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 4BB3A16A412
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 13 Sep 2006 02:54:11 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [216.136.204.117])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 0CB4143D4C
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 13 Sep 2006 02:54:11 +0000 (GMT)
	(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 k8D2sANe066793
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 13 Sep 2006 02:54:10 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.13.1/8.13.1/Submit) id k8D2sAKx066792;
	Wed, 13 Sep 2006 02:54:10 GMT
	(envelope-from nobody)
Message-Id: <200609130254.k8D2sAKx066792@www.freebsd.org>
Date: Wed, 13 Sep 2006 02:54:10 GMT
From: John Hickey <jjh-freebsd@daedalian.us>
To: freebsd-gnats-submit@FreeBSD.org
Subject: tftp does not set proper exit status when a host is down.
X-Send-Pr-Version: www-2.3

>Number:         103206
>Category:       bin
>Synopsis:       [patch] tftp(1) does not set proper exit status when a host is down.
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    matteo
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Sep 13 03:00:41 GMT 2006
>Closed-Date:    Mon Oct 02 18:45:11 GMT 2006
>Last-Modified:  Mon Oct  2 18:50:21 GMT 2006
>Originator:     John Hickey
>Release:        FreeBSD 6.1-STABLE
>Organization:
>Environment:
FreeBSD monolith 6.1-STABLE FreeBSD 6.1-STABLE #3: Thu Jun 15 18:33:32 CDT 2006     root@monolith:/usr/src/sys/i386/compile/monolith  i386

>Description:
If a host is marked as down (e.g. we tried to reach it already with no sucess), tftp will return an exit status of 0.  The output from the code in "How to repeat the problem section" illustrates this behavior.

[host:~] > ./test                                                                                                                                                            
Transfer timed out.                                                                                   
                                                                                                                                                                                               
code=256                                                                           
tftp: sendto: Host is down                                                                                   
code=0                                                                               
[host:~] > 

                                                                     
Here is why we exit with code zero the second time, but not the first.                                
The initial timeout is handled by the function 'timer' in tftp, called by                             
sigalarm every so often.  This bails us out the first time.  More                                     
importantly, it sets the variable txrx_error to 1.  The second time we                                
try, the sendto in recvfile fails immediately.  This means we goto the                                
abort label in the recvfile function. Unfortunately nowhere along the way is                                   
txrx_error set to anything, so we get an exit code of 0.  The patch is                                
pretty simple, just add 'txrx_error = 1;' to the end of recvfile function,                            
which is where the abort code is (and I put it in sendfile for parity).                          
>How-To-Repeat:
Here is a small program to repeat the behavior (note the host 192.168.0.29 should be down):

   #include <stdio.h>                                                                                  
   #include <unistd.h>                                                                                           
   #include <stdlib.h>

   main() {                                                                            
       int code;                                                                                                 
                                                                                       
       do {                                                                                   
           code = system("echo get foobar | tftp 192.168.0.29");                                                                                         
           fprintf(stderr, "code=%i\n", code);                                                                                  
           if(code!=0) sleep(10);                                                                                        
       } while(code!=0);                                                                                                                                                             
   }
>Fix:
Index: tftp.c
===================================================================
RCS file: /home/ncvs/src/usr.bin/tftp/tftp.c,v
retrieving revision 1.12
diff -u -r1.12 tftp.c
--- tftp.c      5 Aug 2005 09:58:49 -0000       1.12
+++ tftp.c      13 Sep 2006 02:53:05 -0000
@@ -205,6 +205,7 @@
        stopclock();
        if (amount > 0)
                printstats("Sent", amount);
+       txrx_error = 1;
 }
 
 /*
@@ -330,6 +331,7 @@
        stopclock();
        if (amount > 0)
                printstats("Received", amount);
+       txrx_error = 1;
 }
 
 static int

>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->feedback 
State-Changed-By: matteo 
State-Changed-When: Thu Sep 28 20:01:15 UTC 2006 
State-Changed-Why:  
I asked for feedback 

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

From: Matteo Riondato <matteo@freebsd.org>
To: bug-followup@freebsd.org, jjh-freebsd@daedalian.us
Cc:  
Subject: Re: bin/103206
Date: Thu, 28 Sep 2006 22:00:42 +0200

 --uJWb33pM2TcUAXIl
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 Content-Transfer-Encoding: quoted-printable
 
 Everything works correctly here (CURRENT from Sep 17):
 (tftptest is your test program)
 
 [rionda@kaiser][~/branch/current/src/usr.bin/tftp]> echo get foobar |
 tftp 192.168.0.29
 Transfer timed out.
 
 [rionda@kaiser][~/branch/current/src/usr.bin/tftp]> echo $?
 1
 [rionda@kaiser][~/branch/current/src/usr.bin/tftp]> ./tftptest
 Transfer timed out.
 
 code=3D256
 Transfer timed out.
 
 code=3D256
 Transfer timed out.
 
 code=3D256
 Transfer timed out.
 
 Are you still having this issue?
 --=20
 Matteo Riondato
 FreeBSD Committer (http://www.freebsd.org)
 G.U.F.I. Staff Member (http://www.gufi.org)
 FreeSBIE Developer (http://www.freesbie.org)
 
 --uJWb33pM2TcUAXIl
 Content-Type: application/pgp-signature
 Content-Disposition: inline
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.4.5 (FreeBSD)
 
 iD8DBQFFHCnp2Mp4pR7Fa+wRAoUPAJ4kQPcYgjiDOFZKvdbvYIkEABIn2gCfVqtz
 QrAfXvimYTDQY8iQk73HxG8=
 =2Nlz
 -----END PGP SIGNATURE-----
 
 --uJWb33pM2TcUAXIl--
State-Changed-From-To: feedback->patched 
State-Changed-By: matteo 
State-Changed-When: Thu Sep 28 21:22:43 UTC 2006 
State-Changed-Why:  
I received the feedback and committed the fix to HEAD. I'll handle the MFC. 


Responsible-Changed-From-To: freebsd-bugs->matteo 
Responsible-Changed-By: matteo 
Responsible-Changed-When: Thu Sep 28 21:22:43 UTC 2006 
Responsible-Changed-Why:  
I'll handle the MFC. 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/103206: commit references a PR
Date: Thu, 28 Sep 2006 21:22:37 +0000 (UTC)

 matteo      2006-09-28 21:22:21 UTC
 
   FreeBSD src repository
 
   Modified files:
     usr.bin/tftp         tftp.c 
   Log:
   Set txrx_error to 1 when we reach abort. This makes the program correctly set the exit code.
   The PR has further details on this.
   
   PR:             bin/103206
   Submitted by:   John Hickey <jjh-freebsd@daedalian.us>
   MFC after:      3 days
   
   Revision  Changes    Path
   1.13      +2 -0      src/usr.bin/tftp/tftp.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: patched->closed 
State-Changed-By: matteo 
State-Changed-When: Mon Oct 2 18:44:36 UTC 2006 
State-Changed-Why:  
Fixed and merged to RELENG_6. Thanks! 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/103206: commit references a PR
Date: Mon,  2 Oct 2006 18:44:16 +0000 (UTC)

 matteo      2006-10-02 18:43:58 UTC
 
   FreeBSD src repository
 
   Modified files:        (Branch: RELENG_6)
     usr.bin/tftp         tftp.c 
   Log:
   MFC rev. 1.12 and rev. 1.13
   
   rev. 1.12 : use socklen_t where appropriate
   rev. 1.13 : Set txrx_error to 1 when we reach abort. This makes the program correctly set the exit code.
   The PR has further details on this. [2]
   
   PR:             bin/103206 [2]
   Approved by:    re@ (bmah@)
   
   Revision   Changes    Path
   1.11.14.1  +4 -2      src/usr.bin/tftp/tftp.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:
