Fri Aug 5 07:04:28 2011 UTC ()
Fix for pkg_delete on NFS from Anthony Mallet.

Problem analysis from Anthony:

	On Wednesday, at 23:52, Anthony Mallet wrote:
	> # rm -rf ~tmp && mkdir ~/tmp
	> # pkg_add -K ~/tmp/var/db/pkg -p ~/tmp /usr/pkgsrc/packages/All/digest-20080510.tgz
	> # pkg_add -U -K ~/tmp/var/db/pkg -p ~/tmp /usr/pkgsrc/packages/All/digest-20080510.tgz
	> pkg_delete: Couldn't remove package directory in `/home/tho/tmp/var/db/pkg/digest-20080510'
	> Also, the dir var/db/pkg/digest-20080510.xxxxxxx is never cleaned.
	>
	> The problem apparently is that pkg_delete finds some stalled NFS entries
	> (.nfs*) in the var/db/pkg/digest-20080510 dir, so it does not delete the
	> directory. Is this due to pkg_add not correctly closing file descriptors before
	> exec'ing pkg_delete? For instance, I really don't understand the logic in
	> check_already_installed() (add/perform.c:375) regarding the open() of +CONTENTS
	> which is almost never closed (and never used as well...). Shouldn't this be
	> closed before running pkg_delete?

	ktrace shows that the +CONTENTS file is open() by pkg_add, I believe this is in
	check_already_installed(), add/perform.c:381. Then pkg_delete is run and when
	it comes to deleting the pkgdir entry, it finds that .nfs file and aborts.

Bump version to 20110805


(agc)
diff -r1.99 -r1.100 pkgsrc/pkgtools/pkg_install/files/add/perform.c
diff -r1.161 -r1.162 pkgsrc/pkgtools/pkg_install/files/lib/version.h

cvs diff -r1.99 -r1.100 pkgsrc/pkgtools/pkg_install/files/add/perform.c (expand / switch to unified diff)

