]> CyberLeo.Net >> Repos - FreeBSD/releng/8.1.git/blob - usr.sbin/pkg_install/add/perform.c
Copy stable/8 to releng/8.1 in preparation for 8.1-RC1.
[FreeBSD/releng/8.1.git] / usr.sbin / pkg_install / add / perform.c
1 /*
2  * FreeBSD install - a package for the installation and maintainance
3  * of non-core utilities.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * Jordan K. Hubbard
15  * 18 July 1993
16  *
17  * This is the main body of the add module.
18  *
19  */
20
21 #include <sys/cdefs.h>
22 __FBSDID("$FreeBSD$");
23
24 #include <err.h>
25 #include <paths.h>
26 #include "lib.h"
27 #include "add.h"
28
29 #include <libgen.h>
30 #include <signal.h>
31 #include <sys/wait.h>
32
33 static int pkg_do(char *);
34 static int sanity_check(char *);
35 static char LogDir[FILENAME_MAX];
36 static int zapLogDir;           /* Should we delete LogDir? */
37
38 int
39 pkg_perform(char **pkgs)
40 {
41     int i, err_cnt = 0;
42
43     signal(SIGINT, cleanup);
44     signal(SIGHUP, cleanup);
45
46     if (AddMode == SLAVE)
47         err_cnt = pkg_do(NULL);
48     else {
49         for (i = 0; pkgs[i]; i++)
50             err_cnt += pkg_do(pkgs[i]);
51     }
52     return err_cnt;
53 }
54
55 /*
56  * This is seriously ugly code following.  Written very fast!
57  * [And subsequently made even worse..  Sigh!  This code was just born
58  * to be hacked, I guess.. :) -jkh]
59  */
60 static int
61 pkg_do(char *pkg)
62 {
63     Package Plist;
64     char pkg_fullname[FILENAME_MAX];
65     char playpen[FILENAME_MAX];
66     char extract_contents[FILENAME_MAX];
67     char *extract;
68     const char *where_to;
69     FILE *cfile;
70     int code;
71     PackingList p;
72     struct stat sb;
73     int inPlace, conflictsfound, errcode;
74     /* support for separate pre/post install scripts */
75     int new_m = 0;
76     char pre_script[FILENAME_MAX] = INSTALL_FNAME;
77     char post_script[FILENAME_MAX];
78     char pre_arg[FILENAME_MAX], post_arg[FILENAME_MAX];
79     char *conflict[2];
80     char **matched;
81
82     conflictsfound = 0;
83     code = 0;
84     zapLogDir = 0;
85     LogDir[0] = '\0';
86     strcpy(playpen, FirstPen);
87     inPlace = 0;
88
89     memset(&Plist, '\0', sizeof(Plist));
90
91     /* Are we coming in for a second pass, everything already extracted? */
92     if (!pkg) {
93         fgets(playpen, FILENAME_MAX, stdin);
94         playpen[strlen(playpen) - 1] = '\0'; /* pesky newline! */
95         if (chdir(playpen) == FAIL) {
96             warnx("pkg_add in SLAVE mode can't chdir to %s", playpen);
97             return 1;
98         }
99         read_plist(&Plist, stdin);
100         where_to = playpen;
101     }
102     /* Nope - do it now */
103     else {
104         /* Is it an ftp://foo.bar.baz/file.t[bg]z specification? */
105         if (isURL(pkg)) {
106             if (!(where_to = fileGetURL(NULL, pkg, KeepPackage))) {
107                 warnx("unable to fetch '%s' by URL", pkg);
108                 return 1;
109             }
110             strcpy(pkg_fullname, pkg);
111             cfile = fopen(CONTENTS_FNAME, "r");
112             if (!cfile) {
113                 warnx(
114                 "unable to open table of contents file '%s' - not a package?",
115                 CONTENTS_FNAME);
116                 goto bomb;
117             }
118             read_plist(&Plist, cfile);
119             fclose(cfile);
120         }
121         else {
122             strcpy(pkg_fullname, pkg);          /*
123                                                  * Copy for sanity's sake,
124                                                  * could remove pkg_fullname
125                                                  */
126             if (strcmp(pkg, "-")) {
127                 if (stat(pkg_fullname, &sb) == FAIL) {
128                     warnx("can't stat package file '%s'", pkg_fullname);
129                     goto bomb;
130                 }
131                 sprintf(extract_contents, "--fast-read %s", CONTENTS_FNAME);
132                 extract = extract_contents;
133             }
134             else {
135                 extract = NULL;
136                 sb.st_size = 100000;    /* Make up a plausible average size */
137             }
138             if (!(where_to = make_playpen(playpen, sb.st_size * 4)))
139                 errx(1, "unable to make playpen for %lld bytes", (long long)sb.st_size * 4);
140             /* Since we can call ourselves recursively, keep notes on where we came from */
141             if (!getenv("_TOP"))
142                 setenv("_TOP", where_to, 1);
143             if (unpack(pkg_fullname, extract)) {
144                 warnx(
145         "unable to extract table of contents file from '%s' - not a package?",
146                 pkg_fullname);
147                 goto bomb;
148             }
149             cfile = fopen(CONTENTS_FNAME, "r");
150             if (!cfile) {
151                 warnx(
152         "unable to open table of contents file '%s' - not a package?",
153                 CONTENTS_FNAME);
154                 goto bomb;
155             }
156             read_plist(&Plist, cfile);
157             fclose(cfile);
158
159             /* Extract directly rather than moving?  Oh goodie! */
160             if (find_plist_option(&Plist, "extract-in-place")) {
161                 if (Verbose)
162                     printf("Doing in-place extraction for %s\n", pkg_fullname);
163                 p = find_plist(&Plist, PLIST_CWD);
164                 if (p) {
165                     if (!isdir(p->name) && !Fake) {
166                         if (Verbose)
167                             printf("Desired prefix of %s does not exist, creating..\n", p->name);
168                         vsystem("/bin/mkdir -p %s", p->name);
169                         if (chdir(p->name) == -1) {
170                             warn("unable to change directory to '%s'", p->name);
171                             goto bomb;
172                         }
173                     }
174                     where_to = p->name;
175                     inPlace = 1;
176                 }
177                 else {
178                     warnx(
179                 "no prefix specified in '%s' - this is a bad package!",
180                         pkg_fullname);
181                     goto bomb;
182                 }
183             }
184
185             /*
186              * Apply a crude heuristic to see how much space the package will
187              * take up once it's unpacked.  I've noticed that most packages
188              * compress an average of 75%, so multiply by 4 for good measure.
189              */
190
191             if (!extract && !inPlace && min_free(playpen) < sb.st_size * 4) {
192                 warnx("projected size of %lld exceeds available free space.\n"
193 "Please set your PKG_TMPDIR variable to point to a location with more\n"
194                        "free space and try again", (long long)sb.st_size * 4);
195                 warnx("not extracting %s\ninto %s, sorry!",
196                         pkg_fullname, where_to);
197                 goto bomb;
198             }
199
200             /* If this is a direct extract and we didn't want it, stop now */
201             if (inPlace && Fake)
202                 goto success;
203
204             /* Finally unpack the whole mess.  If extract is null we
205                already + did so so don't bother doing it again. */
206             if (extract && unpack(pkg_fullname, NULL)) {
207                 warnx("unable to extract '%s'!", pkg_fullname);
208                 goto bomb;
209             }
210         }
211
212         /* Check for sanity and dependencies */
213         if (sanity_check(pkg))
214             goto bomb;
215
216         /* If we're running in MASTER mode, just output the plist and return */
217         if (AddMode == MASTER) {
218             printf("%s\n", where_playpen());
219             write_plist(&Plist, stdout);
220             return 0;
221         }
222     }
223
224     /*
225      * If we have a prefix, delete the first one we see and add this
226      * one in place of it.
227      */
228     if (Prefix) {
229         delete_plist(&Plist, FALSE, PLIST_CWD, NULL);
230         add_plist_top(&Plist, PLIST_CWD, Prefix);
231     }
232
233     setenv(PKG_PREFIX_VNAME, (p = find_plist(&Plist, PLIST_CWD)) ? p->name : ".", 1);
234     /* Protect against old packages with bogus @name and origin fields */
235     if (Plist.name == NULL)
236         Plist.name = "anonymous";
237     if (Plist.origin == NULL)
238         Plist.origin = "anonymous/anonymous";
239
240     /*
241      * See if we're already registered either with the same name (the same
242      * version) or some other version with the same origin.
243      */
244     if ((isinstalledpkg(Plist.name) > 0 ||
245          matchbyorigin(Plist.origin, NULL) != NULL) && !Force) {
246         warnx("package '%s' or its older version already installed%s",
247               Plist.name, FailOnAlreadyInstalled ? "" : " (ignored)");
248         code = FailOnAlreadyInstalled != FALSE;
249         goto success;   /* close enough for government work */
250     }
251
252     /* Now check the packing list for conflicts */
253     if (!IgnoreDeps){
254     for (p = Plist.head; p != NULL; p = p->next) {
255         if (p->type == PLIST_CONFLICTS) {
256             int i;
257             conflict[0] = strdup(p->name);
258             conflict[1] = NULL;
259             matched = matchinstalled(MATCH_GLOB, conflict, &errcode);
260             free(conflict[0]);
261             if (errcode == 0 && matched != NULL)
262                 for (i = 0; matched[i] != NULL; i++)
263                     if (isinstalledpkg(matched[i]) > 0) {
264                         warnx("package '%s' conflicts with %s", Plist.name,
265                                 matched[i]);
266                         conflictsfound = 1;
267                     }
268
269             continue;
270         }
271     }
272     if(conflictsfound) {
273         if(!Force) {
274             warnx("please use pkg_delete first to remove conflicting package(s) or -f to force installation");
275             code = 1;
276             goto bomb;
277         } else
278             warnx("-f specified; proceeding anyway");
279     }
280
281 #if ENSURE_THAT_ALL_REQUIREMENTS_ARE_MET
282     /*
283      * Before attempting to do the slave mode bit, ensure that we've
284      * downloaded & processed everything we need.
285      * It's possible that we haven't already installed all of our
286      * dependencies if the dependency list was misgenerated due to
287      * other dynamic dependencies or if a dependency was added to a
288      * package without all REQUIRED_BY packages being regenerated.
289      */
290     for (p = pkg ? Plist.head : NULL; p; p = p->next) {
291         const char *ext;
292         char *deporigin;
293
294         if (p->type != PLIST_PKGDEP)
295             continue;
296         deporigin = (p->next->type == PLIST_DEPORIGIN) ? p->next->name : NULL;
297
298         if (isinstalledpkg(p->name) <= 0 &&
299             !(deporigin != NULL && matchbyorigin(deporigin, NULL) != NULL)) {
300             char subpkg[FILENAME_MAX], *sep;
301
302             strlcpy(subpkg, pkg, sizeof subpkg);
303             if ((sep = strrchr(subpkg, '/')) != NULL) {
304                 *sep = '\0';
305                 if ((sep = strrchr(subpkg, '/')) != NULL) {
306                     *sep = '\0';
307                     strlcat(subpkg, "/All/", sizeof subpkg);
308                     strlcat(subpkg, p->name, sizeof subpkg);
309                     if ((ext = strrchr(pkg, '.')) == NULL)
310                         ext = ".tbz";
311                     strlcat(subpkg, ext, sizeof subpkg);
312                     pkg_do(subpkg);
313                 }
314             }
315         }
316     }
317 #endif
318
319     /* Now check the packing list for dependencies */
320     for (p = Plist.head; p ; p = p->next) {
321         char *deporigin;
322
323         if (p->type != PLIST_PKGDEP)
324             continue;
325         deporigin = (p->next->type == PLIST_DEPORIGIN) ? p->next->name : NULL;
326         if (Verbose) {
327             printf("Package '%s' depends on '%s'", Plist.name, p->name);
328             if (deporigin != NULL)
329                 printf(" with '%s' origin", deporigin);
330             printf(".\n");
331         }
332         if (isinstalledpkg(p->name) <= 0 &&
333             !(deporigin != NULL && matchbyorigin(deporigin, NULL) != NULL)) {
334             char path[FILENAME_MAX];
335             const char *cp = NULL;
336
337             if (!Fake) {
338                 char prefixArg[2 + MAXPATHLEN]; /* "-P" + Prefix */
339                 if (PrefixRecursive) {
340                     strlcpy(prefixArg, "-P", sizeof(prefixArg));
341                     strlcat(prefixArg, Prefix, sizeof(prefixArg));
342                 }
343                 if (!isURL(pkg) && !getenv("PKG_ADD_BASE")) {
344                     const char *ext;
345
346                     ext = strrchr(pkg_fullname, '.');
347                     if (ext == NULL)
348                         ext = ".tbz";
349                     snprintf(path, FILENAME_MAX, "%s/%s%s", getenv("_TOP"), p->name, ext);
350                     if (fexists(path))
351                         cp = path;
352                     else
353                         cp = fileFindByPath(pkg, p->name);
354                     if (cp) {
355                         if (Verbose)
356                             printf("Loading it from %s.\n", cp);
357                         if (vsystem("%s %s %s '%s'", PkgAddCmd, Verbose ? "-v " : "", PrefixRecursive ? prefixArg : "", cp)) {
358                             warnx("autoload of dependency '%s' failed%s",
359                                 cp, Force ? " (proceeding anyway)" : "!");
360                             if (!Force)
361                                 ++code;
362                         }
363                     }
364                     else {
365                         warnx("could not find package %s %s",
366                               p->name, Force ? " (proceeding anyway)" : "!");
367                         if (!Force)
368                             ++code;
369                     }
370                 }
371                 else if ((cp = fileGetURL(pkg, p->name, KeepPackage)) != NULL) {
372                     if (Verbose)
373                         printf("Finished loading %s via a URL\n", p->name);
374                     if (!fexists("+CONTENTS")) {
375                         warnx("autoloaded package %s has no +CONTENTS file?",
376                                 p->name);
377                         if (!Force)
378                             ++code;
379                     }
380                     else if (vsystem("(pwd; /bin/cat +CONTENTS) | %s %s %s %s -S", PkgAddCmd, Verbose ? "-v" : "", PrefixRecursive ? prefixArg : "", KeepPackage ? "-K" : "")) {
381                         warnx("pkg_add of dependency '%s' failed%s",
382                                 p->name, Force ? " (proceeding anyway)" : "!");
383                         if (!Force)
384                             ++code;
385                     }
386                     else if (Verbose)
387                         printf("\t'%s' loaded successfully.\n", p->name);
388                     /* Nuke the temporary playpen */
389                     leave_playpen();
390                 }
391             }
392             else {
393                 if (Verbose)
394                     printf("and was not found%s.\n", Force ? " (proceeding anyway)" : "");
395                 else
396                     printf("Package dependency %s for %s not found%s\n", p->name, pkg,
397                            Force ? " (proceeding anyway)" : "!");
398                 if (!Force)
399                     ++code;
400             }
401         }
402         else if (Verbose)
403             printf(" - already installed.\n");
404     }
405     } /* if (!IgnoreDeps) */
406
407     if (code != 0)
408         goto bomb;
409
410     /* Look for the requirements file */
411     if (fexists(REQUIRE_FNAME)) {
412         vsystem("/bin/chmod +x %s", REQUIRE_FNAME);     /* be sure */
413         if (Verbose)
414             printf("Running requirements file first for %s..\n", Plist.name);
415         if (!Fake && vsystem("./%s %s INSTALL", REQUIRE_FNAME, Plist.name)) {
416             warnx("package %s fails requirements %s", pkg_fullname,
417                    Force ? "installing anyway" : "- not installed");
418             if (!Force) {
419                 code = 1;
420                 goto success;   /* close enough for government work */
421             }
422         }
423     }
424
425     /*
426      * Test whether to use the old method of passing tokens to installation
427      * scripts, and set appropriate variables..
428      */
429
430     if (fexists(POST_INSTALL_FNAME)) {
431         new_m = 1;
432         sprintf(post_script, "%s", POST_INSTALL_FNAME);
433         pre_arg[0] = '\0';
434         post_arg[0] = '\0';
435     } else {
436         if (fexists(INSTALL_FNAME)) {
437             sprintf(post_script, "%s", INSTALL_FNAME);
438             sprintf(pre_arg, "PRE-INSTALL");
439             sprintf(post_arg, "POST-INSTALL");
440         }
441     }
442
443     /* If we're really installing, and have an installation file, run it */
444     if (!NoInstall && fexists(pre_script)) {
445         vsystem("/bin/chmod +x %s", pre_script);        /* make sure */
446         if (Verbose)
447             printf("Running pre-install for %s..\n", Plist.name);
448         if (!Fake && vsystem("./%s %s %s", pre_script, Plist.name, pre_arg)) {
449             warnx("install script returned error status");
450             unlink(pre_script);
451             code = 1;
452             goto success;               /* nothing to uninstall yet */
453         }
454     }
455
456     /* Now finally extract the entire show if we're not going direct */
457     if (!inPlace && !Fake)
458         extract_plist(".", &Plist);
459
460     if (!Fake && fexists(MTREE_FNAME)) {
461         if (Verbose)
462             printf("Running mtree for %s..\n", Plist.name);
463         p = find_plist(&Plist, PLIST_CWD);
464         if (Verbose)
465             printf("mtree -U -f %s -d -e -p %s >%s\n", MTREE_FNAME, p ? p->name : "/", _PATH_DEVNULL);
466         if (!Fake) {
467             if (vsystem("/usr/sbin/mtree -U -f %s -d -e -p %s >%s", MTREE_FNAME, p ? p->name : "/", _PATH_DEVNULL))
468                 warnx("mtree returned a non-zero status - continuing");
469         }
470     }
471
472     /* Run the installation script one last time? */
473     if (!NoInstall && fexists(post_script)) {
474         vsystem("/bin/chmod +x %s", post_script);       /* make sure */
475         if (Verbose)
476             printf("Running post-install for %s..\n", Plist.name);
477         if (!Fake && vsystem("./%s %s %s", post_script, Plist.name, post_arg)) {
478             warnx("install script returned error status");
479             unlink(post_script);
480             code = 1;
481             goto fail;
482         }
483     }
484
485     /* Time to record the deed? */
486     if (!NoRecord && !Fake) {
487         char contents[FILENAME_MAX];
488         char **depnames = NULL, **deporigins = NULL, ***depmatches;
489         int i, dep_count = 0;
490         FILE *contfile;
491
492         if (getuid() != 0)
493             warnx("not running as root - trying to record install anyway");
494         sprintf(LogDir, "%s/%s", LOG_DIR, Plist.name);
495         zapLogDir = 1;
496         if (Verbose)
497             printf("Attempting to record package into %s..\n", LogDir);
498         if (make_hierarchy(LogDir)) {
499             warnx("can't record package into '%s', you're on your own!",
500                    LogDir);
501             bzero(LogDir, FILENAME_MAX);
502             code = 1;
503             goto success;       /* close enough for government work */
504         }
505         /* Make sure pkg_info can read the entry */
506         vsystem("/bin/chmod a+rx %s", LogDir);
507         move_file(".", DESC_FNAME, LogDir);
508         move_file(".", COMMENT_FNAME, LogDir);
509         if (fexists(INSTALL_FNAME))
510             move_file(".", INSTALL_FNAME, LogDir);
511         if (fexists(POST_INSTALL_FNAME))
512             move_file(".", POST_INSTALL_FNAME, LogDir);
513         if (fexists(DEINSTALL_FNAME))
514             move_file(".", DEINSTALL_FNAME, LogDir);
515         if (fexists(POST_DEINSTALL_FNAME))
516             move_file(".", POST_DEINSTALL_FNAME, LogDir);
517         if (fexists(REQUIRE_FNAME))
518             move_file(".", REQUIRE_FNAME, LogDir);
519         if (fexists(DISPLAY_FNAME))
520             move_file(".", DISPLAY_FNAME, LogDir);
521         if (fexists(MTREE_FNAME))
522             move_file(".", MTREE_FNAME, LogDir);
523         sprintf(contents, "%s/%s", LogDir, CONTENTS_FNAME);
524         contfile = fopen(contents, "w");
525         if (!contfile) {
526             warnx("can't open new contents file '%s'! can't register pkg",
527                 contents);
528             goto success; /* can't log, but still keep pkg */
529         }
530         write_plist(&Plist, contfile);
531         fclose(contfile);
532         for (p = Plist.head; p ; p = p->next) {
533             char *deporigin;
534
535             if (p->type != PLIST_PKGDEP)
536                 continue;
537             deporigin = (p->next->type == PLIST_DEPORIGIN) ? p->next->name :
538                                                              NULL;
539             if (Verbose) {
540                 printf("Trying to record dependency on package '%s'", p->name);
541                 if (deporigin != NULL)
542                     printf(" with '%s' origin", deporigin);
543                 printf(".\n");
544             }
545
546             if (deporigin) {
547                 /* Defer to origin lookup */
548                 depnames = realloc(depnames, (dep_count + 1) * sizeof(*depnames));
549                 depnames[dep_count] = p->name;
550                 deporigins = realloc(deporigins, (dep_count + 2) * sizeof(*deporigins));
551                 deporigins[dep_count] = deporigin;
552                 deporigins[dep_count + 1] = NULL;
553                 dep_count++;
554             } else {
555                /* No origin recorded, try to register on literal package name */
556                sprintf(contents, "%s/%s/%s", LOG_DIR, p->name,
557                      REQUIRED_BY_FNAME);
558                contfile = fopen(contents, "a");
559                if (!contfile) {
560                   warnx("can't open dependency file '%s'!\n"
561                         "dependency registration is incomplete", contents);
562                } else {
563                   fprintf(contfile, "%s\n", Plist.name);
564                   if (fclose(contfile) == EOF) {
565                      warnx("cannot properly close file %s", contents);
566                   }
567                }
568             }
569         }
570         if (dep_count > 0) {
571             depmatches = matchallbyorigin((const char **)deporigins, NULL);
572             free(deporigins);
573             if (!IgnoreDeps && depmatches) {
574                 for (i = 0; i < dep_count; i++) {
575                     if (depmatches[i]) {
576                         int j;
577                         char **tmp = depmatches[i];
578                         for (j = 0; tmp[j] != NULL; j++) {
579                             /* Origin looked up */
580                             sprintf(contents, "%s/%s/%s", LOG_DIR, tmp[j],
581                                 REQUIRED_BY_FNAME);
582                             if (depnames[i] && strcmp(depnames[i], tmp[j]) != 0)
583                                 warnx("warning: package '%s' requires '%s', but '%s' "
584                                     "is installed", Plist.name, depnames[i], tmp[j]);
585                             contfile = fopen(contents, "a");
586                             if (!contfile) {
587                                 warnx("can't open dependency file '%s'!\n"
588                                     "dependency registration is incomplete", contents);
589                             } else {
590                                 fprintf(contfile, "%s\n", Plist.name);
591                                 if (fclose(contfile) == EOF)
592                                     warnx("cannot properly close file %s", contents);
593                             }
594                         }
595                     } else if (depnames[i]) {
596                         /* No package present with this origin, try literal package name */
597                         sprintf(contents, "%s/%s/%s", LOG_DIR, depnames[i],
598                             REQUIRED_BY_FNAME);
599                         contfile = fopen(contents, "a");
600                         if (!contfile) {
601                             warnx("can't open dependency file '%s'!\n"
602                                 "dependency registration is incomplete", contents);
603                         } else {
604                             fprintf(contfile, "%s\n", Plist.name);
605                             if (fclose(contfile) == EOF) {
606                                 warnx("cannot properly close file %s", contents);
607                             }
608                         }
609                     }
610                 }
611             }
612         }
613         if (Verbose)
614             printf("Package %s registered in %s\n", Plist.name, LogDir);
615     }
616
617     if ((p = find_plist(&Plist, PLIST_DISPLAY)) != NULL) {
618         FILE *fp;
619         char buf[BUFSIZ];
620
621         snprintf(buf, sizeof buf, "%s/%s", LogDir, p->name);
622         fp = fopen(buf, "r");
623         if (fp) {
624             putc('\n', stdout);
625             while (fgets(buf, sizeof(buf), fp))
626                 fputs(buf, stdout);
627             putc('\n', stdout);
628             (void) fclose(fp);
629         } else {
630             if (!Fake) {
631                 warnx("cannot open %s as display file", buf);  
632             }
633         }
634     }
635
636     goto success;
637
638  bomb:
639     code = 1;
640     goto success;
641
642  fail:
643     /* Nuke the whole (installed) show, XXX but don't clean directories */
644     if (!Fake)
645         delete_package(FALSE, FALSE, &Plist);
646
647  success:
648     /* delete the packing list contents */
649     free_plist(&Plist);
650     leave_playpen();
651     return code;
652 }
653
654 static int
655 sanity_check(char *pkg)
656 {
657     int code = 0;
658
659     if (!fexists(CONTENTS_FNAME)) {
660         warnx("package %s has no CONTENTS file!", pkg);
661         code = 1;
662     }
663     else if (!fexists(COMMENT_FNAME)) {
664         warnx("package %s has no COMMENT file!", pkg);
665         code = 1;
666     }
667     else if (!fexists(DESC_FNAME)) {
668         warnx("package %s has no DESC file!", pkg);
669         code = 1;
670     }
671     return code;
672 }
673
674 void
675 cleanup(int sig)
676 {
677     static int in_cleanup = 0;
678
679     if (!in_cleanup) {
680         in_cleanup = 1;
681         if (sig)
682             printf("Signal %d received, cleaning up..\n", sig);
683         if (!Fake && zapLogDir && LogDir[0])
684             vsystem("%s -rf %s", REMOVE_CMD, LogDir);
685         while (leave_playpen())
686             ;
687     }
688     if (sig)
689         exit(1);
690 }