ports/171155: PKGNG fails to deinstall large ports

Stefan Esser se at freebsd.org
Wed Aug 29 09:30:07 UTC 2012


The following reply was made to PR ports/171155; it has been noted by GNATS.

From: Stefan Esser <se at freebsd.org>
To: bug-followup at FreeBSD.org
Cc: se at FreeBSD.org, bapt at FreeBSD.org
Subject: Re: ports/171155: PKGNG fails to deinstall large ports
Date: Wed, 29 Aug 2012 11:22:50 +0200

 This is a multi-part message in MIME format.
 --------------050402090505090709060608
 Content-Type: text/plain; charset=ISO-8859-15
 Content-Transfer-Encoding: 7bit
 
 The attached patch seems to fix the problem reported in the PR.
 It allows the math/lapack port to be deinstalled.
 The error checking may need review since my intent was to show that the
 popen() approach suggested in the PR is viable.
 
 Regards, STefan
 
 --------------050402090505090709060608
 Content-Type: text/plain; charset=windows-1252;
  name="patch-libpkg_scripts.c"
 Content-Transfer-Encoding: 7bit
 Content-Disposition: attachment;
  filename="patch-libpkg_scripts.c"
 
 --- libpkg/scripts.c~	2012-08-16 10:24:31.000000000 +0200
 +++ libpkg/scripts.c	2012-08-29 10:37:08.300667589 +0200
 @@ -45,10 +45,9 @@
  {
  	struct sbuf * const script_cmd = sbuf_new_auto();
  	size_t i, j;
 -	int error, pstat;
 -	pid_t pid;
 +	int error;
  	const char *name, *prefix, *version;
 -	const char *argv[4];
 +	FILE *shell;
  
  	struct {
  		const char * const arg;
 @@ -66,10 +65,6 @@
  
  	pkg_get(pkg, PKG_PREFIX, &prefix, PKG_NAME, &name, PKG_VERSION, &version);
  
 -	argv[0] = "sh";
 -	argv[1] = "-c";
 -	argv[3] = NULL;
 -
  	for (i = 0; i < sizeof(map) / sizeof(map[0]); i++) {
  		if (map[i].a == type)
  			break;
 @@ -96,11 +91,14 @@
  			sbuf_cat(script_cmd, "\n");
  			sbuf_cat(script_cmd, pkg_script_get(pkg, j));
  			sbuf_finish(script_cmd);
 -			argv[2] = sbuf_get(script_cmd);
 -
 -			if ((error = posix_spawn(&pid, _PATH_BSHELL, NULL,
 -			    NULL, __DECONST(char **, argv),
 -			    environ)) != 0) {
 +			shell = popen(_PATH_BSHELL, "w");
 +			if (shell == NULL) {
 +				error = EPIPE;
 +			} else {
 +				if (fputs(sbuf_get(script_cmd), shell) == EOF)
 +					error = EPIPE;
 +			}
 +			if (error) {
  				errno = error;
  				pkg_emit_errno("Cannot run script",
  				    map[i].arg);
 @@ -109,13 +107,7 @@
  			}
  
  			unsetenv("PKG_PREFIX");
 -
 -			while (waitpid(pid, &pstat, 0) == -1) {
 -				if (errno != EINTR)
 -					return (EPKG_FATAL);
 -			}
 -
 -			if (WEXITSTATUS(pstat) != 0) {
 +			if (pclose(shell) != 0) {
  				pkg_emit_error("%s script failed", map[i].arg);
  				return (EPKG_FATAL);
  			}
 
 --------------050402090505090709060608--



More information about the freebsd-ports-bugs mailing list