From nobody@FreeBSD.org  Fri Jun 15 06:33:58 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 B522916A400
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 15 Jun 2007 06:33:58 +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 A3F9113C44C
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 15 Jun 2007 06:33:58 +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 l5F6Xwab034998
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 15 Jun 2007 06:33:58 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.13.1/8.13.1/Submit) id l5F6XwBe034996;
	Fri, 15 Jun 2007 06:33:58 GMT
	(envelope-from nobody)
Message-Id: <200706150633.l5F6XwBe034996@www.freebsd.org>
Date: Fri, 15 Jun 2007 06:33:58 GMT
From: Ighighi <ighighi@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [PATCH]: bad output from "pkginfo -g"
X-Send-Pr-Version: www-3.0

>Number:         113702
>Category:       bin
>Synopsis:       [patch] bad output from "pkginfo -g"
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bapt
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Jun 15 06:40:01 GMT 2007
>Closed-Date:    Tue Oct 02 17:07:40 UTC 2012
>Last-Modified:  Tue Oct 02 17:07:40 UTC 2012
>Originator:     Ighighi
>Release:        6.2-STABLE
>Organization:
>Environment:
FreeBSD orion 6.2-STABLE FreeBSD 6.2-STABLE #1: Tue Jun 12 20:39:04 VET 2007     root@orion:/usr/obj/usr/src/sys/CUSTOM  i386
>Description:
When multiple packages are processed by "pkginfo -g" to "show files that do not match
the recorded checksum" and output is save to a file or to a pipe, error messages
relative to a package are printed before the "Information for $PACKAGE:" line,
thus confusing the user on the real package that is having problems.

It doesn't happen when output is printed to a terminal because stdout is
line-buffered in this case, else it is block buffered and any error messages
could be written before the "Information for $PACKAGE:" line.

The solution (contained in the attached patch) is an explicit fflush(stdout)
after the printf() of the line above.  There are 2 other functions that contains
calls that print to stderr that I patched.  The 3 modified functions are:
show_index(), show_plist() & show_cksum()
The file in question is src/usr.sbin/pkg_install/info/show.c

Note: The very first function show_file() contains this line:
printf("ERROR: show_file: Can't open '%s' for reading!\n", fname);

Why not make most errors in this command print to stdout ?
Anyway the attached patch preserves the current functionality (tested on
6.2-STABLE and -CURRENT) and just adds the fflush(stdout) after the information
line for each package.

>How-To-Repeat:
# pkg_which /usr/local/lib/AbiWord-2.4/plugins/libAbiApplix.la
abiword-plugins-2.4.6
# pkg_info -gx ^abiword
Information for abiword-2.4.6:

Mismatched Checksums:

Information for abiword-plugins-2.4.6:

Mismatched Checksums:
pkg_info: /usr/local/lib/AbiWord-2.4/plugins/libAbiApplix.la doesn't exist
pkg_info: /usr/local/lib/AbiWord-2.4/plugins/libAbiApplix.so doesn't exist
                                                                                     
# pkg_info -gx ^abiword >abiword.txt 2>&1
# cat abiword.txt
pkg_info: /usr/local/lib/AbiWord-2.4/plugins/libAbiApplix.la doesn't exist
pkg_info: /usr/local/lib/AbiWord-2.4/plugins/libAbiApplix.so doesn't exist
Information for abiword-2.4.6:

Mismatched Checksums:

Information for abiword-plugins-2.4.6:

Mismatched Checksums:
                                                                                     

>Fix:
As root, download attached patch and run:
patch -d /usr < /path/to/patch
cd /usr/src/usr.sbin/pkg_install/info
make clean
make obj depend && make && make install


Patch attached with submission follows:

--- src/usr.sbin/pkg_install/info/show.c.orig	Thu Feb 15 05:23:34 2007
+++ src/usr.sbin/pkg_install/info/show.c	Fri Jun 15 02:15:47 2007
@@ -61,8 +61,11 @@
 
     strlcpy(line, "???\n", sizeof(line));
 
-    if (!Quiet)
+    if (!Quiet) {
         printf("%s%s", InfoPrefix, title);
+	fflush(stdout);
+    }
+
     fp = fopen(fname, "r");
     if (fp == (FILE *) NULL) {
         warnx("show_file: can't open '%s' for reading", fname);
@@ -88,8 +91,11 @@
     Boolean ign = FALSE;
     char *prefix = NULL;
 
-    if (!Quiet)
+    if (!Quiet) {
 	printf("%s%s", InfoPrefix, title);
+	fflush(stdout);
+    }
+
     p = plist->head;
     while (p) {
 	if (p->type != type && showall != TRUE) {
@@ -316,8 +322,10 @@
     char *prefix = NULL;
     char tmp[FILENAME_MAX];
 
-    if (!Quiet)
+    if (!Quiet) {
 	printf("%s%s", InfoPrefix, title);
+	fflush(stdout);
+    }
 
     for (p = plist->head; p != NULL; p = p->next)
 	if (p->type == PLIST_CWD) {


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->krion 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Fri Jun 15 07:02:32 UTC 2007 
Responsible-Changed-Why:  
Over to maintainer. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=113702 
Responsible-Changed-From-To: krion->portmgr 
Responsible-Changed-By: flz 
Responsible-Changed-When: Fri Jul 17 13:41:37 UTC 2009 
Responsible-Changed-Why:  
pkg_install is maintained by portmgr. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=113702 
State-Changed-From-To: open->patched 
State-Changed-By: bapt 
State-Changed-When: Tue Sep 18 22:12:36 UTC 2012 
State-Changed-Why:  
awaiting MFC 


Responsible-Changed-From-To: portmgr->bapt 
Responsible-Changed-By: bapt 
Responsible-Changed-When: Tue Sep 18 22:12:36 UTC 2012 
Responsible-Changed-Why:  
awaiting MFC 

http://www.freebsd.org/cgi/query-pr.cgi?pr=113702 
State-Changed-From-To: patched->closed 
State-Changed-By: bapt 
State-Changed-When: Tue Oct 2 17:07:39 UTC 2012 
State-Changed-Why:  
MFCed, thanks! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=113702 
>Unformatted:
