Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 28 May 2010 09:14:53 GMT
From:      Garrett Cooper <gcooper@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 178903 for review
Message-ID:  <201005280914.o4S9ErMq016491@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://p4web.freebsd.org/@@178903?ac=10

Change 178903 by gcooper@gcooper-bayonetta on 2010/05/28 09:13:57

	1. Remove all of those whacky cleanup calls spread across the code like
	   strawberry jam -- because we're using atexit(3) now (as suggested by
	   kientzle)!
	2. Reintroduce usr.sbin/pkg_install/lib with ONLY pkg_install
	   infrastructure client bits. Ya heard?!
	
	Yes, the compile's broken, but will be fixed shortly. I just wanted to
	checkpoint this code. k, thx...

Affected files ...

.. //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/usr.sbin/pkg_install/Makefile#3 edit
.. //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/usr.sbin/pkg_install/Makefile.inc#4 edit
.. //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/usr.sbin/pkg_install/add/Makefile#5 edit
.. //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/usr.sbin/pkg_install/add/extract.c#5 edit
.. //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/usr.sbin/pkg_install/add/perform.c#15 edit
.. //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/usr.sbin/pkg_install/create/Makefile#6 edit
.. //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/usr.sbin/pkg_install/create/perform.c#29 edit
.. //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/usr.sbin/pkg_install/create/pl.c#4 edit
.. //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/usr.sbin/pkg_install/delete/Makefile#5 edit
.. //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/usr.sbin/pkg_install/delete/perform.c#8 edit
.. //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/usr.sbin/pkg_install/info/Makefile#5 edit
.. //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/usr.sbin/pkg_install/info/perform.c#8 edit
.. //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/usr.sbin/pkg_install/info/show.c#4 edit
.. //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/usr.sbin/pkg_install/updating/main.c#9 edit
.. //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/usr.sbin/pkg_install/version/Makefile#5 edit
.. //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/usr.sbin/pkg_install/version/perform.c#12 edit

Differences ...

==== //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/usr.sbin/pkg_install/Makefile#3 (text+ko) ====

@@ -2,7 +2,7 @@
 
 .include <bsd.own.mk>
 
-SUBDIR=	add create delete info updating version
+SUBDIR=	lib add create delete info updating version
 
 .include <bsd.subdir.mk>
 

==== //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/usr.sbin/pkg_install/Makefile.inc#4 (text+ko) ====

@@ -2,8 +2,12 @@
 
 .include <bsd.own.mk>
 
+LIBPKG_INSTALL=	${.OBJDIR}/../lib/libpkg_install.a
+
 CFLAGS+=	-DPKG_INSTALL_VERSION=20100423
 CFLAGS+=	-DYES_I_KNOW_THE_API_IS_RUBBISH_AND_IS_DOOMED_TO_CHANGE
+CFLAGS+=	-DI_READ_THE_LIBPKG_INSTALL_MAKEFILE_AND_I_UNDERSTAND_ITS_PURPOSE
+CFLAGS+=	-I${.CURDIR}/../lib
 
 DPADD+=		${LIBPKG} ${LIBARCHIVE}
 LDADD+=		-lpkg -larchive

==== //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/usr.sbin/pkg_install/add/Makefile#5 (text+ko) ====

@@ -3,9 +3,16 @@
 .include <bsd.own.mk>
 
 PROG=	pkg_add
-SRCS=	main.c perform.c futil.c extract.c
+SRCS=				\
+	main.c			\
+	perform.c		\
+	futil.c			\
+	extract.c		\
+
+WARNS?=				3
+WFORMAT?=			1
 
-WARNS?=	3
-WFORMAT?=	1
+DPADD+=	${LIBPKG_INSTALL}
+LPADD+=	${LIBPKG_INSTALL}			
 
 .include <bsd.prog.mk>

==== //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/usr.sbin/pkg_install/add/extract.c#5 (text+ko) ====

