From nobody@FreeBSD.org  Wed Jun  1 14:11:18 2011
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 D0D7F1065670
	for <freebsd-gnats-submit@FreeBSD.org>; Wed,  1 Jun 2011 14:11:18 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id A85538FC0A
	for <freebsd-gnats-submit@FreeBSD.org>; Wed,  1 Jun 2011 14:11:18 +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 p51EBIJ9001008
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 1 Jun 2011 14:11:18 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.4/8.14.4/Submit) id p51EBI1E001007;
	Wed, 1 Jun 2011 14:11:18 GMT
	(envelope-from nobody)
Message-Id: <201106011411.p51EBI1E001007@red.freebsd.org>
Date: Wed, 1 Jun 2011 14:11:18 GMT
From: Konstantin <konstantin.malov@kaspersky.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: fetch confused me with it's error message
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         157499
>Category:       bin
>Synopsis:       fetch(1) confused me with its error message
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Jun 01 14:20:05 UTC 2011
>Closed-Date:    
>Last-Modified:  Thu Jun  2 09:10:09 UTC 2011
>Originator:     Konstantin
>Release:        8.2-RELEASE/7.3-RELEASE
>Organization:
Kaspersky Lab
>Environment:
FreeBSD ourhost.kaspersky.com 7.3-RELEASE-p3 FreeBSD 7.3-RELEASE-p3 #0: Tue Sep 21 18:03:17 MSD 2010     root@ourhost.kaspersky.com:/usr/obj/usr/src/sys/GENERIC  amd64

>Description:
I have found out some strange error handling in /usr/bin/fetch.
Here it is: 

# fetch ftp://ftp.freebsd.org/pub/FreeBSD/ports/ports/ports.tar.gz
fetch: ftp://ftp.freebsd.org/pub/FreeBSD/ports/ports/ports.tar.gz: Syntax error, command unrecognized

So it's very confusing error message. With some extra debug it looks more clear: 

# fetch -vvv ftp://ftp.freebsd.org/pub/FreeBSD/ports/ports/ports.tar.gz
scheme:   [ftp]
user:     []
password: []
host:     [ftp.freebsd.org]
port:     [0]
document: [/pub/FreeBSD/ports/ports/ports.tar.gz]
---> ftp.freebsd.org:21
looking up ftp.freebsd.org
connecting to ftp.freebsd.org:21
<<< 220 Welcome to freebsd.isc.org.
>How-To-Repeat:

>Fix:


>Release-Note:
>Audit-Trail:

From: Jaakko Heinonen <jh@FreeBSD.org>
To: Konstantin <konstantin.malov@kaspersky.com>
Cc: bug-followup@FreeBSD.org
Subject: Re: misc/157499: fetch confused me with it's error message
Date: Thu, 2 Jun 2011 11:01:22 +0300

 On 2011-06-01, Konstantin wrote:
 > I have found out some strange error handling in /usr/bin/fetch.
 > Here it is: 
 > 
 > # fetch ftp://ftp.freebsd.org/pub/FreeBSD/ports/ports/ports.tar.gz
 > fetch: ftp://ftp.freebsd.org/pub/FreeBSD/ports/ports/ports.tar.gz: Syntax error, command unrecognized
 
 >  >>> USER anonymous
 >  <<< 331 Please specify the password.
 >  >>> PASS root@h-ksn-hkg-fe-2.kaspersky-labs.com
 >  <<< 500 OOPS: cannot change directory:/home/ftp
 >  fetch: ftp://ftp.freebsd.org/pub/FreeBSD/ports/ports/ports.tar.gz: Syntax error, command unrecognized
 
 This is how reply code 500 is defined in RFC 959:
 
 500	Syntax error, command unrecognized.
 	This may include errors such as command line too long.
 
 -- 
 Jaakko

