Well, another approach..
Index: fetch.c
===================================================================
RCS file: /cvs/src/usr.bin/ftp/fetch.c,v
retrieving revision 1.134
diff -u -p -r1.134 fetch.c
--- fetch.c 31 Oct 2014 13:48:21 -0000 1.134
+++ fetch.c 24 Nov 2014 22:32:25 -0000
@@ -515,6 +515,10 @@ noslash:
}
#endif /* !SMALL */
+ /* ensure consistent order of the output */
+ if (verbose)
+ setvbuf(ttyout, NULL, _IONBF, 0);
+
s = -1;
for (res = res0; res; res = res->ai_next) {
if (getnameinfo(res->ai_addr, res->ai_addrlen, hbuf,
On Tue, Nov 25, 2014 at 12:02:51AM +0200, Kaspars Bankovskis wrote:
> Hi,
>
> it can be fixed by flushing the 'verbose' output:
>
> Index: fetch.c
> ===================================================================
> RCS file: /cvs/src/usr.bin/ftp/fetch.c,v
> retrieving revision 1.134
> diff -u -p -r1.134 fetch.c
> --- fetch.c 31 Oct 2014 13:48:21 -0000 1.134
> +++ fetch.c 24 Nov 2014 21:47:17 -0000
> @@ -520,8 +520,10 @@ noslash:
> if (getnameinfo(res->ai_addr, res->ai_addrlen, hbuf,
> sizeof(hbuf), NULL, 0, NI_NUMERICHOST) != 0)
> strlcpy(hbuf, "(unknown)", sizeof(hbuf));
> - if (verbose)
> + if (verbose) {
> fprintf(ttyout, "Trying %s...\n", hbuf);
> + fflush(ttyout);
> + }
>
> s = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
> if (s == -1) {
> @@ -620,8 +622,10 @@ again:
> fin = fdopen(s, "r+");
> #endif /* !SMALL */
>
> - if (verbose)
> + if (verbose) {
> fprintf(ttyout, "Requesting %s", origline);
> + fflush(ttyout);
> + }
>
> /*
> * Construct and send the request. Proxy requests don't want leading /.
> @@ -632,8 +636,11 @@ again:
>
> epath = url_encode(path);
> if (proxyurl) {
> - if (verbose)
> + if (verbose) {
> fprintf(ttyout, " (via %s)\n", proxyurl);
> + fflush(ttyout);
> + }
> +
> /*
> * Host: directive must use the destination host address for
> * the original URI (path). We do not attach it at this moment.
> @@ -704,8 +711,10 @@ again:
> #endif /* !SMALL */
> ftp_printf(fin, tls, "\r\n%s%s\r\n\r\n",
> buf ? buf : "", httpuseragent);
> - if (verbose)
> + if (verbose) {
> fprintf(ttyout, "\n");
> + fflush(ttyout);
> + }
> }
> free(epath);
>
> @@ -862,8 +871,10 @@ again:
> loctail = strchr(redirurl, '#');
> if (loctail != NULL)
> *loctail = '\0';
> - if (verbose)
> + if (verbose) {
> fprintf(ttyout, "Redirected to %s\n", redirurl);
> + fflush(ttyout);
> + }
> if (fin != NULL)
> fclose(fin);
> else if (s != -1)
> @@ -953,8 +964,10 @@ again:
> !resume &&
> #endif /* !SMALL */
> filesize != -1 && len == 0 && bytes != filesize) {
> - if (verbose)
> + if (verbose) {
> fputs("Read short file.\n", ttyout);
> + fflush(ttyout);
> + }
> goto cleanup_url_get;
> }
>
> @@ -1290,8 +1303,10 @@ bad_ftp_url:
> continue;
> }
>
> - if (verbose)
> + if (verbose) {
> fprintf(ttyout, "Retrieving %s/%s\n", dir ? dir : "",
> file);
> + fflush(ttyout);
> + }
>
> if (dirhasglob) {
> snprintf(rempath, sizeof(rempath), "%s/%s", dir, file);
>
>
>
> With this applied, the order is correct:
>
> $ ./ftp http://www.tedunangst.com/favicon.ico
> Trying 208.82.130.146...
> Requesting http://www.tedunangst.com/favicon.ico
> 100%
> |**************************************************************************************|
> 1106 00:00
> 1106 bytes received in 0.00 seconds (5.99 MB/s)
> $ ./ftp http://www.tedunangst.com/favicon.ico > log 2>&1
> $ cat log
> Trying 208.82.130.146...
> Requesting http://www.tedunangst.com/favicon.ico
> 1106 bytes received in 0.00 seconds (13.18 MB/s)
>
> On Sun, Nov 16, 2014 at 01:44:18PM -0500, Ted Unangst wrote:
> > Try an ftp command normally:
> >
> > ftp http://www.tedunangst.com/favicon.ico
> > Trying 208.82.130.146...
> > Requesting http://www.tedunangst.com/favicon.ico
> > 100% |************************| 1106 00:00
> > 1106 bytes received in 0.00 seconds (6.13 MB/s)
> >
> > OK. Looks good. Now try logging it.
> >
> > ftp http://www.tedunangst.com/favicon.ico > log 2>&1
> > cat log
> > 1106 bytes received in 0.00 seconds (11.59 MB/s)
> > Trying 208.82.130.146...
> > Requesting http://www.tedunangst.com/favicon.ico
> >
> > What? It's backwards! This certainly does not make log inspection any
> > easier.
> >
>