@@ -26,8 +26,6 @@
 #include <pkg.h>
 #include "add.h"
 
-extern void	cleanup(int);
-
 #define STARTSTRING "/usr/bin/tar cf -"
 #define TOOBIG(str) \
     (((int)strlen(str) + FILENAME_MAX + where_count > maxargs) ||\
@@ -38,8 +36,7 @@
 	strcat(where_args, "|/usr/bin/tar --unlink -xpPf - -C "); \
 	strcat(where_args, todir); \
 	if (system(where_args)) { \
-	    cleanup(0); \
-	    errx(2, "%s: can not invoke %ld byte tar pipeline: %s", \
+	    errx(EXIT_FAILURE, "%s: can not invoke %ld byte tar pipeline: %s", \
 		 __func__, (long)strlen(where_args), where_args); \
 	} \
 	strcpy(where_args, STARTSTRING); \
@@ -116,15 +113,11 @@
 
     maxargs = sysconf(_SC_ARG_MAX) / 2;	/* Just use half the argument space */
     where_args = alloca(maxargs);
-    if (!where_args) {
-	cleanup(0);
-	errx(2, "%s: can't get argument list space", __func__);
-    }
+    if (where_args == NULL)
+	err(EXIT_FAILURE, "%s: can't get argument list space", __func__);
     perm_args = alloca(maxargs);
-    if (!perm_args) {
-	cleanup(0);
-	errx(2, "%s: can't get argument list space", __func__);
-    }
+    if (perm_args == NULL)
+	err(EXIT_FAILURE, "%s: can't get argument list space", __func__);
 
     strcpy(where_args, STARTSTRING);
     where_count = sizeof(STARTSTRING)-1;
@@ -161,7 +154,8 @@
 		/* first try to rename it into place */
 		snprintf(try, FILENAME_MAX, "%s/%s", Directory, p->name);
 		if (fexists(try)) {
-		    (void)chflags(try, 0);	/* XXX hack - if truly immutable, rename fails */
+		    /* XXX hack - if truly immutable, rename fails */
+		    (void)chflags(try, 0);	
 		    if (preserve && PkgName) {
 			char pf[FILENAME_MAX];
 
@@ -181,11 +175,11 @@
 		    if (p->name[0] == '/' || TOOBIG(p->name)) {
 			PUSHOUT(Directory);
 		    }
-		    add_count = add_arg(&perm_args[perm_count], maxargs - perm_count, p->name);
-		    if (add_count < 0 || add_count >= maxargs - perm_count) {
-			cleanup(0);
-			errx(2, "%s: oops, miscounted strings!", __func__);
-		    }
+		    add_count = add_arg(&perm_args[perm_count],
+			maxargs - perm_count, p->name);
+		    if (add_count < 0 || add_count >= maxargs - perm_count)
+			errx(EXIT_FAILURE, "%s: oops, miscounted strings!",
+			    __func__);
 		    perm_count += add_count;
 		}
 		else {
@@ -202,16 +196,14 @@
 			PUSHOUT(Directory);
 		    }
 		    add_count = add_arg(&where_args[where_count], maxargs - where_count, p->name);
-		    if (add_count < 0 || add_count >= maxargs - where_count) {
-			cleanup(0);
-			errx(2, "%s: oops, miscounted strings!", __func__);
-		    }
+		    if (add_count < 0 || add_count >= maxargs - where_count)
+			errx(EXIT_FAILURE, "%s: oops, miscounted strings!",
+			    __func__);
 		    where_count += add_count;
 		    add_count = add_arg(&perm_args[perm_count], maxargs - perm_count, p->name);
-		    if (add_count < 0 || add_count >= maxargs - perm_count) {
-			cleanup(0);
-			errx(2, "%s: oops, miscounted strings!", __func__);
-		    }
+		    if (add_count < 0 || add_count >= maxargs - perm_count)
+			errx(EXIT_FAILURE, "%s: oops, miscounted strings!",
+			    __func__);
 		    perm_count += add_count;
 		}
 	    }
@@ -226,10 +218,9 @@
 		printf("extract: CWD to %s\n", p->name);
 	    PUSHOUT(Directory);
 	    if (strcmp(p->name, ".")) {
-		if (!Fake && make_hierarchy(p->name) == -1) {
-		    cleanup(0);
-		    errx(2, "%s: unable to cwd to '%s'", __func__, p->name);
-		}
+		if (!Fake && make_hierarchy(p->name) == -1)
+		    errx(EXIT_FAILURE, "%s: unable to cwd to '%s'", __func__,
+			p->name);
 		Directory = p->name;
 	    }
 	    else
@@ -238,16 +229,12 @@
 
 	case PLIST_CMD:
 	    if ((strstr(p->name, "%B") || strstr(p->name, "%F") ||
-		 strstr(p->name, "%f")) && last_file == NULL) {
-		cleanup(0);
-		errx(2, "%s: no last file specified for '%s' command",
-		    __func__, p->name);
-	    }
-	    if (strstr(p->name, "%D") && Directory == NULL) {
-		cleanup(0);
+		 strstr(p->name, "%f")) && last_file == NULL)
+		errx(EXIT_FAILURE, "%s: no last file specified for '%s' "
+		    "command", __func__, p->name);
+	    if (strstr(p->name, "%D") && Directory == NULL)
 		errx(2, "%s: no directory specified for '%s' command",
 		    __func__, p->name);