From: Konstantin Malov <Konstantin.Malov@kaspersky.com>
To: Jaakko Heinonen <jh@FreeBSD.org>
Cc: "bug-followup@FreeBSD.org" <bug-followup@FreeBSD.org>
Subject: RE: misc/157499: fetch confused me with it's error message
Date: Thu, 2 Jun 2011 12:48:07 +0400

 I agree with this.
 So real problem is that this error message 'Syntax error, command unrecogni=
 zed' appears with warnx function:=20
 warnx("%s: %s", URL, fetchLastErrString);=20
 
 There are three such places in fetch.c where warnx is used without addition=
 al information about error cause. I don't know what to add in this place:=20
 
     402         /* set the protocol timeout. */
     403         fetchTimeout =3D timeout;
     404
     405         /* just print size */
     406         if (s_flag) {
     407                 if (timeout)
     408                         alarm(timeout);
     409                 r =3D fetchStat(url, &us, flags);
     410                 if (timeout)
     411                         alarm(0);
     412                 if (sigalrm || sigint)
     413                         goto signal;
     414                 if (r =3D=3D -1) {
     415                         warnx("%s", fetchLastErrString);
     416                         goto failure;
     417                 }
     418                 if (us.size =3D=3D -1)
     419                         printf("Unknown\n");
     420                 else
     421                         printf("%jd\n", (intmax_t)us.size);
     422                 goto success;
     423         }
 
 But for last two I can suggest this patch:=20
 
 --- fetch.c.orig        2011-06-02 12:06:26.000000000 +0400
 +++ fetch.c     2011-06-02 12:28:25.000000000 +0400
 @@ -463,7 +463,7 @@
         if (sigalrm || sigint)
                 goto signal;
         if (f =3D=3D NULL) {
 -               warnx("%s: %s", URL, fetchLastErrString);
 +               warnx("data fetch from '%s' failed with error: %s", URL, fe=
 tchLastErrString);
                 if (i_flag && strcmp(url->scheme, SCHEME_HTTP) =3D=3D 0
                     && fetchLastErrCode =3D=3D FETCH_OK
                     && strcmp(fetchLastErrString, "Not Modified") =3D=3D 0)=
  {
 @@ -574,7 +574,7 @@
                          */
                         url->offset =3D 0;
                         if ((f =3D fetchXGet(url, &us, flags)) =3D=3D NULL)=
  {
 -                               warnx("%s: %s", URL, fetchLastErrString);
 +                               warnx("data fetch from '%s' failed with err=
 or: %s", URL, fetchLastErrString);
                                 goto failure;
                         }
                         if (sigint)
 
 -----Original Message-----
 From: Jaakko Heinonen [mailto:jh@FreeBSD.org]=20
 Sent: Thursday, June 02, 2011 12:01 PM
 To: Konstantin Malov
 Cc: bug-followup@FreeBSD.org
 Subject: Re: misc/157499: fetch confused me with it's error message
 
 On 2011-06-01, Konstantin wrote:
 > I have found out some strange error handling in /usr/bin/fetch.
 > Here it is:=20
 >=20
 > # fetch ftp://ftp.freebsd.org/pub/FreeBSD/ports/ports/ports.tar.gz
 > fetch: ftp://ftp.freebsd.org/pub/FreeBSD/ports/ports/ports.tar.gz: Syntax=
  error, command unrecognized
 
 >  >>> USER anonymous
 >  <<< 331 Please specify the password.
 >  >>> PASS root@h-ksn-hkg-fe-2.kaspersky-labs.com
 >  <<< 500 OOPS: cannot change directory:/home/ftp
 >  fetch: ftp://ftp.freebsd.org/pub/FreeBSD/ports/ports/ports.tar.gz: Synta=
 x error, command unrecognized
 
 This is how reply code 500 is defined in RFC 959:
 
 500	Syntax error, command unrecognized.
 	This may include errors such as command line too long.
 
 --=20
 Jaakko
>Unformatted:
 >>> USER anonymous
 <<< 331 Please specify the password.
 >>> PASS root@h-ksn-hkg-fe-2.kaspersky-labs.com
 <<< 500 OOPS: cannot change directory:/home/ftp
 fetch: ftp://ftp.freebsd.org/pub/FreeBSD/ports/ports/ports.tar.gz: Syntax error, command unrecognized
 
 # host ftp.freebsd.org
 ftp.freebsd.org has address 204.152.184.73
 ftp.freebsd.org has address 87.51.34.132
 ftp.freebsd.org has address 149.20.64.73
 ftp.freebsd.org has IPv6 address 2001:4f8:0:2::e
 ftp.freebsd.org has IPv6 address 2001:6c8:2:600::132
 
 Actually this problem exists only with 204.152.184.73 server. See ftp connect to it:
 # ftp
 ftp> open ftp.freebsd.org
 Trying 204.152.184.73...
 Connected to ftp.freebsd.org.
 220 Welcome to freebsd.isc.org.
 Name (ftp.freebsd.org:root): ftp
 331 Please specify the password.
 Password:
 500 OOPS: cannot change directory:/home/ftp
 ftp: Login failed.
 ftp> exit
 500 OOPS: priv_sock_get_cmd
 
 I don't know why fetch on 7.3 sticked to this server and I had error 'Syntax error, command unrecognized' every time I run fetch. It could be some problem in DNS resolving algorithm on 7.3. On 8.2 fetch works with different servers, so I had this error n ot very often.    
 
 Anyway, error message 'Syntax error, command unrecognized' on some FTP problems sounds very confusing for me.
