summaryrefslogtreecommitdiffstats
path: root/usr.sbin/pkg_install/lib
diff options
context:
space:
mode:
authorjkh <jkh@FreeBSD.org>1994-12-06 00:51:50 +0000
committerjkh <jkh@FreeBSD.org>1994-12-06 00:51:50 +0000
commit773a5f451d951042f1a9541533ee9b5c97430c39 (patch)
tree769d2ca49d84039a97bd74c4ce202b318da0828a /usr.sbin/pkg_install/lib
parentf9dc382f6c8f8900550f2f35436613d329df120d (diff)
downloadFreeBSD-src-773a5f451d951042f1a9541533ee9b5c97430c39.zip
FreeBSD-src-773a5f451d951042f1a9541533ee9b5c97430c39.tar.gz
Many of John T. Kohl's patches from NetBSD. Thanks, John!
Submitted by: jkohl
Diffstat (limited to 'usr.sbin/pkg_install/lib')
-rw-r--r--usr.sbin/pkg_install/lib/exec.c20
-rw-r--r--usr.sbin/pkg_install/lib/file.c22
-rw-r--r--usr.sbin/pkg_install/lib/lib.h12
-rw-r--r--usr.sbin/pkg_install/lib/plist.c73
4 files changed, 101 insertions, 26 deletions
diff --git a/usr.sbin/pkg_install/lib/exec.c b/usr.sbin/pkg_install/lib/exec.c
index 5232dd2..dd6b184 100644
--- a/usr.sbin/pkg_install/lib/exec.c
+++ b/usr.sbin/pkg_install/lib/exec.c
@@ -1,5 +1,5 @@
#ifndef lint
-static const char *rcsid = "$Id: exec.c,v 1.4 1993/09/04 05:06:47 jkh Exp $";
+static const char *rcsid = "$Id: exec.c,v 1.2 1993/09/03 23:01:12 jkh Exp $";
#endif
/*
@@ -33,16 +33,28 @@ int
vsystem(const char *fmt, ...)
{
va_list args;
- char cmd[FILENAME_MAX * 2]; /* reasonable default for what I do */
- int ret;
+ char *cmd;
+ int ret, maxargs;
+
+ maxargs = sysconf(_SC_ARG_MAX);
+ maxargs -= 32; /* some slop for the sh -c */
+ cmd = malloc(maxargs);
+ if (!cmd) {
+ whinge("vsystem can't alloc arg space");
+ return 1;
+ }
va_start(args, fmt);
- vsprintf(cmd, fmt, args);
+ if (vsnprintf(cmd, maxargs, fmt, args) > maxargs) {
+ whinge("vsystem args are too long");
+ return 1;
+ }
#ifdef DEBUG
printf("Executing %s\n", cmd);
#endif
ret = system(cmd);
va_end(args);
+ free(cmd);
return ret;
}
diff --git a/usr.sbin/pkg_install/lib/file.c b/usr.sbin/pkg_install/lib/file.c
index 698fd87..e2c2668 100644
--- a/usr.sbin/pkg_install/lib/file.c
+++ b/usr.sbin/pkg_install/lib/file.c
@@ -1,5 +1,5 @@
#ifndef lint
-static const char *rcsid = "$Id: file.c,v 1.4 1993/09/06 23:28:42 jkh Exp $";
+static const char *rcsid = "$Id: file.c,v 1.5 1993/09/18 03:39:48 jkh Exp $";
#endif
/*
@@ -39,8 +39,7 @@ isdir(char *fname)
{
struct stat sb;
- if (stat(fname, &sb) != FAIL &&
- (sb.st_mode & S_IFDIR))
+ if (stat(fname, &sb) != FAIL && S_ISDIR(sb.st_mode))
return TRUE;
else
return FALSE;
@@ -48,7 +47,7 @@ isdir(char *fname)
/* Check to see if file is a dir, and is empty */
Boolean
-isempty(char *fname)
+isemptydir(char *fname)
{
if (isdir(fname)) {
DIR *dirp;
@@ -69,6 +68,19 @@ isempty(char *fname)
return FALSE;
}
+/* Check to see if file is a file and is empty. If nonexistent or not
+ a file, say "it's empty", otherwise return TRUE if zero sized. */
+Boolean
+isemptyfile(char *fname)
+{
+ struct stat sb;
+ if (stat(fname, &sb) != FAIL && S_ISREG(sb.st_mode)) {
+ if (sb.st_size != 0)
+ return FALSE;
+ }
+ return TRUE;
+}
+
char *
get_file_contents(char *fname)
{
@@ -84,7 +96,7 @@ get_file_contents(char *fname)
if (fd == FAIL)
barf("Unable to open '%s' for reading.", fname);
if (read(fd, contents, sb.st_size) != sb.st_size)
- barf("Short read on '%s' - did not get %d bytes.", fname, sb.st_size);
+ barf("Short read on '%s' - did not get %qd bytes.", fname, sb.st_size);
close(fd);
contents[sb.st_size] = '\0';
return contents;
diff --git a/usr.sbin/pkg_install/lib/lib.h b/usr.sbin/pkg_install/lib/lib.h
index b9f6a15..abcfed7 100644
--- a/usr.sbin/pkg_install/lib/lib.h
+++ b/usr.sbin/pkg_install/lib/lib.h
@@ -1,4 +1,4 @@
-/* $Id: lib.h,v 1.10 1994/10/04 16:07:50 jkh Exp $ */
+/* $Id: lib.h,v 1.11 1994/11/17 10:51:46 jkh Exp $ */
/*
* FreeBSD install - a package for the installation and maintainance
@@ -66,6 +66,9 @@
#define INSTALL_FNAME "+INSTALL"
#define DEINSTALL_FNAME "+DEINSTALL"
#define REQUIRE_FNAME "+REQUIRE"
+#define REQUIRED_BY_FNAME "+REQUIRED_BY"
+#define DISPLAY_FNAME "+DISPLAY"
+#define MTREE_FNAME "+MTREE_DIRS"
#define CMD_CHAR '@' /* prefix for extended PLIST cmd */
@@ -75,7 +78,8 @@
enum _plist_t {
PLIST_FILE, PLIST_CWD, PLIST_CMD, PLIST_CHMOD,
PLIST_CHOWN, PLIST_CHGRP, PLIST_COMMENT,
- PLIST_IGNORE, PLIST_NAME, PLIST_UNEXEC, PLIST_SRC
+ PLIST_IGNORE, PLIST_NAME, PLIST_UNEXEC, PLIST_SRC, PLIST_DISPLAY,
+ PLIST_PKGDEP, PLIST_MTREE, PLIST_DIR_RM, PLIST_IGNORE_INST
};
typedef enum _plist_t plist_t;
@@ -119,7 +123,7 @@ char *get_file_contents(char *);
void write_file(char *, char *);
void copy_file(char *, char *, char *);
void copy_hierarchy(char *, char *, Boolean);
-int delete_hierarchy(char *, Boolean);
+int delete_hierarchy(char *, Boolean, Boolean);
int unpack(char *, char *);
void format_cmd(char *, char *, char *, char *);
@@ -142,7 +146,7 @@ void add_plist_top(Package *, plist_t, char *);
void write_plist(Package *, FILE *);
void read_plist(Package *, FILE *);
int plist_cmd(char *, char **);
-int delete_package(Boolean, Package *);
+int delete_package(Boolean, Boolean, Package *);
/* For all */
void usage(const char *, const char *, ...);
diff --git a/usr.sbin/pkg_install/lib/plist.c b/usr.sbin/pkg_install/lib/plist.c
index 577ae5e..282f3d0 100644
--- a/usr.sbin/pkg_install/lib/plist.c
+++ b/usr.sbin/pkg_install/lib/plist.c
@@ -1,5 +1,5 @@
#ifndef lint
-static const char *rcsid = "$Id: plist.c,v 1.8 1994/08/28 14:15:30 jkh Exp $";
+static const char *rcsid = "$Id: plist.c,v 1.9 1994/09/29 13:19:43 jkh Exp $";
#endif
/*
@@ -198,8 +198,18 @@ plist_cmd(char *s, char **arg)
return PLIST_COMMENT;
else if (!strcmp(cmd, "ignore"))
return PLIST_IGNORE;
+ else if (!strcmp(cmd, "ignore_inst"))
+ return PLIST_IGNORE_INST;
else if (!strcmp(cmd, "name"))
return PLIST_NAME;
+ else if (!strcmp(cmd, "display"))
+ return PLIST_DISPLAY;
+ else if (!strcmp(cmd, "pkgdep"))
+ return PLIST_PKGDEP;
+ else if (!strcmp(cmd, "mtree"))
+ return PLIST_MTREE;
+ else if (!strcmp(cmd, "dirrm"))
+ return PLIST_DIR_RM;
else
return FAIL;
}
@@ -280,6 +290,7 @@ write_plist(Package *pkg, FILE *fp)
break;
case PLIST_IGNORE:
+ case PLIST_IGNORE_INST: /* a one-time non-ignored file */
fprintf(fp, "%cignore\n", CMD_CHAR);
break;
@@ -287,6 +298,22 @@ write_plist(Package *pkg, FILE *fp)
fprintf(fp, "%cname %s\n", CMD_CHAR, plist->name);
break;
+ case PLIST_DISPLAY:
+ fprintf(fp, "%cdisplay %s\n", CMD_CHAR, plist->name);
+ break;
+
+ case PLIST_PKGDEP:
+ fprintf(fp, "%cpkgdep %s\n", CMD_CHAR, plist->name);
+ break;
+
+ case PLIST_MTREE:
+ fprintf(fp, "%cmtree %s\n", CMD_CHAR, plist->name);
+ break;
+
+ case PLIST_DIR_RM:
+ fprintf(fp, "%cdirrm %s\n", CMD_CHAR, plist->name);
+ break;
+
default:
barf("Unknown command type %d (%s)\n", plist->type, plist->name);
break;
@@ -297,7 +324,7 @@ write_plist(Package *pkg, FILE *fp)
/* Delete the results of a package installation, not the packaging itself */
int
-delete_package(Boolean ign_err, Package *pkg)
+delete_package(Boolean ign_err, Boolean nukedirs, Package *pkg)
{
PackingList p = pkg->head;
char *Where = ".", *last_file = "";
@@ -322,14 +349,16 @@ delete_package(Boolean ign_err, Package *pkg)
}
else if (p->type == PLIST_IGNORE)
p = p->next;
- else if (p->type == PLIST_FILE) {
+ else if (p->type == PLIST_FILE || p->type == PLIST_DIR_RM) {
char full_name[FILENAME_MAX];
sprintf(full_name, "%s/%s", Where, p->name);
if (Verbose)
- printf("Delete: %s\n", full_name);
+ printf("Delete%s: %s\n",
+ p->type == PLIST_FILE ? "" : " directory", full_name);
- if (!Fake && delete_hierarchy(full_name, ign_err)) {
+ if (!Fake && delete_hierarchy(full_name, ign_err,
+ p->type == PLIST_DIR_RM ? FALSE : nukedirs)) {
whinge("Unable to completely remove file '%s'", full_name);
fail = FAIL;
}
@@ -340,26 +369,44 @@ delete_package(Boolean ign_err, Package *pkg)
return fail;
}
+#ifdef DEBUG
+#define RMDIR(dir) vsystem("%s %s", RMDIR_CMD, dir)
+#define REMOVE(dir,ie) vsystem("%s %s%s", REMOVE_CMD, (ie ? "-f " : ""), dir)
+#else
+#define RMDIR rmdir
+#define REMOVE(file,ie) remove(file)
+#endif
+
/* Selectively delete a hierarchy */
int
-delete_hierarchy(char *dir, Boolean ign_err)
+delete_hierarchy(char *dir, Boolean ign_err, Boolean nukedirs)
{
char *cp1, *cp2;
cp1 = cp2 = dir;
- if (vsystem("%s -r%s %s", REMOVE_CMD, (ign_err ? "f" : ""), dir))
- return 1;
+ if (nukedirs) {
+ if (vsystem("%s -r%s %s", REMOVE_CMD, (ign_err ? "f" : ""), dir))
+ return 1;
+ } else if (isdir(dir)) {
+ if (RMDIR(dir))
+ return 1;
+ } else {
+ if (REMOVE(dir, ign_err))
+ return 1;
+ }
+
+ if (!nukedirs)
+ return 0;
while (cp2) {
if ((cp2 = rindex(cp1, '/')) != NULL)
*cp2 = '\0';
- if (!isempty(dir))
+ if (!isemptydir(dir))
return 0;
- if (vsystem("%s %s", RMDIR_CMD, dir) && ign_err)
+ if (RMDIR(dir) && ign_err)
return 1;
- /* Put it back */
+ /* back up the pathname one component */
if (cp2) {
- *cp2 = '/';
- cp1 = cp2 - 1;
+ cp1 = dir;
}
}
return 0;
OpenPOWER on IntegriCloud