diff options
author | Marco S Hyman <marc@cvs.openbsd.org> | 1998-09-07 22:30:18 +0000 |
---|---|---|
committer | Marco S Hyman <marc@cvs.openbsd.org> | 1998-09-07 22:30:18 +0000 |
commit | b7191a530a228038c0867ad6aedd90f5b534d1e9 (patch) | |
tree | dff11f7b0f8e66c2c0a6b6dbf273127ef93423cd /usr.sbin/pkg_install/create/perform.c | |
parent | d772ee662c59d0c57ee6ec091bcc1b5d284fb641 (diff) |
updated pkg_* tools. Merged in many changes/improvements from NetBSD.
New features include md5 hash so pkg_delete won't remove files that have
changed and the ability to define conflicting packages, e.g. you can't
install both mh and nmh. The ports tree will have to be updated to take
advantage of this.
Let me know of any problems, real or imagined :-)
Diffstat (limited to 'usr.sbin/pkg_install/create/perform.c')
-rw-r--r-- | usr.sbin/pkg_install/create/perform.c | 94 |
1 files changed, 71 insertions, 23 deletions
diff --git a/usr.sbin/pkg_install/create/perform.c b/usr.sbin/pkg_install/create/perform.c index 83ceae813a2..53aaf2ca084 100644 --- a/usr.sbin/pkg_install/create/perform.c +++ b/usr.sbin/pkg_install/create/perform.c @@ -1,7 +1,7 @@ -/* $OpenBSD: perform.c,v 1.4 1997/01/17 07:14:13 millert Exp $ */ +/* $OpenBSD: perform.c,v 1.5 1998/09/07 22:30:14 marc Exp $ */ #ifndef lint -static const char *rcsid = "$OpenBSD: perform.c,v 1.4 1997/01/17 07:14:13 millert Exp $"; +static const char *rcsid = "$OpenBSD: perform.c,v 1.5 1998/09/07 22:30:14 marc Exp $"; #endif /* @@ -27,9 +27,10 @@ static const char *rcsid = "$OpenBSD: perform.c,v 1.4 1997/01/17 07:14:13 miller #include "lib.h" #include "create.h" -#include <errno.h> +#include <err.h> #include <signal.h> #include <sys/syslimits.h> +#include <sys/wait.h> #include <unistd.h> static void sanity_check(void); @@ -57,7 +58,8 @@ pkg_perform(char **pkgs) else { pkg_in = fopen(Contents, "r"); if (!pkg_in) - barf("Unable to open contents file '%s' for input.", Contents); + cleanup(0), errx(2, "unable to open contents file '%s' for input", + Contents); } plist.head = plist.tail = NULL; @@ -84,6 +86,30 @@ pkg_perform(char **pkgs) if (Verbose && !PlistOnly) printf(".\n"); } + + /* Put the conflicts directly after the dependencies, if any */ + if (Pkgcfl) { + if (Verbose && !PlistOnly) + printf("Registering conflicts:"); + while (Pkgcfl) { + cp = strsep(&Pkgcfl, " \t\n"); + if (*cp) { + add_plist(&plist, PLIST_PKGCFL, cp); + if (Verbose && !PlistOnly) + printf(" %s", cp); + } + } + if (Verbose && !PlistOnly) + printf(".\n"); + } + + /* If a SrcDir override is set, add it now */ + if (SrcDir) { + if (Verbose && !PlistOnly) + printf("Using SrcDir value of %s\n", SrcDir); + add_plist(&plist, PLIST_SRC, SrcDir); + } + /* Slurp in the packing list */ read_plist(&plist, pkg_in); @@ -104,6 +130,7 @@ pkg_perform(char **pkgs) * hack. It's not a real create in progress. */ if (PlistOnly) { + check_list(home, &plist); write_plist(&plist, stdout); exit(0); } @@ -157,18 +184,13 @@ pkg_perform(char **pkgs) add_plist(&plist, PLIST_MTREE, MTREE_FNAME); } - /* Run through the list again, picking up extra "local" items */ - /* check_list(".", &plist); */ - /* copy_plist(".", &plist); */ - /* mark_plist(&plist); */ - /* Finally, write out the packing list */ fp = fopen(CONTENTS_FNAME, "w"); if (!fp) - barf("Can't open file %s for writing.", CONTENTS_FNAME); + cleanup(0), errx(2, "can't open file %s for writing", CONTENTS_FNAME); write_plist(&plist, fp); if (fclose(fp)) - barf("Error while closing %s.", CONTENTS_FNAME); + cleanup(0), errx(2, "error while closing %s", CONTENTS_FNAME); /* And stick it into a tar ball */ make_dist(home, pkg, suffix, &plist); @@ -177,7 +199,7 @@ pkg_perform(char **pkgs) free(Comment); free(Desc); free_plist(&plist); - cleanup(0); + leave_playpen(home); return TRUE; /* Success */ } @@ -186,10 +208,9 @@ make_dist(char *home, char *pkg, char *suffix, Package *plist) { char tball[FILENAME_MAX]; PackingList p; - int ret, max, len; - /* XXX - The next one should be - allocated dynamically */ - char *args[4096]; /* Much more than enough. */ + int ret; +#define DIST_MAX_ARGS 4096 + char *args[DIST_MAX_ARGS]; /* Much more than enough. */ int nargs = 0; int pipefds[2]; FILE *totar; @@ -238,6 +259,8 @@ make_dist(char *home, char *pkg, char *suffix, Package *plist) args[nargs++] = MTREE_FNAME; for (p = plist->head; p; p = p->next) { + if (nargs > (DIST_MAX_ARGS - 2)) + errx(2, "too many args for tar command"); if (p->type == PLIST_FILE) args[nargs++] = p->name; else if (p->type == PLIST_CWD || p->type == PLIST_SRC) { @@ -248,24 +271,34 @@ make_dist(char *home, char *pkg, char *suffix, Package *plist) p = p->next; } args[nargs] = NULL; - execv("/bin/tar", args); - barf("Failed to execute tar command: %s", strerror(errno)); + /* fork/exec tar to create the package */ + + pid = fork(); + if ( pid < 0 ) + err(2, "failed to fork"); + else if ( pid == 0 ) { + execv("/bin/tar", args); + err(2, "failed to execute tar command"); + } wait(&ret); /* assume either signal or bad exit is enough for us */ if (ret) - barf("tar command failed with code %d", ret); + cleanup(0), errx(2, "tar command failed with code %d", ret); } static void sanity_check() { if (!Comment) - barf("Required package comment string is missing (-c comment)."); + cleanup(0), errx(2, + "required package comment string is missing (-c comment)"); if (!Desc) - barf("Required package description string is missing (-d desc)."); + cleanup(0), errx(2, + "required package description string is missing (-d desc)"); if (!Contents) - barf("Required package contents list is missing (-f [-]file)."); + cleanup(0), errx(2, + "required package contents list is missing (-f [-]file)"); } @@ -273,5 +306,20 @@ sanity_check() void cleanup(int sig) { - leave_playpen(home); + static int alreadyCleaning; + void (*oldint)(int); + void (*oldhup)(int); + oldint = signal(SIGINT, SIG_IGN); + oldhup = signal(SIGHUP, SIG_IGN); + + if (!alreadyCleaning) { + alreadyCleaning = 1; + if (sig) + printf("Signal %d received, cleaning up.\n", sig); + leave_playpen(home); + if (sig) + exit(1); + } + signal(SIGINT, oldint); + signal(SIGHUP, oldhup); } |