NetBSD Problem Report #33884

From yamt@mwd.biglobe.ne.jp  Sat Jul  1 13:03:01 2006
Return-Path: <yamt@mwd.biglobe.ne.jp>
Received: from mail.netbsd.org (mail.netbsd.org [204.152.190.11])
	by narn.NetBSD.org (Postfix) with ESMTP id 22FF363B8ED
	for <gnats-bugs@gnats.NetBSD.org>; Sat,  1 Jul 2006 13:03:01 +0000 (UTC)
Message-Id: <1151758944.951860.3402.nullmailer@yamt.dyndns.org>
Date: Sat, 01 Jul 2006 22:02:24 +0900
From: yamt@mwd.biglobe.ne.jp
Reply-To: yamt@mwd.biglobe.ne.jp
To: gnats-bugs@NetBSD.org
Subject: PKG_PATH handling is weird
X-Send-Pr-Version: 3.95

>Number:         33884
>Category:       pkg
>Synopsis:       PKG_PATH handling is weird
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    joerg
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Jul 01 13:05:00 +0000 2006
>Closed-Date:    Thu Nov 05 16:33:34 +0000 2009
>Last-Modified:  Thu Nov 05 16:33:34 +0000 2009
>Originator:     YAMAMOTO Takashi <yamt@mwd.biglobe.ne.jp>
>Release:        NetBSD 3.99.21
>Organization:

>Environment:


System: NetBSD kaeru 3.99.21 NetBSD 3.99.21 (build.kaeru.xen.nodebug) #: Fri Jun 30 09:45:59 JST 2006 takashi@kaeru:/home/takashi/work/kernel/build.kaeru.xen.nodebug i386
Architecture: i386
Machine: i386
>Description:
	the behaviour of PKG_PATH is not straightforward, at best.

	if you do:
		PKG_PATH=/aa;/bb pkg_add cc/dd.tgz

	a package "dd.tgz" will be searched in the following order:
		1. ./cc/cc/dd.tgz  <= weird
		2. /aa/cc/dd.tgz
		3. /bb/cc/dd.tgz

	see this thread:
		http://mail-index.NetBSD.org/tech-pkg/2002/10/29/0002.html
>How-To-Repeat:

>Fix:
	i'm using the following patch. (revert path_prepend hack)
	i think it can make some people unhappy, tho.