-	    }
 	    format_cmd(cmd, FILENAME_MAX, p->name, Directory, last_file);
 	    PUSHOUT(Directory);
 	    if (Verbose)

==== //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/usr.sbin/pkg_install/add/perform.c#15 (text+ko) ====

@@ -21,16 +21,16 @@
 #include <sys/cdefs.h>
 __FBSDID("$FreeBSD: src/usr.sbin/pkg_install/add/perform.c,v 1.90 2010/04/23 11:07:43 flz Exp $");
 
+#include <sys/wait.h>
 #include <err.h>
+#include <libgen.h>
 #include <paths.h>
+
 #include <pkg.h>
 #include "add.h"
+#include "cleanup.h"
 
-#include <libgen.h>
-#include <signal.h>
-#include <sys/wait.h>
-
-void		cleanup(int);
+void		cleanup(void);
 static int	pkg_do(char *);
 static int	sanity_check(char *);
 
@@ -40,18 +40,18 @@
 int
 pkg_perform(char **pkgs)
 {
-    int i, err_cnt = 0;
+	int i;
+	int err_cnt = 0;
 
-    signal(SIGINT, cleanup);
-    signal(SIGHUP, cleanup);
+	if (register_cleanup_handler(cleanup, NULL, NULL, 0) == -1)
+		err(EXIT_FAILURE, "failed to initialize exit handler");
 
-    if (AddMode == SLAVE)
-	err_cnt = pkg_do(NULL);
-    else {
-	for (i = 0; pkgs[i]; i++)
-	    err_cnt += pkg_do(pkgs[i]);
-    }
-    return err_cnt;
+	if (AddMode == SLAVE)
+		err_cnt = pkg_do(NULL);
+	else
+		for (i = 0; pkgs[i]; i++)
+			err_cnt += pkg_do(pkgs[i]);
+	return err_cnt;
 }
 
 /*
@@ -107,7 +107,7 @@
 	if (isURL(pkg)) {
 	    if (!(where_to = fileGetURL(NULL, pkg, KeepPackage))) {
 		warnx("unable to fetch '%s' by URL", pkg);
-		cleanup(0);
+		cleanup();
 		return 1;
 	    }
 	    cfile = open(CONTENTS_FNAME, O_RDONLY);
@@ -380,7 +380,7 @@
 		else {
 
 		    if ((cp = fileGetURL(pkg, p->name, KeepPackage)) == NULL) {
-			cleanup(0);
+			cleanup();
 			warnx("Getting pkg '%s' by URL failed", pkg);
 			goto bomb;
 		    } else {
@@ -536,7 +536,6 @@
 	fchmod(fd, sb.st_mode | S_IRALL | S_IXALL);	/* be sure, chmod a+rx */
 	close(fd);
 	if (move_file(".", DESC_FNAME, LogDir) == -1) {
-	    cleanup(0);
 	    errx(EXIT_FAILURE, "failed to move %s to %s", DESC_FNAME, LogDir);
 	}
 	move_file(".", COMMENT_FNAME, LogDir);
@@ -545,7 +544,6 @@
 	do {								\
 		if (fexists(file)) {					\
 			if (move_file(".", file, LogDir) == -1) {	\
-				cleanup(0);				\
 				errx(EXIT_FAILURE,			\
 				    "failed to move '%s' to '%s'",	\
 				    file, LogDir);			\
@@ -715,19 +713,9 @@
 }
 
 void
-cleanup(int sig)
+cleanup(void)
 {
-    static int in_cleanup = 0;
-
-    if (!in_cleanup) {
-	in_cleanup = 1;
-    	if (sig)
-	    printf("Signal %d received, cleaning up..\n", sig);
-    	if (!Fake && zapLogDir && LogDir[0])
-	    vsystem("%s -rf %s", REMOVE_CMD, LogDir);
-    	while (leave_playpen())
-	    ;
-    }
-    if (sig)
-	exit(1);
+	if (!Fake && zapLogDir && LogDir[0])
+		vsystem("%s -rf %s", REMOVE_CMD, LogDir);
+	while (leave_playpen()) ;
 }

==== //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/usr.sbin/pkg_install/create/Makefile#6 (text+ko) ====

@@ -1,11 +1,25 @@
 # $FreeBSD: src/usr.sbin/pkg_install/create/Makefile,v 1.23 2010/04/23 11:07:43 flz Exp $
 
 PROG=	pkg_create
-SRCS=	main.c perform.c pl.c
+SRCS=				\
+	main.c			\
+	perform.c		\
+	pl.c			\
+
+#
+# Bits that belong in libarchive(5), or somewhere in that general area, that
+# supply -X functionality.
+#
+# Shamelessly grabbed from tar(1).
+#
+SRCS+=	tar_line_reader.c	\
+	tar_matching.c		\
+	tar_pathmatch.c		\
 
-SRCS+=	tar_line_reader.c tar_matching.c tar_pathmatch.c 
+WARNS?=				3
+WFORMAT?=			1
 
-WARNS?=	3
-WFORMAT?=	1
+DPADD+=	${LIBPKG_INSTALL}
+LPADD+=	${LIBPKG_INSTALL}
 
 .include <bsd.prog.mk>

==== //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/usr.sbin/pkg_install/create/perform.c#29 (text+ko) ====

@@ -34,7 +34,6 @@
 #include <fcntl.h>
 #include <libgen.h>
 #include <limits.h>
-#include <signal.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
@@ -44,9 +43,10 @@
 #include "tar_matching.h"
 
 #include <pkg.h>
+#include "cleanup.h"
 #include "create.h"
 
-void		cleanup(int);
+void		cleanup(void);
 
 static void	sanity_check(void);
 static const char* add_file(struct archive *, const char *, const char *,
@@ -68,6 +68,9 @@
     int rc;
     const char *suf;
 
+    if (register_cleanup_handler(cleanup, NULL, NULL, 0) == -1)
+	err(EXIT_FAILURE, "failed to initialize exit handler");
+
     /* Preliminary setup */
     if (InstalledPkg == NULL)
 	sanity_check();
@@ -143,11 +146,9 @@
 	pkg_in = fileno(stdin);
     else {
 	pkg_in = open(Contents, O_RDONLY);
-	if (pkg_in == -1) {
-	    cleanup(0);
+	if (pkg_in == -1)
 	    errx(2, "%s: unable to open contents file '%s' for input",
 		__func__, Contents);
-	}
     }
     plist.head = plist.tail = NULL;
 
@@ -260,12 +261,8 @@
     }
 
     /* Make a directory to stomp around in */
-    if ((home = make_playpen(PlayPen, 0)) == NULL) {
-	cleanup(0);
+    if ((home = make_playpen(PlayPen, 0)) == NULL)
 	errx(EXIT_FAILURE, "failed to create a playpen");
-    }
-    signal(SIGINT, cleanup);
-    signal(SIGHUP, cleanup);
 
     /* Make first "real contents" pass over it */
     check_list(home, &plist);
@@ -284,20 +281,14 @@
 	add_plist(&plist, PLIST_IGNORE, NULL);
 	add_plist(&plist, PLIST_FILE, COMMENT_FNAME);
 	add_cksum(&plist, plist.tail, COMMENT_FNAME);
-    }
-    else {
-	cleanup(0);
+    } else
 	err(EXIT_FAILURE, "failed to write comment file");
-    }
     if (write_file(DESC_FNAME, Desc) == 0) {
 	add_plist(&plist, PLIST_IGNORE, NULL);
 	add_plist(&plist, PLIST_FILE, DESC_FNAME);
 	add_cksum(&plist, plist.tail, DESC_FNAME);
-    }
-    else {
-	cleanup(0);
+    } else
 	err(EXIT_FAILURE, "failed to write description file");
-    }
 
     if (Install != NULL) {
 	add_plist(&plist, PLIST_IGNORE, NULL);
@@ -339,18 +330,13 @@
 
     /* Finally, write out the packing list */
     fp = fopen(CONTENTS_FNAME, "w");
-    if (!fp) {
-	cleanup(0);
+    if (!fp)
 	errx(2, "%s: can't open file %s for writing", __func__, CONTENTS_FNAME);
-    }
     rc = write_plist(&plist, fp);
-    if (fclose(fp)) {
-	cleanup(0);
+    if (fclose(fp))
 	errx(2, "%s: error occurred when closing %s", __func__, CONTENTS_FNAME);
-    } else if (rc != 0) {
-	cleanup(0);
+    else if (rc != 0)
 	errx(2, "%s: couldn't write to %s", __func__, CONTENTS_FNAME);
-    }
 
     /* And stick it into a tarball */
     make_dist(home, pkg, suf, &plist);
@@ -758,36 +744,23 @@
 static void
 sanity_check()
 {
-    if (!Comment) {
-	cleanup(0);
+    if (!Comment)
 	errx(2, "%s: required package comment string is missing (-c comment)",
 	    __func__);
-    }
-    if (!Desc) {
-	cleanup(0);
+    if (!Desc)
 	errx(2,	"%s: required package description string is missing (-d desc)",
 	    __func__);
-    }
-    if (!Contents) {
-	cleanup(0);
+    if (!Contents)
 	errx(2,	"%s: required package contents list is missing (-f [-]file)",
 	    __func__);
-    }
 }
 
 
 /* Clean up those things that would otherwise hang around */
 void
-cleanup(int sig)
+cleanup(void)
 {
-    int in_cleanup = 0;
-
-    if (!in_cleanup) {
-	in_cleanup = 1;
-    	leave_playpen();
-    }
-    if (sig)
-	exit(1);
+	leave_playpen();
 }
 
 static int

==== //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/usr.sbin/pkg_install/create/pl.c#4 (text+ko) ====

@@ -29,8 +29,6 @@
 
 #include "create.h"
 
-extern void	cleanup(int);
-
 /* Add an MD5 checksum entry for a file or link */
 void
 add_cksum(Package *pkg, PackingList p, const char *fname)
@@ -123,8 +121,8 @@
 	if (where_count > (int)sizeof(STARTSTRING)-1) { \
 		    strcat(where_args, "|/usr/bin/tar xpf -"); \
 		    if (system(where_args)) { \
-			cleanup(0); \
-			errx(2, "%s: can't invoke tar pipeline", __func__); \
+			errx(EXIT_FAILURE, "%s: can't invoke tar pipeline", \
+			    __func__); \
 		    } \
 		    memset(where_args, 0, maxargs); \
  		    last_chdir = NULL; \
@@ -154,10 +152,8 @@
 					 * and sh -c
 					 */
     where_args = malloc(maxargs);
-    if (!where_args) {
-	cleanup(0);
-	errx(2, "%s: can't get argument list space", __func__);
-    }
+    if (where_args == NULL)
+	err(EXIT_FAILURE, "%s: can't get argument list space", __func__);
 
     memset(where_args, 0, maxargs);
     strcpy(where_args, STARTSTRING);
@@ -227,10 +223,8 @@
 					 p->name);
 		    last_chdir = home;
 		}
