From: Frank Ch. Eigler Date: Sun, 29 Mar 2020 19:10:37 +0000 (-0400) Subject: debuginfod-client default_progressfn: formatting fix X-Git-Tag: elfutils-0.179~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=03bb9dbb2d2ee515e3daee94ae1e2d36aeaedec7;p=platform%2Fupstream%2Felfutils.git debuginfod-client default_progressfn: formatting fix The saga of clean $DEBUGINFOD_PROGRESS=1 output continues. Previous code would sometimes insert a \n (a blank line) into the output stream, even if the target file was found in a cache and thus the progressfn was never called. New code sets a client flag to track this case more precisely. Signed-off-by: Frank Ch. Eigler --- diff --git a/debuginfod/ChangeLog b/debuginfod/ChangeLog index 193c272..9901c52 100644 --- a/debuginfod/ChangeLog +++ b/debuginfod/ChangeLog @@ -1,3 +1,11 @@ +2020-03-29 Frank Ch. Eigler + + * debuginfod-client.c (struct debuginfod_client): Add a flag field + for progressfn printing. + (default_progressfn): Set it if printing \rsomething. + (debuginfod_end): Terminate with \n if flag set, i.e., only if the + default_progressfn was actually called. + 2020-03-27 Mark Wielaard * debuginfod.cxx (parse_opt): Check port is not zero. diff --git a/debuginfod/debuginfod-client.c b/debuginfod/debuginfod-client.c index 043e8aa..fa017a8 100644 --- a/debuginfod/debuginfod-client.c +++ b/debuginfod/debuginfod-client.c @@ -89,6 +89,10 @@ struct debuginfod_client int user_agent_set_p; /* affects add_default_headers */ struct curl_slist *headers; + /* Flags the default_progressfn having printed something that + debuginfod_end needs to terminate. */ + int default_progressfn_printed_p; + /* Can contain all other context, like cache_path, server_urls, timeout or other info gotten from environment variables, the handle data, etc. So those don't have to be reparsed and @@ -438,6 +442,7 @@ default_progressfn (debuginfod_client *c, long a, long b) dprintf(STDERR_FILENO, "\rDownloading from %.*s %ld/%ld", len, url, a, b); + c->default_progressfn_printed_p = 1; return 0; } @@ -935,7 +940,10 @@ debuginfod_query_server (debuginfod_client *c, /* general purpose exit */ out: /* Conclude the last \r status line */ - if (c->progressfn == & default_progressfn) + /* Another possibility is to use the ANSI CSI n K EL "Erase in Line" + code. That way, the previously printed messages would be erased, + and without a newline. */ + if (c->default_progressfn_printed_p) dprintf(STDERR_FILENO, "\n"); free (cache_path);