summaryrefslogtreecommitdiff
path: root/pkgtools
diff options
context:
space:
mode:
authorben <ben@pkgsrc.org>2004-10-14 16:11:05 +0000
committerben <ben@pkgsrc.org>2004-10-14 16:11:05 +0000
commit62580eacca3bf8e2a378b53639d2b6666a8ad643 (patch)
tree4aefca18dd3cf44302e3ed88daeeee3c6ec4df33 /pkgtools
parent1e47b42f8f13517d59cf78b6c109f4292424a9b4 (diff)
downloadpkgsrc-62580eacca3bf8e2a378b53639d2b6666a8ad643.tar.gz
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.
Diffstat (limited to 'pkgtools')
-rw-r--r--pkgtools/pkgclean/Makefile4
-rw-r--r--pkgtools/pkgclean/files/pkgclean.c28
2 files changed, 15 insertions, 17 deletions
diff --git a/pkgtools/pkgclean/Makefile b/pkgtools/pkgclean/Makefile
index ec3484bcfd0..2a8ae9a5434 100644
--- a/pkgtools/pkgclean/Makefile
+++ b/pkgtools/pkgclean/Makefile
@@ -1,6 +1,6 @@
-# $NetBSD: Makefile,v 1.2 2004/10/07 02:01:38 jlam Exp $
+# $NetBSD: Makefile,v 1.3 2004/10/14 16:11:05 ben Exp $
-DISTNAME= pkgclean-20040622
+DISTNAME= pkgclean-20041014
CATEGORIES= pkgtools
MASTER_SITES= # empty
DISTFILES= # empty
diff --git a/pkgtools/pkgclean/files/pkgclean.c b/pkgtools/pkgclean/files/pkgclean.c
index 23011e7715c..2af58555527 100644
--- a/pkgtools/pkgclean/files/pkgclean.c
+++ b/pkgtools/pkgclean/files/pkgclean.c
@@ -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 const char * const skip[] = {
};
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 @@ static void
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 @@ pkgclean(const char *path, const char *work)
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 @@ pkgclean(const char *path, const char *work)
free(cat);
}
-
-#ifdef __OpenBSD__
-static int
-checkskip(struct dirent *dp)
-#else
static int
checkskip(const struct dirent *dp)
-#endif
{
const char * const *p;