From owner-freebsd-bugs@FreeBSD.ORG  Mon Sep 21 14:10:01 2009
Return-Path: <owner-freebsd-bugs@FreeBSD.ORG>
Delivered-To: freebsd-bugs@hub.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id A06871065693
	for <freebsd-bugs@hub.freebsd.org>;
	Mon, 21 Sep 2009 14:10:01 +0000 (UTC)
	(envelope-from gnats@FreeBSD.org)
Received: from freefall.freebsd.org (freefall.freebsd.org
	[IPv6:2001:4f8:fff6::28])
	by mx1.freebsd.org (Postfix) with ESMTP id 7D8C18FC13
	for <freebsd-bugs@hub.freebsd.org>;
	Mon, 21 Sep 2009 14:10:01 +0000 (UTC)
Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1])
	by freefall.freebsd.org (8.14.3/8.14.3) with ESMTP id n8LEA11c017323
	for <freebsd-bugs@freefall.freebsd.org>; Mon, 21 Sep 2009 14:10:01 GMT
	(envelope-from gnats@freefall.freebsd.org)
Received: (from gnats@localhost)
	by freefall.freebsd.org (8.14.3/8.14.3/Submit) id n8LEA1Wa017322;
	Mon, 21 Sep 2009 14:10:01 GMT (envelope-from gnats)
Resent-Date: Mon, 21 Sep 2009 14:10:01 GMT
Resent-Message-Id: <200909211410.n8LEA1Wa017322@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,
	Anton Yuzhaninov <citrin@citrin.ru>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 8FAF21065676
	for <freebsd-gnats-submit@FreeBSD.org>;
	Mon, 21 Sep 2009 14:05:36 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id 744278FC1A
	for <freebsd-gnats-submit@FreeBSD.org>;
	Mon, 21 Sep 2009 14:05:36 +0000 (UTC)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.3/8.14.3) with ESMTP id n8LE5Z8W014986
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 21 Sep 2009 14:05:35 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.3/8.14.3/Submit) id n8LE5ZZc014984;
	Mon, 21 Sep 2009 14:05:35 GMT (envelope-from nobody)
Message-Id: <200909211405.n8LE5ZZc014984@www.freebsd.org>
Date: Mon, 21 Sep 2009 14:05:35 GMT
From: Anton Yuzhaninov <citrin@citrin.ru>
To: freebsd-gnats-submit@FreeBSD.org
X-Send-Pr-Version: www-3.1
Cc: 
Subject: bin/139015: [patch] pkg_info -g
X-BeenThere: freebsd-bugs@freebsd.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: Bug reports <freebsd-bugs.freebsd.org>
List-Unsubscribe: <http://lists.freebsd.org/mailman/listinfo/freebsd-bugs>,
	<mailto:freebsd-bugs-request@freebsd.org?subject=unsubscribe>
List-Archive: <http://lists.freebsd.org/pipermail/freebsd-bugs>
List-Post: <mailto:freebsd-bugs@freebsd.org>
List-Help: <mailto:freebsd-bugs-request@freebsd.org?subject=help>
List-Subscribe: <http://lists.freebsd.org/mailman/listinfo/freebsd-bugs>,
	<mailto:freebsd-bugs-request@freebsd.org?subject=subscribe>
X-List-Received-Date: Mon, 21 Sep 2009 14:10:01 -0000


>Number:         139015
>Category:       bin
>Synopsis:       [patch] pkg_info -g
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Mon Sep 21 14:10:01 UTC 2009
>Closed-Date:
>Last-Modified:
>Originator:     Anton Yuzhaninov
>Release:        7.2-STABLE
>Organization:
>Environment:
>Description:
pkg_info -g allow to check package integrity, but exit code always 0 even if checksum for some files mismatch.

This makes pkg_info -g hard to use in shell scripts.
>How-To-Repeat:
1. install some package
2. edit some of installed files
3. run:
pkg_info -g package
echo $?

pkg_info -g will show checksum mismatch, but exit code will be 0.
>Fix:
exit with non zero exit code, when checksum mismatch discovered.

Patch attached with submission follows:

--- usr.sbin/pkg_install/info/perform.c.orig	2009-08-19 12:12:03.000000000 +0000
+++ usr.sbin/pkg_install/info/perform.c	2009-08-19 15:16:37.000000000 +0000
@@ -221,7 +221,7 @@ pkg_do(char *pkg)
 	if ((Flags & SHOW_SIZE) && installed)
 	    show_size("Package Size:\n", &plist);
 	if ((Flags & SHOW_CKSUM) && installed)
-	    show_cksum("Mismatched Checksums:\n", &plist);
+	    code += show_cksum("Mismatched Checksums:\n", &plist);
 	if (Flags & SHOW_ORIGIN)
 	    show_origin("Origin:\n", &plist);
 	if (Flags & SHOW_FMTREV)
@@ -234,7 +234,7 @@ pkg_do(char *pkg)
     leave_playpen();
     if (isTMP)
 	unlink(fname);
-    return code;
+    return (code ? 1 : 0);
 }
 
 void
--- usr.sbin/pkg_install/info/show.c.orig	2009-08-19 12:12:10.000000000 +0000
+++ usr.sbin/pkg_install/info/show.c	2009-08-19 12:49:36.000000000 +0000
@@ -308,13 +308,14 @@ show_size(const char *title, Package *pl
 }
 
 /* Show files that don't match the recorded checksum */
-void
+int
 show_cksum(const char *title, Package *plist)
 {
     PackingList p;
     const char *dir = ".";
     char *prefix = NULL;
     char tmp[FILENAME_MAX];
+    int errcode = 0;
 
     if (!Quiet)
 	printf("%s%s", InfoPrefix, title);
@@ -329,9 +330,10 @@ show_cksum(const char *title, Package *p
 		dir = p->name;
 	} else if (p->type == PLIST_FILE) {
 	    snprintf(tmp, FILENAME_MAX, "%s/%s", dir, p->name);
-	    if (!fexists(tmp))
+	    if (!fexists(tmp)) {
 		warnx("%s doesn't exist", tmp);
-	    else if (p->next && p->next->type == PLIST_COMMENT &&
+		errcode = 1;
+	    } else if (p->next && p->next->type == PLIST_COMMENT &&
 	             (strncmp(p->next->name, "MD5:", 4) == 0)) {
 		char *cp = NULL, buf[33];
 
@@ -351,13 +353,15 @@ show_cksum(const char *title, Package *p
 
 		if (cp != NULL) {
 		    /* Mismatch? */
-		    if (strcmp(cp, p->next->name + 4))
+		    if (strcmp(cp, p->next->name + 4)) {
 			printf("%s fails the original MD5 checksum\n", tmp);
-		    else if (Verbose)
+			errcode = 1;
+		    } else if (Verbose)
 			printf("%s matched the original MD5 checksum\n", tmp);
 		}
 	    }
 	}
+    return errcode;
 }
 
 /* Show an "origin" path (usually category/portname) */
--- usr.sbin/pkg_install/info/info.h.orig	2009-08-19 12:16:47.000000000 +0000
+++ usr.sbin/pkg_install/info/info.h	2009-08-19 12:17:10.000000000 +0000
@@ -77,7 +77,7 @@ extern void	show_plist(const char *, Pac
 extern void	show_files(const char *, Package *);
 extern void	show_index(const char *, const char *);
 extern void	show_size(const char *, Package *);
-extern void	show_cksum(const char *, Package *);
+extern int	show_cksum(const char *, Package *);
 extern void	show_origin(const char *, Package *);
 extern void	show_fmtrev(const char *, Package *);
 


>Release-Note:
>Audit-Trail:
>Unformatted: