NetBSD Problem Report #32228

From peter@jupiter.pointless.nl  Sat Dec  3 17:11:18 2005
Return-Path: <peter@jupiter.pointless.nl>
Received: from jupiter.pointless.nl (d128238.upc-d.chello.nl [213.46.128.238])
	by narn.netbsd.org (Postfix) with ESMTP id F110D63B883
	for <gnats-bugs@gnats.NetBSD.org>; Sat,  3 Dec 2005 17:11:13 +0000 (UTC)
Message-Id: <200512031452.jB3EqVN4015219@jupiter.pointless.nl>
Date: Sat, 3 Dec 2005 15:52:31 +0100 (CET)
From: Peter Postma <peter@pointless.nl>
Reply-To: peter@pointless.nl
To: gnats-bugs@netbsd.org
Subject: pkg_add does not execute /usr/pkg/bin/tar even when it says so
X-Send-Pr-Version: 3.95

>Number:         32228
>Category:       pkg
>Synopsis:       pkg_add does not execute /usr/pkg/bin/tar even when it says so
>Confidential:   no
>Severity:       critical
>Priority:       high
>Responsible:    pkg-manager
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Dec 03 18:48:10 +0000 2005
>Closed-Date:    Tue Dec 06 01:10:21 +0000 2005
>Last-Modified:  Tue Dec 06 01:20:04 +0000 2005
>Originator:     Peter Postma
>Release:        OpenBSD 3.8 + pkgsrc -current
>Organization:
>Environment:
>Description:
I just installed pkgsrc current on OpenBSD 3.8 and I noticed problems with
pkg_add using tar. It looks likes pkg_add is executing /bin/tar even when
the verbose output says that it is executing /usr/pkg/bin/tar.

Here's the pkg_add verbose output:

# /usr/pkg/sbin/pkg_add -v -K /var/db/pkgdb /usr/pkgsrc/packages/All/audit-packages-1.41.tgz
parsing: .
path: /usr/pkgsrc/.
increasing RLIMIT_NOFILE to max. 1024 open files
Requested space: 35412 bytes, free space: 8587143168 bytes in /var/tmp/instmp.b26295
running: /usr/pkg/bin/tar --fast-read --use-compress-program gzip -xpf /usr/pkgsrc/packages/All/audit-packages-1.41.tgz +CONTENTS
tar: unknown option -- -
usage: tar {crtux}[014578befHhLmOoPpqsvwXZz]
          [blocking-factor | archive | replstr] [-C directory] [-I file]
          [file ...]
       tar {-crtux} [-014578eHhLmOoPpqvwXZz] [-b blocking-factor]
          [-C directory] [-f archive] [-I file] [-s replstr] [file ...]
pkg_add: extract of /usr/pkgsrc/packages/All/audit-packages-1.41.tgz failed
pkg_add: unable to extract table of contents file from `/usr/pkgsrc/packages/All/audit-packages-1.41.tgz' - not a package?
pkg_add: 1 package addition failed


Renaming /bin/tar seems to help, pkg_add now picks up the tar in
/usr/pkg/bin:

# mv /bin/tar /bin/tar.orig

# /usr/pkg/sbin/pkg_add -v -K /var/db/pkgdb /usr/pkgsrc/packages/All/audit-packages-1.41.tgz
parsing: .
path: /usr/pkgsrc/.
increasing RLIMIT_NOFILE to max. 1024 open files
Requested space: 35412 bytes, free space: 8587143168 bytes in /var/tmp/instmp.qg8160
running: /usr/pkg/bin/tar --fast-read --use-compress-program gzip -xpf /usr/pkgsrc/packages/All/audit-packages-1.41.tgz +CONTENTS
running: /usr/pkg/bin/tar --use-compress-program gzip -xpf /usr/pkgsrc/packages/All/audit-packages-1.41.tgz
Depends pre-scan: `digest-[0-9]*' required.
Package `audit-packages-1.41' depends on `digest-[0-9]*'.
 - digest-20050731 already installed.
extract: Package name is audit-packages-1.41
[....]

>How-To-Repeat:
Install current pkgsrc on OpenBSD. Create a package and pkg_add it.

>Fix:
It seems that in lib/file.c, the path is stripped off:

	up_argv[i] = strrchr(TAR_CMD, '/');
	if (up_argv[i] == NULL)
		up_argv[i] = TAR_CMD;
	else
		up_argv[i]++;  /* skip / character */

Then pfcexec() is called with up_argv not having the full path for tar.
execvp() finds /bin/tar first in the path and executes that instead of
/usr/pkg/bin/tar.

A quick fix is below, add an extra argument to pfcexec() for the full 
name of the file to execute. There might be a better fix, but this works
for me.


Index: files/add/futil.c
===================================================================
RCS file: /cvsroot/pkgsrc/pkgtools/pkg_install/files/add/futil.c,v
retrieving revision 1.8
diff -u -u -r1.8 futil.c
--- files/add/futil.c	23 Nov 2005 14:33:50 -0000	1.8
+++ files/add/futil.c	3 Dec 2005 16:17:26 -0000
@@ -107,7 +107,7 @@
 		argv[0] = CHMOD_CMD;
 		argv[1] = "-R";
 		argv[2] = Mode;
-		if (pfcexec(cd_to, argv))
+		if (pfcexec(cd_to, argv[0], argv))
 			warnx("couldn't change modes of '%s' ... to '%s'",
 			    args[0], Mode);
 	}
@@ -122,7 +122,7 @@
 		argv[0] = CHOWN_CMD;
 		argv[1] = "-R";
 		argv[2] = owner_group;
-		if (pfcexec(cd_to, argv))
+		if (pfcexec(cd_to, argv[0], argv))
 			warnx("couldn't change owner/group of '%s' ... to '%s:%s'",
 				args[0], Owner, Group);
 		free(argv);
@@ -132,7 +132,7 @@
 		argv[0] = CHOWN_CMD;
 		argv[1] = "-R";
 		argv[2] = Owner;
-		if (pfcexec(cd_to, argv))
+		if (pfcexec(cd_to, argv[0], argv))
 			warnx("couldn't change owner of '%s' ... to '%s'",
 				args[0], Owner);
 		free(argv);
@@ -143,7 +143,7 @@
 		argv[0] = CHGRP_CMD;
 		argv[1] = "-R";
 		argv[2] = Group;
-		if (pfcexec(cd_to, argv))
+		if (pfcexec(cd_to, argv[0], argv))
 			warnx("couldn't change group of '%s' ... to '%s'",
 				args[0], Group);
 	}
Index: files/lib/fexec.c
===================================================================
RCS file: /cvsroot/pkgsrc/pkgtools/pkg_install/files/lib/fexec.c,v
retrieving revision 1.7
diff -u -u -r1.7 fexec.c
--- files/lib/fexec.c	23 Nov 2005 04:49:51 -0000	1.7
+++ files/lib/fexec.c	3 Dec 2005 16:17:26 -0000
@@ -76,7 +76,7 @@
  * wait for the command to finish, then return the exit status.
  */
 int
-pfcexec(const char *path, const char **argv)
+pfcexec(const char *path, const char *file, const char **argv)
 {
 	pid_t			child;
 	int			status;
@@ -87,7 +87,7 @@
 		if ((path != NULL) && (chdir(path) < 0))
 			_exit(127);

-		(void) execvp(argv[0], (char ** const)argv);
+		(void)execvp(file, (char ** const)argv);
 		_exit(127);
 		/* NOTREACHED */
 	case -1:
@@ -146,7 +146,7 @@
 		argv[argc++] = arg;
 	} while (arg != NULL);

-	return pfcexec(path, argv);
+	return pfcexec(path, argv[0], argv);
 }

 int
Index: files/lib/file.c
===================================================================
RCS file: /cvsroot/pkgsrc/pkgtools/pkg_install/files/lib/file.c,v
retrieving revision 1.16
diff -u -u -r1.16 file.c
--- files/lib/file.c	23 Nov 2005 04:49:51 -0000	1.16
+++ files/lib/file.c	3 Dec 2005 16:17:26 -0000
@@ -676,7 +676,7 @@
 		printf("\n");
 	}