-		if (add_count < 0 || add_count >= maxargs - where_count) {
-		    cleanup(0);
+		if (add_count < 0 || add_count >= maxargs - where_count)
 		    errx(2, "%s: oops, miscounted strings!", __func__);
-		}
 		where_count += add_count;
 	    }
 	    /*
@@ -269,10 +263,8 @@
 					 " -C %s %s",
 					 mythere ? mythere : where,
 					 p->name);
-		if (add_count < 0 || add_count >= maxargs - where_count) {
-		    cleanup(0);
+		if (add_count < 0 || add_count >= maxargs - where_count)
 		    errx(2, "%s: oops, miscounted strings!", __func__);
-		}
 		where_count += add_count;
 		last_chdir = (mythere ? mythere : where);
 	    }

==== //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/usr.sbin/pkg_install/delete/Makefile#5 (text+ko) ====

@@ -1,8 +1,13 @@
 # $FreeBSD: src/usr.sbin/pkg_install/delete/Makefile,v 1.24 2010/04/23 11:07:43 flz Exp $
 
 PROG=	pkg_delete
-SRCS=	main.c perform.c
+SRCS=				\
+	main.c			\
+	perform.c		\
+
+WFORMAT?=			1
 
-WFORMAT?=	1
+DPADD+=	${LIBPKG_INSTALL}
+LPADD+=	${LIBPKG_INSTALL}
 
 .include <bsd.prog.mk>

==== //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/usr.sbin/pkg_install/delete/perform.c#8 (text+ko) ====

@@ -25,9 +25,10 @@
 #include <errno.h>
 
 #include <pkg.h>
+#include "cleanup.h"
 #include "delete.h"
 
-void		cleanup(int);
+void		cleanup(void);
 static int	pkg_do(char *);
 static void	sanity_check(char *);
 static void	undepend(char *, char *);
@@ -43,6 +44,9 @@
     struct reqr_by_entry *rb_entry;
     struct reqr_by_head *rb_list;
 
+    if (register_cleanup_handler(cleanup, NULL, NULL, 0) == -1)
+	err(EXIT_FAILURE, "failed to initialize exit handler");
+
     if (MatchType != MATCH_EXACT) {
 	matched = matchinstalled(MatchType, pkgs, &errcode);
 	if (errcode != 0)
@@ -172,10 +176,8 @@
 	return 0;
     }
 
-    if (!getcwd(home, FILENAME_MAX)) {
-	cleanup(0);
-	errx(2, "%s: unable to get current working directory!", __func__);
-    }
+    if (getcwd(home, FILENAME_MAX) == NULL)
+	errx(EXIT_FAILURE, "%s: unable to get current working directory!", __func__);
 
     if (chdir(LogDir) == -1) {
 	warnx("unable to change directory to %s! deinstall failed", LogDir);
@@ -323,11 +325,9 @@
 	}
     }
 
-    if (chdir(home) == -1) {
-	cleanup(0);
-	errx(2, "%s: unable to return to working directory %s!", __func__,
-	    home);
-    }
+    if (chdir(home) == -1)
+	errx(EXIT_FAILURE, "%s: unable to return to working directory %s!",
+	    __func__, home);
 
     /*
      * Some packages aren't packed right, so we need to just ignore
@@ -358,11 +358,9 @@
  	}
     }
 
-    if (chdir(home) == -1) {
- 	cleanup(0);
-	errx(2, "%s: unable to return to working directory %s!", __func__,
-	    home);
-    }
+    if (chdir(home) == -1)
+	errx(EXIT_FAILURE, "%s: unable to return to working directory %s!",
+	    __func__, home);
 
     if (!Fake) {
 	if (vsystem("%s -r%c %s", REMOVE_CMD, Force ? 'f' : ' ', LogDir)) {
@@ -377,18 +375,14 @@
 static void
 sanity_check(char *pkg)
 {
-    if (!fexists(CONTENTS_FNAME)) {
-	cleanup(0);
-	errx(2, "%s: installed package %s has no %s file!", __func__,
-	    pkg, CONTENTS_FNAME);
-    }
+    if (!fexists(CONTENTS_FNAME))
+	errx(EXIT_FAILURE, "%s: installed package %s has no %s file!",
+	    __func__, pkg, CONTENTS_FNAME);
 }
 
 void
-cleanup(int sig)
+cleanup(void)
 {
-    if (sig)
-	exit(1);
 }
 
 static void

==== //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/usr.sbin/pkg_install/info/Makefile#5 (text+ko) ====

@@ -1,8 +1,14 @@
 # $FreeBSD: src/usr.sbin/pkg_install/info/Makefile,v 1.22 2010/04/23 11:07:43 flz Exp $
 
 PROG=	pkg_info
-SRCS=	main.c perform.c show.c
+SRCS=				\
+	main.c			\
+	perform.c		\
+	show.c			\
+
+WFORMAT?=			1
 
-WFORMAT?=	1
+DPADD+=	${LIBPKG_INSTALL}
+LPADD+=	${LIBPKG_INSTALL}
 
 .include <bsd.prog.mk>

==== //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/usr.sbin/pkg_install/info/perform.c#8 (text+ko) ====

@@ -23,13 +23,12 @@
 
 #include <err.h>
 #include <fcntl.h>
-#include <signal.h>
 
 #include <pkg.h>
-
+#include "cleanup.h"
 #include "info.h"
 
-void		cleanup(int);
+void		cleanup(void);
 static int	pkg_do(char *);
 static int	find_pkg(struct which_head *);
 static int	cmp_path(const char *, const char *, const char *);
@@ -44,19 +43,19 @@
     int err_cnt = 0;
     int i, errcode;
 
-    signal(SIGINT, cleanup);
+    if (register_cleanup_handler(cleanup, NULL, NULL, 0) == -1)
+	err(EXIT_FAILURE, "failed to initialize exit handler");
 
     /* Overriding action? */
