From owner-freebsd-bugs@FreeBSD.ORG Fri Jun 15 06:40:02 2007 Return-Path: X-Original-To: freebsd-bugs@hub.freebsd.org Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 4E89416A469 for ; Fri, 15 Jun 2007 06:40:02 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [69.147.83.40]) by mx1.freebsd.org (Postfix) with ESMTP id 2D39713C455 for ; Fri, 15 Jun 2007 06:40:02 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.4/8.13.4) with ESMTP id l5F6e2uc070705 for ; Fri, 15 Jun 2007 06:40:02 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.4/8.13.4/Submit) id l5F6e1xq070704; Fri, 15 Jun 2007 06:40:02 GMT (envelope-from gnats) Resent-Date: Fri, 15 Jun 2007 06:40:02 GMT Resent-Message-Id: <200706150640.l5F6e1xq070704@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Ighighi Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id B522916A400 for ; 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 ; 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 ; 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 To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.0 Cc: Subject: bin/113702: [PATCH]: bad output from "pkginfo -g" X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 15 Jun 2007 06:40:02 -0000 >Number: 113702 >Category: bin >Synopsis: [PATCH]: bad output from "pkginfo -g" >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: Fri Jun 15 06:40:01 GMT 2007 >Closed-Date: >Last-Modified: >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: >Unformatted: