Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 21 Sep 2009 14:05:35 GMT
From:      Anton Yuzhaninov <citrin@citrin.ru>
To:        freebsd-gnats-submit@FreeBSD.org
Subject:   bin/139015: [patch] pkg_info -g
Message-ID:  <200909211405.n8LE5ZZc014984@www.freebsd.org>
Resent-Message-ID: <200909211410.n8LEA1Wa017322@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>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:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200909211405.n8LE5ZZc014984>