NetBSD Problem Report #27250

Received: (qmail 14797 invoked by uid 605); 13 Oct 2004 12:25:43 -0000
Message-Id: <20041013122539.65F0910F4B@bonnie.jaist.ac.jp>
Date: Wed, 13 Oct 2004 21:25:39 +0900 (JST)
From: Ryo HAYASAKA <ryoh@jaist.ac.jp>
Sender: gnats-bugs-owner@NetBSD.org
Reply-To: ryoh@jaist.ac.jp
To: gnats-bugs@gnats.NetBSD.org
Subject: man page of pkgclean should explicitly say "working in background"
X-Send-Pr-Version: 3.95

>Number:         27250
>Category:       pkg
>Synopsis:       man page of pkgclean should explicitly say "working in background"
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    pkg-manager
>State:          closed
>Class:          doc-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Oct 13 12:26:00 +0000 2004
>Closed-Date:    Thu Oct 14 16:59:46 +0000 2004
>Last-Modified:  Thu Oct 14 16:59:46 +0000 2004
>Originator:     Ryo HAYASAKA
>Release:        NetBSD 2.99.9
>Organization:
Japan Advanced Institute of Science and Technology (JAIST)
>Environment:
System: NetBSD bonnie.jaist.ac.jp 2.99.9 NetBSD 2.99.9 (BONNIE) #508: Wed Oct 13 14:33:59 JST 2004 ryoh@bonnie.jaist.ac.jp:/sys/arch/i386/compile/BONNIE i386
Architecture: i386
Machine: i386
ryoh@bonnie$ pkg_info | fgrep pkgclean
pkgclean-20040622   Quickly clean up all work directories in pkgsrc

>Description:
The man page of pkgclean describes pkgclean as a fast alternative for
"cd /usr/pkgsrc && make clean", which waits for finishing the deletion
of all "work" directories.  When "make clean" finishes, all "work"
directories have been deleted.

In the meantime, pkgclean does not wait for finishing the deletion of
them, since it forks and its child processes actually do the job.
Although pkgclean finishes, many "rm" processes are still running.

The difference of the process in foreground for "make clean" and in
background for pkgclean is confusing.

>How-To-Repeat:

>Fix:
Say that pkgclean runs in background (like "cd /usr/pkgsrc && make clean
&"?) in the man page, or change pkgclean to wait for the termination of
all the child processes.

>Release-Note:
>Audit-Trail:

From: Peter Postma <peter@pointless.nl>
To: gnats-bugs@NetBSD.org
Cc: ryoh@jaist.ac.jp
Subject: Re: pkg/27250
Date: Thu, 14 Oct 2004 14:32:56 +0200

 Hi,

 The program should wait for the child to finish.
 This patch fixes it.

 Regards,
 Peter Postma

 Index: Makefile
 ===================================================================
 RCS file: /cvsroot/pkgsrc/pkgtools/pkgclean/Makefile,v
 retrieving revision 1.2
 diff -u -r1.2 Makefile
 --- Makefile	7 Oct 2004 02:01:38 -0000	1.2
 +++ Makefile	14 Oct 2004 12:29:03 -0000
 @@ -1,6 +1,6 @@
  # $NetBSD: Makefile,v 1.2 2004/10/07 02:01:38 jlam Exp $

 -DISTNAME=	pkgclean-20040622
 +DISTNAME=	pkgclean-20041014
  CATEGORIES=	pkgtools
  MASTER_SITES=	# empty
  DISTFILES=	# empty
 Index: files/pkgclean.c
 ===================================================================
 RCS file: /cvsroot/pkgsrc/pkgtools/pkgclean/files/pkgclean.c,v
 retrieving revision 1.1.1.1
 diff -u -r1.1.1.1 pkgclean.c
 --- files/pkgclean.c	22 Jun 2004 20:02:43 -0000	1.1.1.1
 +++ files/pkgclean.c	14 Oct 2004 12:29:03 -0000
 @@ -28,6 +28,7 @@
  #include <sys/types.h>
  #include <sys/param.h>
  #include <sys/stat.h>
 +#include <sys/wait.h>

  #include <err.h>
  #include <dirent.h>
 @@ -44,11 +45,7 @@
  };

  static void	pkgclean(const char *, const char *);
 -#ifdef __OpenBSD__
 -static int	checkskip(struct dirent *);
 -#else
  static int	checkskip(const struct dirent *);
 -#endif

  int
  main(int argc, char *argv[])
 @@ -70,9 +67,10 @@
  pkgclean(const char *path, const char *work)
  {
  	struct dirent **cat, **list;
 -	int ncat, nlist, i, j;
 +	int status, ncat, nlist, i, j;
  	char tmp[PATH_MAX];
  	struct stat sb;
 +	pid_t pid;

  	if ((ncat = scandir(path, &cat, checkskip, alphasort)) < 0)
  		err(EXIT_FAILURE, "scandir: %s", path);
 @@ -98,10 +96,16 @@
  			if (stat(tmp, &sb) < 0 || !S_ISDIR(sb.st_mode))
  				continue;
  			(void)printf("Deleting %s\n", tmp);
 -			if (fork() == 0) {
 -				(void)execl("/bin/rm", "rm", "-rf", tmp, (char *)NULL);
 -				err(EXIT_FAILURE, "Failed to exec /bin/rm"); 
 -			}
 +			pid = fork();
 +			if (pid < 0) {
 +				warn("fork");
 +				continue;
 +			} else if (pid == 0)
 +				(void)execl("/bin/rm", "rm", "-rf", tmp, NULL);
 +			if (waitpid(pid, &status, 0) == -1)
 +				err(EXIT_FAILURE, "waitpid");
 +			if (WEXITSTATUS(status))
 +				warn("/bin/rm terminated abnormally");
  			free(list[j]);
  		}
  		free(cat[i]);
 @@ -110,14 +114,8 @@
  	free(cat);
  }

 -
 -#ifdef __OpenBSD__
 -static int
 -checkskip(struct dirent *dp)
 -#else
  static int
  checkskip(const struct dirent *dp)
 -#endif
  {
  	const char * const *p;


 -- 
 Peter Postma

From: Ben Collver <ben@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:  
Subject: pr/27250 CVS commit: pkgsrc/pkgtools/pkgclean
Date: Thu, 14 Oct 2004 16:11:05 +0000 (UTC)

 Module Name:	pkgsrc
 Committed By:	ben
 Date:		Thu Oct 14 16:11:05 UTC 2004

 Modified Files:
 	pkgsrc/pkgtools/pkgclean: Makefile
 	pkgsrc/pkgtools/pkgclean/files: pkgclean.c

 Log Message:
 Change pkgclean to wait for the termination of all the child processes.
 This fix comes from Peter Postma, and it addresses a problem reported
 by Ryo HAYASAKA in PR#27250.


 To generate a diff of this commit:
 cvs rdiff -r1.2 -r1.3 pkgsrc/pkgtools/pkgclean/Makefile
 cvs rdiff -r1.1.1.1 -r1.2 pkgsrc/pkgtools/pkgclean/files/pkgclean.c

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

State-Changed-From-To: open->closed 
State-Changed-By: wiz 
State-Changed-When: Thu Oct 14 16:59:09 UTC 2004 
State-Changed-Why:  
Fixed, but differently -- it now waits for the childs to finish. 
>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.