pkgsrc-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[pkgsrc/trunk]: pkgsrc/pkgtools/pkgclean Change pkgclean to wait for the term...
details: https://anonhg.NetBSD.org/pkgsrc/rev/bf905bc084d2
branches: trunk
changeset: 481896:bf905bc084d2
user: ben <ben%pkgsrc.org@localhost>
date: Thu Oct 14 16:11:05 2004 +0000
description:
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:
pkgtools/pkgclean/Makefile | 4 ++--
pkgtools/pkgclean/files/pkgclean.c | 28 +++++++++++++---------------
2 files changed, 15 insertions(+), 17 deletions(-)
diffs (83 lines):
diff -r 2d795e177b9d -r bf905bc084d2 pkgtools/pkgclean/Makefile
--- a/pkgtools/pkgclean/Makefile Thu Oct 14 16:04:49 2004 +0000
+++ b/pkgtools/pkgclean/Makefile Thu Oct 14 16:11:05 2004 +0000
@@ -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 -r 2d795e177b9d -r bf905bc084d2 pkgtools/pkgclean/files/pkgclean.c
--- a/pkgtools/pkgclean/files/pkgclean.c Thu Oct 14 16:04:49 2004 +0000
+++ b/pkgtools/pkgclean/files/pkgclean.c Thu Oct 14 16:11:05 2004 +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;
Home |
Main Index |
Thread Index |
Old Index