Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 12 Aug 2001 15:57:27 +0900
From:      "Akinori MUSHA" <knu@iDaemons.org>
To:        audit@FreeBSD.org
Subject:   adding -P option to pkg_delete(1)
Message-ID:  <86d761hijs.wl@archon.local.idaemons.org>
References:  <86elqphctp.wl@archon.local.idaemons.org>

next in thread | previous in thread | raw e-mail | index | archive | help
I'm resending this to audit@, since ports@ does not seem to
respond.. ;)

Please review the attached patch, which adds a new option "-P" to
pkg_delete(1) which preserves shared library files.  This is useful
when one suspects that s/he still have some binaries that depend on
the shared library that's being deleted.  Probably pkg_version(1) may
want to use the option for the -c feature.

If possible, I'd like to see this in the 4.4-RELEASE because that
would allow users to upgrade packages safely, which can only be done
by portupgrade(1) currently.

I've already implemented the equivalent in my pkg_deinstall(1) utility
bundled in sysutils/portupgrade, but it would be nice if pkg_delete(1)
had this feature in the first place.

Regards,

Index: add/perform.c
===================================================================
RCS file: /home/ncvs/src/usr.sbin/pkg_install/add/perform.c,v
retrieving revision 1.63
diff -u -r1.63 perform.c
--- add/perform.c	2001/08/02 13:13:05	1.63
+++ add/perform.c	2001/08/06 05:50:24
@@ -481,7 +481,7 @@
  fail:
     /* Nuke the whole (installed) show, XXX but don't clean directories */
     if (!Fake)
-	delete_package(FALSE, FALSE, &Plist);
+	delete_package(FALSE, FALSE, FALSE, &Plist);
 
  success:
     /* delete the packing list contents */
Index: delete/delete.h
===================================================================
RCS file: /home/ncvs/src/usr.sbin/pkg_install/delete/delete.h,v
retrieving revision 1.6
diff -u -r1.6 delete.h
--- delete/delete.h	2001/02/27 09:00:18	1.6
+++ delete/delete.h	2001/08/05 17:39:55
@@ -28,6 +28,7 @@
 extern Boolean	Interactive;
 extern Boolean	NoDeInstall;
 extern Boolean	Force;
+extern Boolean	PreserveShlib;
 extern char	*Directory;
 extern char	*PkgName;
 extern match_t	MatchType;
Index: delete/main.c
===================================================================
RCS file: /home/ncvs/src/usr.sbin/pkg_install/delete/main.c,v
retrieving revision 1.22
diff -u -r1.22 main.c
--- delete/main.c	2001/08/02 13:13:05	1.22
+++ delete/main.c	2001/08/06 06:22:43
@@ -30,12 +30,13 @@
 #include "lib.h"
 #include "delete.h"
 
-static char Options[] = "adDfGhinp:vx";
+static char Options[] = "adDfGhinp:Pvx";
 
 char	*Prefix		= NULL;
 Boolean	CleanDirs	= FALSE;
 Boolean	Interactive	= FALSE;
 Boolean	NoDeInstall	= FALSE;
+Boolean	PreserveShlib	= FALSE;
 match_t	MatchType	= MATCH_GLOB;
 
 static void usage __P((void));
@@ -93,6 +94,10 @@
 	    Interactive = TRUE;
 	    break;
 
+	case 'P':
+	    PreserveShlib = TRUE;
+	    break;
+
 	case 'h':
 	case '?':
 	default:
@@ -148,7 +153,7 @@
 usage()
 {
     fprintf(stderr, "%s\n%s\n",
-	"usage: pkg_delete [-dDfGinvx] [-p prefix] pkg-name ...",
+	"usage: pkg_delete [-dDfGinPvx] [-p prefix] pkg-name ...",
 	"       pkg_delete -a [flags]");
     exit(1);
 }
Index: delete/perform.c
===================================================================
RCS file: /home/ncvs/src/usr.sbin/pkg_install/delete/perform.c,v
retrieving revision 1.32
diff -u -r1.32 perform.c
--- delete/perform.c	2001/08/02 13:13:05	1.32
+++ delete/perform.c	2001/08/05 17:40:22
@@ -217,7 +217,7 @@
      * Some packages aren't packed right, so we need to just ignore
      * delete_package()'s status.  Ugh! :-(
      */
-    if (delete_package(FALSE, CleanDirs, &Plist) == FAIL)
+    if (delete_package(FALSE, CleanDirs, PreserveShlib, &Plist) == FAIL)
 	warnx(
 	"couldn't entirely delete package (perhaps the packing list is\n"
 	"incorrectly specified?)");