Index: add/perform.c
===================================================================
RCS file: /cvsroot/src/usr.sbin/pkg_install/add/perform.c,v
retrieving revision 1.120
diff -u -p -r1.120 perform.c
--- add/perform.c	24 Apr 2006 13:36:22 -0000	1.120
+++ add/perform.c	1 Jul 2006 12:54:10 -0000
@@ -1079,9 +1079,7 @@ pkg_perform(lpkg_head_t *pkgs)
 		err_cnt = pkg_do(NULL, NULL);
 	else {
 		while ((lpp = TAILQ_FIRST(pkgs)) != NULL) {
-			path_prepend_from_pkgname(lpp->lp_name);
 			err_cnt += pkg_do(lpp->lp_name, pkgs);
-			path_prepend_clear();
 			TAILQ_REMOVE(pkgs, lpp, lp_link);
 			free_lpkg(lpp);
 		}
Index: lib/path.c
===================================================================
RCS file: /cvsroot/src/usr.sbin/pkg_install/lib/path.c,v
retrieving revision 1.8
diff -u -p -r1.8 path.c
--- lib/path.c	5 Nov 2005 13:11:02 -0000	1.8
+++ lib/path.c	1 Jul 2006 12:54:10 -0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: path.c,v 1.8 2005/11/05 13:11:02 wiz Exp $	*/
+/*	$NetBSD: path.c,v 1.2 2002/08/08 00:17:39 yamt Exp $	*/

 /*-
  * Copyright (c)2002 YAMAMOTO Takashi,
@@ -44,9 +44,6 @@ __RCSID("$NetBSD: path.c,v 1.8 2005/11/0
 #include "lib.h"

 struct pathhead PkgPath = TAILQ_HEAD_INITIALIZER(PkgPath);
-static struct path *prepend = 0;
-
-static struct path *path_new_entry(const char *cp, size_t len);

 /*
  * path_create: make PkgPath from a given string.
@@ -59,6 +56,8 @@ path_create(const char *path)
 {
 	const char *cp;
 	size_t len;
+	char cwd[MAXPATHLEN];
+	size_t cwdlen;

 	path_free();

@@ -69,6 +68,10 @@ path_create(const char *path)
 	if (Verbose)
 		printf("parsing: %s\n", path);

+	if (getcwd(cwd, sizeof(cwd)) == NULL)
+		err(1, "getcwd");
+	cwdlen = strlen(cwd);
+
 	cp = path;
 	while (*cp) {
 		len = strcspn(cp, ";");
@@ -76,7 +79,28 @@ path_create(const char *path)
 			/* add a new path */
 			struct path *new;

-			new = path_new_entry(cp, len);
+			new = malloc(sizeof(*new));
+			if (new == NULL)
+				err(1, "path_create");
+
+			if (!IS_FULLPATH(cp) && !IS_URL(cp)) {
+				/* this is a relative path */
+				size_t total;
+
+				total = cwdlen + 1 + len + 1;
+				new->pl_path = malloc(total);
+				if (new->pl_path == NULL)
+					err(1, "path_create");
+				snprintf(new->pl_path, total, "%s/%*.*s", cwd, (int)len, (int)len, cp);
+			}
+			else {
+				new->pl_path = malloc(len + 1);
+				if (new->pl_path == NULL)
+					err(1, "path_create");
+				memcpy(new->pl_path, cp, len);
+				new->pl_path[len] = '\0';
+			}
+
 			if (Verbose)
 				printf("path: %s\n", new->pl_path);
 			TAILQ_INSERT_TAIL(&PkgPath, new, pl_entry);
@@ -105,69 +129,6 @@ path_free()
 }

 /*
- * path_new_entry: Generate a new 'struct path' entry to be included in
- * 'PkgPath' using the first 'len' characters of 'cp'.
- */
-static struct path *
-path_new_entry(const char *cp, size_t len)
-{
-	struct path *new;
-
-	new = malloc(sizeof(*new));
-	if (new == NULL)
-		err(EXIT_FAILURE, "path_create");
-
-	if (!IS_FULLPATH(cp) && !IS_URL(cp)) {
-		/* this is a relative path */
-		size_t total;
-		char cwd[MaxPathSize];
-		size_t cwdlen;
-
-		if (getcwd(cwd, sizeof(cwd)) == NULL)
-			err(EXIT_FAILURE, "getcwd");
-		cwdlen = strlen(cwd);
-		total = cwdlen + 1 + len + 1;
-		new->pl_path = malloc(total);
-		if (new->pl_path == NULL)
-			err(EXIT_FAILURE, "path_create");
-		snprintf(new->pl_path, total, "%s/%*.*s", cwd, (int)len, (int)len, cp);
-	}
-	else {
-		new->pl_path = malloc(len + 1);
-		if (new->pl_path == NULL)
-			err(EXIT_FAILURE, "path_create");
-		memcpy(new->pl_path, cp, len);
-		new->pl_path[len] = '\0';
-	}
-	return new;
-}
-
-/*
- * path_prepend_from_pkgname: prepend the path for a package onto 'PkgPath'
- */
-void
-path_prepend_from_pkgname(const char *pkgname)
-{
-	char *ptr;
-	if ((ptr = strrchr(pkgname , '/'))) {
-		prepend = path_new_entry(pkgname, ptr - pkgname);
-		TAILQ_INSERT_HEAD(&PkgPath, prepend, pl_entry);
-	}
-}
-
-/*
- * path_prepend_clear: Remove any prepended entry from 'PkgPath'
- */
-void
-path_prepend_clear()
-{
-	if (prepend) {
-		TAILQ_REMOVE(&PkgPath, prepend, pl_entry);
-		prepend = 0;
-	}
-}
-
-/*
  * path_setenv: construct string from PkgPath and set it to a environment.
  *
  * => the environment name is given by envname.
Index: lib/path.h
===================================================================
RCS file: /cvsroot/src/usr.sbin/pkg_install/lib/path.h,v
retrieving revision 1.4
diff -u -p -r1.4 path.h
--- lib/path.h	2 Sep 2003 07:35:03 -0000	1.4
+++ lib/path.h	1 Jul 2006 12:54:10 -0000
@@ -35,6 +35,4 @@ TAILQ_HEAD(pathhead, path);
 extern struct pathhead PkgPath;
 void path_create(const char *);
 void path_free(void);
-void path_prepend_from_pkgname(const char *);
-void path_prepend_clear(void);
 void path_setenv(const char *);

>Release-Note:

>Audit-Trail:

Responsible-Changed-From-To: pkg-manager->joerg
Responsible-Changed-By: joerg@NetBSD.org
Responsible-Changed-When: Thu, 12 Feb 2009 00:27:29 +0000
Responsible-Changed-Why:
pkg_install maintainer


From: Joerg Sonnenberger <joerg@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/33884 CVS commit: pkgsrc/pkgtools/pkg_install/files
Date: Sat, 28 Feb 2009 16:03:56 +0000 (UTC)

 Module Name:	pkgsrc
 Committed By:	joerg
 Date:		Sat Feb 28 16:03:56 UTC 2009

 Modified Files:
 	pkgsrc/pkgtools/pkg_install/files/add: main.c perform.c pkg_add.1
 	    pkg_add.cat1
 	pkgsrc/pkgtools/pkg_install/files/info: main.c pkg_info.1 pkg_info.cat1
 	pkgsrc/pkgtools/pkg_install/files/lib: Makefile.in lib.h parse-config.c
 	    pkg_install.conf.5.in pkg_install.conf.cat5.in pkg_io.c version.h
 Removed Files:
 	pkgsrc/pkgtools/pkg_install/files/lib: path.c path.h

 Log Message:
 pkg_install-20090228:
 Integrate the PKG_PATH logic for tightly with the find_archive logic:
 - remember initial current working directory from the time PKG_PATH is
   processed, it will be used as reference for all relative entries
 - remove now redundant fchdir dance in pkg_add
 - pass down to find_archive if this is a top-level package (e.g.
   requested on the command line) or not; the location of top-level
   packages is searched for packages first and for URLs or path names the
   PKG_PATH itself is not processed (e.g. pkg_add foo/bar not look into
   PKG_PATH for bar). This addresses PR 33884 in a different way.
 - document the rules for finding packages more explicitly
 - allow specifying PKG_PATH in pkg_install.conf as well; environment
   takes precendence.
 - remove PKG_PATH related logic in pkg_info(1), it doesn't deal with
   PKG_PATH anyway
 - remove PKG_PATH, PKG_TMPDIR and TMPDIR description in pkg_info(1),
   they are no longer used


 To generate a diff of this commit:
 cvs rdiff -r1.17 -r1.18 pkgsrc/pkgtools/pkg_install/files/add/main.c
 cvs rdiff -r1.80 -r1.81 pkgsrc/pkgtools/pkg_install/files/add/perform.c
 cvs rdiff -r1.32 -r1.33 pkgsrc/pkgtools/pkg_install/files/add/pkg_add.1
 cvs rdiff -r1.27 -r1.28 pkgsrc/pkgtools/pkg_install/files/add/pkg_add.cat1
 cvs rdiff -r1.23 -r1.24 pkgsrc/pkgtools/pkg_install/files/info/main.c
 cvs rdiff -r1.22 -r1.23 pkgsrc/pkgtools/pkg_install/files/info/pkg_info.1
 cvs rdiff -r1.19 -r1.20 pkgsrc/pkgtools/pkg_install/files/info/pkg_info.cat1
 cvs rdiff -r1.25 -r1.26 pkgsrc/pkgtools/pkg_install/files/lib/Makefile.in
 cvs rdiff -r1.48 -r1.49 pkgsrc/pkgtools/pkg_install/files/lib/lib.h
 cvs rdiff -r1.3 -r1.4 pkgsrc/pkgtools/pkg_install/files/lib/parse-config.c
 cvs rdiff -r1.7 -r0 pkgsrc/pkgtools/pkg_install/files/lib/path.c
 cvs rdiff -r1.3 -r0 pkgsrc/pkgtools/pkg_install/files/lib/path.h
 cvs rdiff -r1.2 -r1.3 \
     pkgsrc/pkgtools/pkg_install/files/lib/pkg_install.conf.5.in \
     pkgsrc/pkgtools/pkg_install/files/lib/pkg_install.conf.cat5.in
 cvs rdiff -r1.4 -r1.5 pkgsrc/pkgtools/pkg_install/files/lib/pkg_io.c
 cvs rdiff -r1.114 -r1.115 pkgsrc/pkgtools/pkg_install/files/lib/version.h

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: open->feedback
State-Changed-By: joerg@NetBSD.org
State-Changed-When: Sat, 28 Feb 2009 16:10:42 +0000
State-Changed-Why:
pkg_install has been changed to only search PKG_PATH for
package names without /, e.g. pkg_add cc/dd.tgz will not look
into the PKG_PATH at all. From the different ways to behave,
this seems to me to be the most consistent and least surprising.
Does this address your concerns?


State-Changed-From-To: feedback->closed
State-Changed-By: joerg@NetBSD.org
State-Changed-When: Thu, 05 Nov 2009 16:33:34 +0000
State-Changed-Why:
Consider concerns addressed after 8 month of silence.


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.