--- pkgsrc/pkgtools/pkg_install/files/add/perform.c 2010/12/12 13:18:38 1.99
+++ pkgsrc/pkgtools/pkg_install/files/add/perform.c 2011/08/05 07:04:28 1.100
@@ -1,22 +1,22 @@ @@ -1,22 +1,22 @@
1/* $NetBSD: perform.c,v 1.99 2010/12/12 13:18:38 wiz Exp $ */ 1/* $NetBSD: perform.c,v 1.100 2011/08/05 07:04:28 agc Exp $ */
2#if HAVE_CONFIG_H 2#if HAVE_CONFIG_H
3#include "config.h" 3#include "config.h"
4#endif 4#endif
5#include <nbcompat.h> 5#include <nbcompat.h>
6#if HAVE_SYS_CDEFS_H 6#if HAVE_SYS_CDEFS_H
7#include <sys/cdefs.h> 7#include <sys/cdefs.h>
8#endif 8#endif
9__RCSID("$NetBSD: perform.c,v 1.99 2010/12/12 13:18:38 wiz Exp $"); 9__RCSID("$NetBSD: perform.c,v 1.100 2011/08/05 07:04:28 agc Exp $");
10 10
11/*- 11/*-
12 * Copyright (c) 2003 Grant Beattie <grant@NetBSD.org> 12 * Copyright (c) 2003 Grant Beattie <grant@NetBSD.org>
13 * Copyright (c) 2005 Dieter Baron <dillo@NetBSD.org> 13 * Copyright (c) 2005 Dieter Baron <dillo@NetBSD.org>
14 * Copyright (c) 2007 Roland Illig <rillig@NetBSD.org> 14 * Copyright (c) 2007 Roland Illig <rillig@NetBSD.org>
15 * Copyright (c) 2008, 2009 Joerg Sonnenberger <joerg@NetBSD.org> 15 * Copyright (c) 2008, 2009 Joerg Sonnenberger <joerg@NetBSD.org>
16 * Copyright (c) 2010 Thomas Klausner <wiz@NetBSD.org> 16 * Copyright (c) 2010 Thomas Klausner <wiz@NetBSD.org>
17 * All rights reserved. 17 * All rights reserved.
18 * 18 *
19 * Redistribution and use in source and binary forms, with or without 19 * Redistribution and use in source and binary forms, with or without
20 * modification, are permitted provided that the following conditions 20 * modification, are permitted provided that the following conditions
21 * are met: 21 * are met:
22 * 22 *
@@ -372,26 +372,27 @@ dup_value(const char *line, const char * @@ -372,26 +372,27 @@ dup_value(const char *line, const char *
372} 372}
373 373
374static int 374static int
375check_already_installed(struct pkg_task *pkg) 375check_already_installed(struct pkg_task *pkg)
376{ 376{
377 char *filename; 377 char *filename;
378 int fd; 378 int fd;
379 379
380 filename = pkgdb_pkg_file(pkg->pkgname, CONTENTS_FNAME); 380 filename = pkgdb_pkg_file(pkg->pkgname, CONTENTS_FNAME);
381 fd = open(filename, O_RDONLY); 381 fd = open(filename, O_RDONLY);
382 free(filename); 382 free(filename);
383 if (fd == -1) 383 if (fd == -1)
384 return 1; 384 return 1;
 385 close(fd);
385 386
386 if (ReplaceSame) { 387 if (ReplaceSame) {
387 struct stat sb; 388 struct stat sb;
388 389
389 pkg->install_logdir_real = pkg->install_logdir; 390 pkg->install_logdir_real = pkg->install_logdir;
390 pkg->install_logdir = xasprintf("%s.xxxxxx", pkg->install_logdir); 391 pkg->install_logdir = xasprintf("%s.xxxxxx", pkg->install_logdir);
391 if (stat(pkg->install_logdir, &sb) == 0) { 392 if (stat(pkg->install_logdir, &sb) == 0) {
392 warnx("package `%s' already has a temporary update " 393 warnx("package `%s' already has a temporary update "
393 "directory `%s', remove it manually", 394 "directory `%s', remove it manually",
394 pkg->pkgname, pkg->install_logdir); 395 pkg->pkgname, pkg->install_logdir);
395 return -1; 396 return -1;
396 } 397 }
397 return 1; 398 return 1;
@@ -401,27 +402,26 @@ check_already_installed(struct pkg_task  @@ -401,27 +402,26 @@ check_already_installed(struct pkg_task
401 return 1; 402 return 1;
402 403
403 /* We can only arrive here for explicitly requested packages. */ 404 /* We can only arrive here for explicitly requested packages. */
404 if (!Automatic && is_automatic_installed(pkg->pkgname)) { 405 if (!Automatic && is_automatic_installed(pkg->pkgname)) {
405 if (Fake || 406 if (Fake ||
406 mark_as_automatic_installed(pkg->pkgname, 0) == 0) 407 mark_as_automatic_installed(pkg->pkgname, 0) == 0)
407 warnx("package `%s' was already installed as " 408 warnx("package `%s' was already installed as "
408 "dependency, now marked as installed " 409 "dependency, now marked as installed "
409 "manually", pkg->pkgname); 410 "manually", pkg->pkgname);
410 } else { 411 } else {
411 warnx("package `%s' already recorded as installed", 412 warnx("package `%s' already recorded as installed",
412 pkg->pkgname); 413 pkg->pkgname);
413 } 414 }
414 close(fd); 
415 return 0; 415 return 0;
416 416
417} 417}
418 418
419static int 419static int
420check_other_installed(struct pkg_task *pkg) 420check_other_installed(struct pkg_task *pkg)
421{ 421{
422 FILE *f, *f_pkg; 422 FILE *f, *f_pkg;
423 size_t len; 423 size_t len;
424 char *pkgbase, *iter, *filename; 424 char *pkgbase, *iter, *filename;
425 package_t plist; 425 package_t plist;
426 plist_t *p; 426 plist_t *p;
427 int status; 427 int status;

cvs diff -r1.161 -r1.162 pkgsrc/pkgtools/pkg_install/files/lib/version.h (expand / switch to unified diff)

--- pkgsrc/pkgtools/pkg_install/files/lib/version.h 2011/02/18 15:59:52 1.161
+++ pkgsrc/pkgtools/pkg_install/files/lib/version.h 2011/08/05 07:04:28 1.162
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: version.h,v 1.161 2011/02/18 15:59:52 aymeric Exp $ */ 1/* $NetBSD: version.h,v 1.162 2011/08/05 07:04:28 agc Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2001 Thomas Klausner. All rights reserved. 4 * Copyright (c) 2001 Thomas Klausner. All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright 11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the 12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution. 13 * documentation and/or other materials provided with the distribution.
14 * 14 *
@@ -17,16 +17,16 @@ @@ -17,16 +17,16 @@
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */ 25 */
26 26
27#ifndef _INST_LIB_VERSION_H_ 27#ifndef _INST_LIB_VERSION_H_
28#define _INST_LIB_VERSION_H_ 28#define _INST_LIB_VERSION_H_
29 29
30#define PKGTOOLS_VERSION 20110215 30#define PKGTOOLS_VERSION 20110805
31 31
32#endif /* _INST_LIB_VERSION_H_ */ 32#endif /* _INST_LIB_VERSION_H_ */