Index: delete/pkg_delete.1
===================================================================
RCS file: /home/ncvs/src/usr.sbin/pkg_install/delete/pkg_delete.1,v
retrieving revision 1.26
diff -u -r1.26 pkg_delete.1
--- delete/pkg_delete.1	2001/07/15 08:02:37	1.26
+++ delete/pkg_delete.1	2001/08/06 06:20:53
@@ -25,7 +25,7 @@
 .Nd a utility for deleting previously installed software package distributions
 .Sh SYNOPSIS
 .Nm
-.Op Fl dDfGinvx
+.Op Fl dDfGinPvx
 .Op Fl p Ar prefix
 .Ar pkg-name ...
 .Nm
@@ -91,6 +91,14 @@
 which do not explicitly set theirs.  For most packages, the prefix will
 be set automatically to the installed location by
 .Xr pkg_add 1 .
+.It Fl P
+Preserve (possible) shared library files that end with the
+.Dq .so ,
+.Dq .so.X ,
+or
+.Dq .so.X.Y
+suffix.  This is useful when you suspect that you still have some
+binaries that depend on the shared library being deleted.
 .It Fl d
 Remove empty directories created by file cleanup.  By default, only
 files/directories explicitly listed in a package's contents (either as
Index: lib/lib.h
===================================================================
RCS file: /home/ncvs/src/usr.sbin/pkg_install/lib/lib.h,v
retrieving revision 1.36
diff -u -r1.36 lib.h
--- lib/lib.h	2001/08/02 13:13:06	1.36
+++ lib/lib.h	2001/08/05 17:41:50
@@ -174,7 +174,7 @@
 void		write_plist(Package *, FILE *);
 void		read_plist(Package *, FILE *);
 int		plist_cmd(char *, char **);
-int		delete_package(Boolean, Boolean, Package *);
+int		delete_package(Boolean, Boolean, Boolean, Package *);
 Boolean 	make_preserve_name(char *, int, char *, char *);
 
 /* For all */
Index: lib/plist.c
===================================================================
RCS file: /home/ncvs/src/usr.sbin/pkg_install/lib/plist.c,v
retrieving revision 1.34
diff -u -r1.34 plist.c
--- lib/plist.c	2001/08/02 12:38:29	1.34
+++ lib/plist.c	2001/08/05 17:53:29
@@ -346,13 +346,48 @@
 }
 
 /*
+ * Check if the given filename looks like a shared library.
+ */
+static Boolean
+is_shlib(char *filename)
+{
+    char *p, *q;
+
+    /* basename */
+    if (NULL != (p = strrchr(filename, '/')))
+	p++;
+    else
+	p = filename;
+
+    /* empty filename or dotfile? */
+    if (*p == '\0' || *p == '.')
+	return FALSE;
+
+    /* do "strrstr" for .so */
+    if (NULL == (q = strstr(p + 1, ".so")))
+	return FALSE;
+    while (NULL != (p = strstr(q += 3, ".so")))
+	q = p;
+
+    /* skip version numbers */
+    while (*q) {
+	if (*q != '.' || !isdigit(*++q))
+	    return FALSE;
+	while (isdigit(*++q))
+	    ;
+    }
+
+    return TRUE;
+}
+
+/*
  * Delete the results of a package installation.
  *
  * This is here rather than in the pkg_delete code because pkg_add needs to
  * run it too in cases of failure.
  */
 int
-delete_package(Boolean ign_err, Boolean nukedirs, Package *pkg)
+delete_package(Boolean ign_err, Boolean nukedirs, Boolean preserve_shlib, Package *pkg)
 {
     PackingList p;
     char *Where = ".", *last_file = "";
@@ -389,7 +424,12 @@
 
 	case PLIST_FILE:
 	    last_file = p->name;
-	    sprintf(tmp, "%s/%s", Where, p->name);
+	    sprintf(tmp, "%s/%s", Where, last_file);
+	    if (preserve_shlib && is_shlib(last_file)) {
+		if (Verbose)
+		    printf("Preserve shared library file %s\n", tmp);
+		continue;
+	    }
 	    if (isdir(tmp) && fexists(tmp) && !issymlink(tmp)) {
 		warnx("cannot delete specified file '%s' - it is a directory!\n"
 	   "this packing list is incorrect - ignoring delete request", tmp);


-- 
                     /
                    /__  __            Akinori.org / MUSHA.org
                   / )  )  ) )  /     FreeBSD.org / Ruby-lang.org
Akinori MUSHA aka / (_ /  ( (__(  @ iDaemons.org / and.or.jp

"Freeze this moment a little bit longer, make each impression
  a little bit stronger..  Experience slips away -- Time stand still"

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-audit" in the body of the message




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