-	result = pfcexec(NULL, (const char **)up_argv);
+	result = pfcexec(NULL, TAR_CMD, (const char **)up_argv);
 	free(up_argv);
 	if (result != 0) {
 		warnx("extract of %s failed", pkg);
Index: files/lib/lib.h
===================================================================
RCS file: /cvsroot/pkgsrc/pkgtools/pkg_install/files/lib/lib.h,v
retrieving revision 1.20
diff -u -u -r1.20 lib.h
--- files/lib/lib.h	28 Nov 2005 01:50:21 -0000	1.20
+++ files/lib/lib.h	3 Dec 2005 16:17:26 -0000
@@ -313,7 +313,7 @@
 int	fexec(const char *, ...);
 int	fexec_skipempty(const char *, ...);
 int	fcexec(const char *, const char *, ...);
-int	pfcexec(const char *path, const char **argv);
+int	pfcexec(const char *, const char *, const char **);
 pipe_to_system_t	*pipe_to_system_begin(const char *, char *const *, void (*)(void));
 int	pipe_to_system_end(pipe_to_system_t *);


>Release-Note:

>Audit-Trail:

State-Changed-From-To: open->closed
State-Changed-By: ben@netbsd.org
State-Changed-When: Tue, 06 Dec 2005 01:10:21 +0000
State-Changed-Why:
Thank you for this bug report!  It was indeed broken by me.
I committed your fix.  -Ben


From: Ben Collver <ben@netbsd.org>
To: gnats-bugs@netbsd.org
Cc: 
Subject: PR/32228 CVS commit: pkgsrc/pkgtools/pkg_install/files
Date: Tue,  6 Dec 2005 01:08:09 +0000 (UTC)

 Module Name:	pkgsrc
 Committed By:	ben
 Date:		Tue Dec  6 01:08:09 UTC 2005

 Modified Files:
 	pkgsrc/pkgtools/pkg_install/files/add: futil.c
 	pkgsrc/pkgtools/pkg_install/files/lib: fexec.c file.c lib.h

 Log Message:
 Specify the full path to tar when unpacking a package.
 Modify pfcexec so the new process file name can be different from argv[0].
 This fix is from Peter Postma, and it addresses PR#32228


 To generate a diff of this commit:
 cvs rdiff -r1.8 -r1.9 pkgsrc/pkgtools/pkg_install/files/add/futil.c
 cvs rdiff -r1.7 -r1.8 pkgsrc/pkgtools/pkg_install/files/lib/fexec.c
 cvs rdiff -r1.16 -r1.17 pkgsrc/pkgtools/pkg_install/files/lib/file.c
 cvs rdiff -r1.20 -r1.21 pkgsrc/pkgtools/pkg_install/files/lib/lib.h

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

From: Ben Collver <ben@netbsd.org>
To: gnats-bugs@netbsd.org
Cc: 
Subject: PR/32228 CVS commit: src/usr.sbin/pkg_install
Date: Tue,  6 Dec 2005 01:07:30 +0000 (UTC)

 Module Name:	src
 Committed By:	ben
 Date:		Tue Dec  6 01:07:30 UTC 2005

 Modified Files:
 	src/usr.sbin/pkg_install/add: futil.c
 	src/usr.sbin/pkg_install/lib: fexec.c file.c lib.h

 Log Message:
 Specify the full path to tar when unpacking a package.
 Modify pfcexec so the new process file name can be different from argv[0].
 This fix is from Peter Postma, and it addresses PR#32228


 To generate a diff of this commit:
 cvs rdiff -r1.17 -r1.18 src/usr.sbin/pkg_install/add/futil.c
 cvs rdiff -r1.9 -r1.10 src/usr.sbin/pkg_install/lib/fexec.c
 cvs rdiff -r1.75 -r1.76 src/usr.sbin/pkg_install/lib/file.c
 cvs rdiff -r1.80 -r1.81 src/usr.sbin/pkg_install/lib/lib.h

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

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