-    if (Flags & SHOW_PKGNAME) {
+    if (Flags & SHOW_PKGNAME)
 	return matched_packages(pkgs);
-    } else if (CheckPkg) {
+    else if (CheckPkg) {
 	return isinstalledpkg(CheckPkg) > 0 ? 0 : 1;
 	/* Not reached */
-    } else if (!TAILQ_EMPTY(whead)) {
+    } else if (!TAILQ_EMPTY(whead))
 	return find_pkg(whead);
-    } else if (LookUpOrigin != NULL) {
+    else if (LookUpOrigin != NULL)
 	return find_pkgs_by_origin(LookUpOrigin);
-    }
 
     if (MatchType != MATCH_EXACT) {
 	matched = matchinstalled(MatchType, pkgs, &errcode);
@@ -107,7 +106,7 @@
 		err(EXIT_FAILURE, "getcwd()");
 	    isTMP = TRUE;
 	} else {
-	    cleanup(0);
+	    cleanup();
 	    goto bail;
 	}
     }
@@ -143,7 +142,7 @@
 	    }
 	    else if (make_playpen(PlayPen, sb.st_size / 2) == NULL) {
 		warn("failed to create a playpen");
-		cleanup(0);
+		cleanup();
 		code = 1;
 		goto bail;
 	    }
@@ -249,16 +248,9 @@
 }
 
 void
-cleanup(int sig)
+cleanup(void)
 {
-    static int in_cleanup = 0;
-
-    if (!in_cleanup) {
-	in_cleanup = 1;
 	leave_playpen();
-    }
-    if (sig)
-	exit(1);
 }
 
 /*

==== //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/usr.sbin/pkg_install/info/show.c#4 (text+ko) ====

@@ -30,8 +30,6 @@
 #include <pkg.h>
 #include "info.h"
 
-extern void	cleanup(int);
-
 void
 show_file(const char *title, const char *fname)
 {
@@ -201,8 +199,7 @@
 	    break;
 
 	default:
-	    cleanup(0);
-	    errx(2, "%s: unknown command type %d (%s)",
+	    errx(EXIT_FAILURE, "%s: unknown command type %d (%s)",
 		__func__, p->type, p->name);
 	    break;
 	}

==== //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/usr.sbin/pkg_install/updating/main.c#9 (text+ko) ====

@@ -27,7 +27,6 @@
 	char name[LINE_MAX];					/* Name of the installed port. */
 } INSTALLEDPORT;
 
-void		cleanup(int);
 int		usage(void);
 
 static char opts[] = "d:f:h";
@@ -289,10 +288,3 @@
 		"usage: pkg_updating [-h] [-d YYYYMMDD] [-f file] [portname ...]\n");
 	exit(1);
 }
-
-void
-cleanup(int sig)
-{
-	if (sig)
-		exit(1);
-}

==== //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/usr.sbin/pkg_install/version/Makefile#5 (text+ko) ====

@@ -1,10 +1,15 @@
 # $FreeBSD: src/usr.sbin/pkg_install/version/Makefile,v 1.18 2010/04/23 11:07:43 flz Exp $
 
 PROG=	pkg_version
-SRCS=	main.c perform.c
+SRCS=				\
+	main.c 			\
+	perform.c		\
 
 WFORMAT?=	1
 
+DPADD+=	${LIBPKG_INSTALL}
+LPADD+=	${LIBPKG_INSTALL}
+
 test:
 	sh ${.CURDIR}/test-pkg_version.sh
 

==== //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/usr.sbin/pkg_install/version/perform.c#12 (text+ko) ====

@@ -25,16 +25,15 @@
 #include <stdio.h>
 #include <err.h>
 #include <fetch.h>
-#include <signal.h>
 
 #include <pkg.h>
+#include "cleanup.h"
 #include "version.h"
 
 FILE *IndexFile;
 char IndexPath[PATH_MAX] = "";
 struct index_head Index = SLIST_HEAD_INITIALIZER(Index);
 
-void		cleanup(int);
 static int	pkg_do(char *);
 static void	show_version(Package, const char *, const char *);
 
@@ -161,8 +160,11 @@
 	warnx("the package info for package '%s' is corrupt", pkg);
 	return 1;
     }
-    read_plist(&plist, fd);
-    close(fd);
+    if (read_plist(&plist, fd) == -1) {
+	warn("plist read failed");
+	return 1;
+    }
+    (void) close(fd);
     if (plist.name == NULL) {
     	warnx("%s does not appear to be a valid package!", pkg);
     	return 1;
@@ -417,10 +419,3 @@
 
     return ret;
 }
-
-void
-cleanup(int sig)
-{
-    if (sig)
-	exit(1);
-}



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