static void test_dpkg_arch_varbuf_archqual(void) { struct varbuf vb = VARBUF_INIT; varbuf_add_archqual(&vb, dpkg_arch_get(DPKG_ARCH_NONE)); varbuf_end_str(&vb); test_str(vb.buf, ==, ""); varbuf_reset(&vb); varbuf_add_archqual(&vb, dpkg_arch_get(DPKG_ARCH_EMPTY)); varbuf_end_str(&vb); test_str(vb.buf, ==, ""); varbuf_reset(&vb); varbuf_add_archqual(&vb, dpkg_arch_get(DPKG_ARCH_ALL)); varbuf_end_str(&vb); test_str(vb.buf, ==, ":all"); varbuf_reset(&vb); varbuf_add_archqual(&vb, dpkg_arch_get(DPKG_ARCH_WILDCARD)); varbuf_end_str(&vb); test_str(vb.buf, ==, ":any"); varbuf_reset(&vb); }
/** * Returns the path to the script inside the chroot. */ static const char * preexecscript(struct command *cmd) { const char *admindir = dpkg_db_get_dir(); size_t instdirl = strlen(instdir); if (*instdir) { if (strncmp(admindir, instdir, instdirl) != 0) ohshit(_("admindir must be inside instdir for dpkg to work properly")); if (setenv("DPKG_ADMINDIR", admindir + instdirl, 1) < 0) ohshite(_("unable to setenv for subprocesses")); if (chroot(instdir)) ohshite(_("failed to chroot to `%.250s'"),instdir); if (chdir("/")) ohshite(_("failed to chdir to `%.255s'"), "/"); } if (debug_has_flag(dbg_scripts)) { struct varbuf args = VARBUF_INIT; const char **argv = cmd->argv; while (*++argv) { varbuf_add_char(&args, ' '); varbuf_add_str(&args, *argv); } varbuf_end_str(&args); debug(dbg_scripts, "fork/exec %s (%s )", cmd->filename, args.buf); varbuf_destroy(&args); } if (!instdirl) return cmd->filename; assert(strlen(cmd->filename) >= instdirl); return cmd->filename + instdirl; }
bool find_command(const char *prog) { struct varbuf filename = VARBUF_INIT; struct stat stab; const char *path_list; const char *path, *path_end; size_t path_len; path_list = getenv("PATH"); if (!path_list) ohshit(_("PATH is not set")); for (path = path_list; path; path = path_end ? path_end + 1 : NULL) { path_end = strchr(path, ':'); path_len = path_end ? (size_t)(path_end - path) : strlen(path); varbuf_reset(&filename); varbuf_add_buf(&filename, path, path_len); if (path_len) varbuf_add_char(&filename, '/'); varbuf_add_str(&filename, prog); varbuf_end_str(&filename); if (stat(filename.buf, &stab) == 0 && (stab.st_mode & 0111)) { varbuf_destroy(&filename); return true; } } varbuf_destroy(&filename); return false; }
const char * varbuf_get_str(struct varbuf *v) { varbuf_end_str(v); return v->buf; }
/** * Verify that some programs can be found in the PATH. */ void checkpath(void) { static const char *const prog_list[] = { DEFAULTSHELL, RM, TAR, FIND, BACKEND, "ldconfig", #if WITH_START_STOP_DAEMON "start-stop-daemon", #endif NULL }; const char *const *prog; const char *path_list; struct varbuf filename = VARBUF_INIT; int warned= 0; path_list = getenv("PATH"); if (!path_list) ohshit(_("PATH is not set.")); for (prog = prog_list; *prog; prog++) { struct stat stab; const char *path, *path_end; size_t path_len; for (path = path_list; path; path = path_end ? path_end + 1 : NULL) { path_end = strchr(path, ':'); path_len = path_end ? (size_t)(path_end - path) : strlen(path); varbuf_reset(&filename); varbuf_add_buf(&filename, path, path_len); if (path_len) varbuf_add_char(&filename, '/'); varbuf_add_str(&filename, *prog); varbuf_end_str(&filename); if (stat(filename.buf, &stab) == 0 && (stab.st_mode & 0111)) break; } if (!path) { warning(_("'%s' not found in PATH or not executable."), *prog); warned++; } } varbuf_destroy(&filename); if (warned) forcibleerr(fc_badpath, P_("%d expected program not found in PATH or not executable.\n%s", "%d expected programs not found in PATH or not executable.\n%s", warned), warned, _("Note: root's PATH should usually contain " "/usr/local/sbin, /usr/sbin and /sbin.")); }
/** * Add a string representation of the package name to a varbuf. * * Works exactly like pkgbin_name() but acts on the varbuf instead of * returning a string. It NUL terminates the varbuf. * * @param vb The varbuf struct to modify. * @param pkg The package to consider. * @param pkgbin The binary package instance to consider. * @param pnaw When to display the architecture qualifier. */ void varbuf_add_pkgbin_name(struct varbuf *vb, const struct pkginfo *pkg, const struct pkgbin *pkgbin, enum pkg_name_arch_when pnaw) { varbuf_add_str(vb, pkg->set->name); if (pkgbin_name_needs_arch(pkgbin, pnaw)) varbuf_add_archqual(vb, pkgbin->arch); varbuf_end_str(vb); }
/* * Does cycle checking. Doesn't mind if pkg has no triggers pending - in * that case does nothing but fix up any stale awaiters. */ void trigproc(struct pkginfo *pkg) { static struct varbuf namesarg; struct trigpend *tp; struct pkginfo *gaveup; debug(dbg_triggers, "trigproc %s", pkg_describe(pkg, pdo_foreign)); if (pkg->clientdata->trigprocdeferred) pkg->clientdata->trigprocdeferred->pkg = NULL; pkg->clientdata->trigprocdeferred = NULL; if (pkg->trigpend_head) { assert(pkg->status == stat_triggerspending || pkg->status == stat_triggersawaited); gaveup = check_trigger_cycle(pkg); if (gaveup == pkg) return; printf(_("Processing triggers for %s ...\n"), pkg_describe(pkg, pdo_foreign)); log_action("trigproc", pkg); varbuf_reset(&namesarg); for (tp = pkg->trigpend_head; tp; tp = tp->next) { varbuf_add_char(&namesarg, ' '); varbuf_add_str(&namesarg, tp->name); } varbuf_end_str(&namesarg); /* Setting the status to half-configured * causes modstatdb_note to clear pending triggers. */ pkg->status = stat_halfconfigured; modstatdb_note(pkg); if (!f_noact) { sincenothing = 0; maintainer_script_postinst(pkg, "triggered", namesarg.buf + 1, NULL); } /* This is to cope if the package triggers itself: */ pkg->status = pkg->trigaw.head ? stat_triggersawaited : pkg->trigpend_head ? stat_triggerspending : stat_installed; post_postinst_tasks_core(pkg); } else { /* In other branch is done by modstatdb_note. */ trig_clear_awaiters(pkg); } }
static void file_init(struct file *f, const char *filename) { struct varbuf usefilename = VARBUF_INIT; varbuf_add_str(&usefilename, instdir); varbuf_add_str(&usefilename, filename); varbuf_end_str(&usefilename); f->name = varbuf_detach(&usefilename); f->stat_state = FILE_STAT_INVALID; }
/** * Parse the field and value into the package being constructed. */ static void pkg_parse_field(struct parsedb_state *ps, struct field_state *fs, void *parse_obj) { struct pkg_parse_object *pkg_obj = parse_obj; const struct nickname *nick; const struct fieldinfo *fip; int *ip; for (nick = nicknames; nick->nick; nick++) if (strncasecmp(nick->nick, fs->fieldstart, fs->fieldlen) == 0 && nick->nick[fs->fieldlen] == '\0') break; if (nick->nick) { fs->fieldstart = nick->canon; fs->fieldlen = strlen(fs->fieldstart); } for (fip = fieldinfos, ip = fs->fieldencountered; fip->name; fip++, ip++) if (strncasecmp(fip->name, fs->fieldstart, fs->fieldlen) == 0) break; if (fip->name) { if ((*ip)++) parse_error(ps, _("duplicate value for `%s' field"), fip->name); varbuf_reset(&fs->value); varbuf_add_buf(&fs->value, fs->valuestart, fs->valuelen); varbuf_end_str(&fs->value); fip->rcall(pkg_obj->pkg, pkg_obj->pkgbin, ps, fs->value.buf, fip); } else { struct arbitraryfield *arp, **larpp; if (fs->fieldlen < 2) parse_error(ps, _("user-defined field name `%.*s' too short"), fs->fieldlen, fs->fieldstart); larpp = &pkg_obj->pkgbin->arbs; while ((arp = *larpp) != NULL) { if (!strncasecmp(arp->name, fs->fieldstart, fs->fieldlen)) parse_error(ps, _("duplicate value for user-defined field `%.*s'"), fs->fieldlen, fs->fieldstart); larpp = &arp->next; } arp = nfmalloc(sizeof(struct arbitraryfield)); arp->name = nfstrnsave(fs->fieldstart, fs->fieldlen); arp->value = nfstrnsave(fs->valuestart, fs->valuelen); arp->next = NULL; *larpp = arp; } }
/* * Does cycle checking. Doesn't mind if pkg has no triggers pending - in * that case does nothing but fix up any stale awaiters. */ void trigproc(struct pkginfo *pkg) { static struct varbuf namesarg; struct trigpend *tp; struct pkginfo *gaveup; debug(dbg_triggers, "trigproc %s", pkg_name(pkg, pnaw_always)); if (pkg->clientdata->trigprocdeferred) pkg->clientdata->trigprocdeferred->pkg = NULL; pkg->clientdata->trigprocdeferred = NULL; if (pkg->trigpend_head) { assert(pkg->status == stat_triggerspending || pkg->status == stat_triggersawaited); gaveup = check_trigger_cycle(pkg); if (gaveup == pkg) return; printf(_("Processing triggers for %s (%s) ...\n"), pkg_name(pkg, pnaw_nonambig), versiondescribe(&pkg->installed.version, vdew_nonambig)); log_action("trigproc", pkg, &pkg->installed); varbuf_reset(&namesarg); for (tp = pkg->trigpend_head; tp; tp = tp->next) { varbuf_add_char(&namesarg, ' '); varbuf_add_str(&namesarg, tp->name); } varbuf_end_str(&namesarg); /* Setting the status to half-configured * causes modstatdb_note to clear pending triggers. */ pkg_set_status(pkg, stat_halfconfigured); modstatdb_note(pkg); if (!f_noact) { sincenothing = 0; maintscript_postinst(pkg, "triggered", namesarg.buf + 1, NULL); } post_postinst_tasks(pkg, stat_installed); } else { /* In other branch is done by modstatdb_note(), from inside * post_postinst_tasks(). */ trig_clear_awaiters(pkg); } }
static void breaks_check_one(struct varbuf *aemsgs, enum dep_check *ok, struct deppossi *breaks, struct pkginfo *broken, struct pkginfo *breaker, struct deppossi *virtbroken) { struct varbuf depmsg = VARBUF_INIT; debug(dbg_depcondetail, " checking breaker %s virtbroken %s", pkg_name(breaker, pnaw_always), virtbroken ? virtbroken->ed->name : "<none>"); if (breaker->status == PKG_STAT_NOTINSTALLED || breaker->status == PKG_STAT_CONFIGFILES) return; if (broken == breaker) return; if (!versionsatisfied(&broken->installed, breaks)) return; /* The test below can only trigger if dep_breaks start having * arch qualifiers different from “any”. */ if (!archsatisfied(&broken->installed, breaks)) return; if (ignore_depends(breaker)) return; if (virtbroken && ignore_depends(&virtbroken->ed->pkg)) return; if (virtbroken && !pkg_virtual_deppossi_satisfied(breaks, virtbroken)) return; varbufdependency(&depmsg, breaks->up); varbuf_end_str(&depmsg); varbuf_printf(aemsgs, _(" %s (%s) breaks %s and is %s.\n"), pkg_name(breaker, pnaw_nonambig), versiondescribe(&breaker->installed.version, vdew_nonambig), depmsg.buf, gettext(statusstrings[breaker->status])); varbuf_destroy(&depmsg); if (virtbroken) { varbuf_printf(aemsgs, _(" %s (%s) provides %s.\n"), pkg_name(broken, pnaw_nonambig), versiondescribe(&broken->installed.version, vdew_nonambig), virtbroken->ed->name); } else if (breaks->verrel != DPKG_RELATION_NONE) { varbuf_printf(aemsgs, _(" Version of %s to be configured is %s.\n"), pkg_name(broken, pnaw_nonambig), versiondescribe(&broken->installed.version, vdew_nonambig)); if (in_force(FORCE_DEPENDS_VERSION)) return; } if (force_breaks(breaks)) return; *ok = DEP_CHECK_HALT; }
/* * If mask is nonzero, will not write any file whose filenamenode * has any flag bits set in mask. */ void write_filelist_except(struct pkginfo *pkg, struct pkgbin *pkgbin, struct fileinlist *list, enum fnnflags mask) { static struct varbuf newvb; const char *listfile; FILE *file; listfile = pkgadminfile(pkg, pkgbin, LISTFILE); varbuf_reset(&newvb); varbuf_add_str(&newvb, listfile); varbuf_add_str(&newvb, NEWDBEXT); varbuf_end_str(&newvb); file= fopen(newvb.buf,"w+"); if (!file) ohshite(_("unable to create updated files list file for package %s"), pkg_describe(pkg, pdo_foreign)); push_cleanup(cu_closestream, ehflag_bombout, NULL, 0, 1, (void *)file); while (list) { if (!(mask && (list->namenode->flags & mask))) { fputs(list->namenode->name,file); putc('\n',file); } list= list->next; } if (ferror(file)) ohshite(_("failed to write to updated files list file for package %s"), pkg_describe(pkg, pdo_foreign)); if (fflush(file)) ohshite(_("failed to flush updated files list file for package %s"), pkg_describe(pkg, pdo_foreign)); if (fsync(fileno(file))) ohshite(_("failed to sync updated files list file for package %s"), pkg_describe(pkg, pdo_foreign)); pop_cleanup(ehflag_normaltidy); /* file = fopen() */ if (fclose(file)) ohshite(_("failed to close updated files list file for package %s"), pkg_describe(pkg, pdo_foreign)); if (rename(newvb.buf, listfile)) ohshite(_("failed to install updated files list file for package %s"), pkg_describe(pkg, pdo_foreign)); dir_sync_path(pkgadmindir()); note_must_reread_files_inpackage(pkg); }
static void trk_explicit_start(const char *trig) { trk_explicit_activate_done(); varbuf_reset(&trk_explicit_fn); varbuf_add_str(&trk_explicit_fn, triggersdir); varbuf_add_str(&trk_explicit_fn, trig); varbuf_end_str(&trk_explicit_fn); trk_explicit_f = fopen(trk_explicit_fn.buf, "r"); if (!trk_explicit_f) { if (errno != ENOENT) ohshite(_("failed to open trigger interest list file `%.250s'"), trk_explicit_fn.buf); } }
static void breaks_check_one(struct varbuf *aemsgs, enum dep_check *ok, struct deppossi *breaks, struct pkginfo *broken, struct pkginfo *breaker, struct pkgset *virtbroken) { struct varbuf depmsg = VARBUF_INIT; debug(dbg_depcondetail, " checking breaker %s virtbroken %s", pkg_name(breaker, pnaw_always), virtbroken ? virtbroken->name : "<none>"); if (breaker->status == stat_notinstalled || breaker->status == stat_configfiles) return; if (broken == breaker) return; if (!versionsatisfied(&broken->installed, breaks)) return; /* The test below can only trigger if dep_breaks start having * arch qualifiers different from “any”. */ if (!archsatisfied(&broken->installed, breaks)) return; if (ignore_depends(breaker)) return; if (virtbroken && ignore_depends(&virtbroken->pkg)) return; varbufdependency(&depmsg, breaks->up); varbuf_end_str(&depmsg); varbuf_printf(aemsgs, _(" %s (%s) breaks %s and is %s.\n"), pkg_name(breaker, pnaw_nonambig), versiondescribe(&breaker->installed.version, vdew_nonambig), depmsg.buf, gettext(statusstrings[breaker->status])); varbuf_destroy(&depmsg); if (virtbroken) { varbuf_printf(aemsgs, _(" %s (%s) provides %s.\n"), pkg_name(broken, pnaw_nonambig), versiondescribe(&broken->installed.version, vdew_nonambig), virtbroken->name); } else if (breaks->verrel != dpkg_relation_none) { varbuf_printf(aemsgs, _(" Version of %s to be configured is %s.\n"), pkg_name(broken, pnaw_nonambig), versiondescribe(&broken->installed.version, vdew_nonambig)); if (fc_dependsversion) return; } if (force_breaks(breaks)) return; *ok = dep_check_halt; }
static void verify_package(struct pkginfo *pkg) { struct fsys_namenode_list *file; struct varbuf filename = VARBUF_INIT; ensure_packagefiles_available(pkg); parse_filehash(pkg, &pkg->installed); pkg_conffiles_mark_old(pkg); for (file = pkg->files; file; file = file->next) { struct verify_checks checks; struct fsys_namenode *fnn; char hash[MD5HASHLEN + 1]; int failures = 0; fnn = namenodetouse(file->namenode, pkg, &pkg->installed); if (strcmp(fnn->newhash, EMPTYHASHFLAG) == 0) { if (fnn->oldhash == NULL) continue; else fnn->newhash = fnn->oldhash; } varbuf_reset(&filename); varbuf_add_str(&filename, instdir); varbuf_add_str(&filename, fnn->name); varbuf_end_str(&filename); memset(&checks, 0, sizeof(checks)); md5hash(pkg, hash, filename.buf); if (strcmp(hash, fnn->newhash) != 0) { checks.md5sum = VERIFY_FAIL; failures++; } if (failures) verify_output(fnn, &checks); } varbuf_destroy(&filename); }
const char * pkgadminfile(struct pkginfo *pkg, struct pkgbin *pkgbin, const char *filetype) { static struct varbuf vb; varbuf_reset(&vb); varbuf_add_str(&vb, infodir); varbuf_add_char(&vb, '/'); varbuf_add_str(&vb, pkg->set->name); if (pkgbin->multiarch == multiarch_same && pkg_infodb_format() >= 1) { varbuf_add_char(&vb, ':'); varbuf_add_str(&vb, pkgbin->arch->name); } varbuf_add_char(&vb, '.'); varbuf_add_str(&vb, filetype); varbuf_end_str(&vb); return vb.buf; }
const char *versiondescribe (const struct dpkg_version *version, enum versiondisplayepochwhen vdew) { static struct varbuf bufs[10]; static int bufnum=0; struct varbuf *vb; if (!dpkg_version_is_informative(version)) return C_("version", "<none>"); vb= &bufs[bufnum]; bufnum++; if (bufnum == 10) bufnum= 0; varbuf_reset(vb); varbufversion(vb,version,vdew); varbuf_end_str(vb); return vb->buf; }
char * get_force_string(void) { const struct forceinfo *fip; struct varbuf vb = VARBUF_INIT; for (fip = forceinfos; fip->name; fip++) { if ((enum force_flags)fip->flag == FORCE_ALL || (fip->flag & force_mask) != fip->flag || !in_force(fip->flag)) continue; if (vb.used) varbuf_add_char(&vb, ','); varbuf_add_str(&vb, fip->name); } varbuf_end_str(&vb); return varbuf_detach(&vb); }
static char * deb_field(const char *filename, const char *field) { pid_t pid; int p[2]; struct varbuf buf = VARBUF_INIT; char *end; m_pipe(p); pid = subproc_fork(); if (pid == 0) { /* Child writes to pipe. */ m_dup2(p[1], 1); close(p[0]); close(p[1]); execlp(BACKEND, BACKEND, "--field", filename, field, NULL); ohshite(_("unable to execute %s (%s)"), _("package field value extraction"), BACKEND); } close(p[1]); /* Parant reads from pipe. */ varbuf_reset(&buf); fd_vbuf_copy(p[0], &buf, -1, _("package field value extraction")); varbuf_end_str(&buf); close(p[0]); subproc_wait_check(pid, _("package field value extraction"), PROCPIPE); /* Trim down trailing junk. */ for (end = buf.buf + strlen(buf.buf) - 1; end - buf.buf >= 1; end--) if (isspace(*end)) *end = '\0'; else break; return varbuf_detach(&buf); }
static void test_varbuf_end_str(void) { struct varbuf vb; varbuf_init(&vb, 10); varbuf_add_buf(&vb, "1234567890X", 11); test_pass(vb.used == 11); test_pass(vb.size >= vb.used); test_mem(vb.buf, ==, "1234567890X", 11); varbuf_trunc(&vb, 10); varbuf_end_str(&vb); test_pass(vb.used == 10); test_pass(vb.size >= vb.used + 1); test_pass(vb.buf[10] == '\0'); test_str(vb.buf, ==, "1234567890"); varbuf_destroy(&vb); }
/** * Return a string representation of the package name. * * The returned string must not be freed, and it's permanently allocated so * can be used as long as the non-freeing memory pool has not been freed. * * The pnaw parameter should be one of pnaw_never (never print arch), * pnaw_foreign (print arch for foreign packages only), pnaw_nonambig (print * arch for non ambiguous cases) or pnaw_always (always print arch), * * @param pkg The package to consider. * @param pkgbin The binary package instance to consider. * @param pnaw When to display the architecture qualifier. * * @return The string representation. */ const char * pkgbin_name(struct pkginfo *pkg, struct pkgbin *pkgbin, enum pkg_name_arch_when pnaw) { if (!pkgbin_name_needs_arch(pkgbin, pnaw)) return pkg->set->name; /* Cache the package name representation, for later reuse. */ if (pkgbin->pkgname_archqual == NULL) { struct varbuf vb = VARBUF_INIT; varbuf_add_str(&vb, pkg->set->name); varbuf_add_archqual(&vb, pkgbin->arch); varbuf_end_str(&vb); pkgbin->pkgname_archqual = nfstrsave(vb.buf); varbuf_destroy(&vb); } return pkgbin->pkgname_archqual; }
const char * pkg_infodb_get_file(const struct pkginfo *pkg, const struct pkgbin *pkgbin, const char *filetype) { static struct varbuf vb; enum pkg_infodb_format format; /* Make sure to always read and verify the format version. */ format = pkg_infodb_get_format(); varbuf_reset(&vb); varbuf_add_str(&vb, pkg_infodb_get_dir()); varbuf_add_char(&vb, '/'); varbuf_add_str(&vb, pkg->set->name); if (pkgbin->multiarch == PKG_MULTIARCH_SAME && format == PKG_INFODB_FORMAT_MULTIARCH) varbuf_add_archqual(&vb, pkgbin->arch); varbuf_add_char(&vb, '.'); varbuf_add_str(&vb, filetype); varbuf_end_str(&vb); return vb.buf; }
void describedepcon(struct varbuf *addto, struct dependency *dep) { const char *fmt; struct varbuf depstr = VARBUF_INIT; switch (dep->type) { case dep_depends: fmt = _("%s depends on %s"); break; case dep_predepends: fmt = _("%s pre-depends on %s"); break; case dep_recommends: fmt = _("%s recommends %s"); break; case dep_suggests: fmt = _("%s suggests %s"); break; case dep_breaks: fmt = _("%s breaks %s"); break; case dep_conflicts: fmt = _("%s conflicts with %s"); break; case dep_enhances: fmt = _("%s enhances %s"); break; default: internerr("unknown deptype '%d'", dep->type); } varbufdependency(&depstr, dep); varbuf_end_str(&depstr); varbuf_printf(addto, fmt, pkg_name(dep->up, pnaw_nonambig), depstr.buf); varbuf_destroy(&depstr); }
void process_archive(const char *filename) { static const struct tar_operations tf = { .read = tarfileread, .extract_file = tarobject, .link = tarobject, .symlink = tarobject, .mkdir = tarobject, .mknod = tarobject, }; /* These need to be static so that we can pass their addresses to * push_cleanup as arguments to the cu_xxx routines; if an error occurs * we unwind the stack before processing the cleanup list, and these * variables had better still exist ... */ static int p1[2]; static char *cidir = NULL; static struct fileinlist *newconffiles, *newfileslist; static enum pkgstatus oldversionstatus; static struct varbuf depprobwhy; static struct tarcontext tc; int r, i; pid_t pid; struct pkgiterator *it; struct pkginfo *pkg, *otherpkg; char *cidirrest, *p; char conffilenamebuf[MAXCONFFILENAME]; char *psize; const char *pfilename; struct fileinlist *newconff, **newconffileslastp; struct fileinlist *cfile; struct reversefilelistiter rlistit; struct conffile *searchconff, **iconffileslastp, *newiconff; struct dependency *dsearch, *newdeplist, **newdeplistlastp; struct dependency *newdep, *dep, *providecheck; struct deppossi *psearch, **newpossilastp, *possi, *newpossi, *pdep; FILE *conff; struct filenamenode *namenode; struct stat stab, oldfs; struct pkg_deconf_list *deconpil, *deconpiltemp; struct pkginfo *fixbytrigaw; cleanup_pkg_failed= cleanup_conflictor_failed= 0; pfilename = summarize_filename(filename); if (stat(filename,&stab)) ohshite(_("cannot access archive")); /* We can't ‘tentatively-reassemble’ packages. */ if (!f_noact) { if (!deb_reassemble(&filename, &pfilename)) return; } /* Verify the package. */ if (!f_nodebsig) deb_verify(filename); /* Get the control information directory. */ cidir = get_control_dir(cidir); cidirrest = cidir + strlen(cidir); push_cleanup(cu_cidir, ~0, NULL, 0, 2, (void *)cidir, (void *)cidirrest); pid = subproc_fork(); if (pid == 0) { cidirrest[-1] = '\0'; execlp(BACKEND, BACKEND, "--control", filename, cidir, NULL); ohshite(_("unable to execute %s (%s)"), _("package control information extraction"), BACKEND); } subproc_wait_check(pid, BACKEND " --control", 0); /* We want to guarantee the extracted files are on the disk, so that the * subsequent renames to the info database do not end up with old or zero * length files in case of a system crash. As neither dpkg-deb nor tar do * explicit fsync()s, we have to do them here. * XXX: This could be avoided by switching to an internal tar extractor. */ dir_sync_contents(cidir); strcpy(cidirrest,CONTROLFILE); parsedb(cidir, pdb_parse_binary | pdb_ignorefiles | parsedb_force_flags(), &pkg); if (!pkg->files) { pkg->files= nfmalloc(sizeof(struct filedetails)); pkg->files->next = NULL; pkg->files->name = pkg->files->msdosname = pkg->files->md5sum = NULL; } /* Always nfmalloc. Otherwise, we may overwrite some other field (like * md5sum). */ psize = nfmalloc(30); sprintf(psize, "%jd", (intmax_t)stab.st_size); pkg->files->size = psize; if (cipaction->arg_int == act_avail) { printf(_("Recorded info about %s from %s.\n"), pkgbin_name(pkg, &pkg->available, pnaw_nonambig), pfilename); pop_cleanup(ehflag_normaltidy); return; } if (pkg->available.arch->type != arch_all && pkg->available.arch->type != arch_native) forcibleerr(fc_architecture, _("package architecture (%s) does not match system (%s)"), pkg->available.arch->name, dpkg_arch_get(arch_native)->name); for (deconpil= deconfigure; deconpil; deconpil= deconpiltemp) { deconpiltemp= deconpil->next; free(deconpil); } deconfigure = NULL; clear_istobes(); if (!wanttoinstall(pkg)) { pop_cleanup(ehflag_normaltidy); return; } /* Check if anything is installed that we conflict with, or not installed * that we need. */ pkg->clientdata->istobe= itb_installnew; for (dsearch= pkg->available.depends; dsearch; dsearch= dsearch->next) { switch (dsearch->type) { case dep_conflicts: /* Look for things we conflict with. */ check_conflict(dsearch, pkg, pfilename); break; case dep_breaks: /* Look for things we break. */ check_breaks(dsearch, pkg, pfilename); break; case dep_provides: /* Look for things that conflict with what we provide. */ for (psearch = dsearch->list->ed->depended.installed; psearch; psearch = psearch->rev_next) { if (psearch->up->type != dep_conflicts) continue; check_conflict(psearch->up, pkg, pfilename); } break; case dep_suggests: case dep_recommends: case dep_depends: case dep_replaces: case dep_enhances: /* Ignore these here. */ break; case dep_predepends: if (!depisok(dsearch, &depprobwhy, NULL, &fixbytrigaw, true)) { if (fixbytrigaw) { while (fixbytrigaw->trigaw.head) trigproc(fixbytrigaw->trigaw.head->pend); } else { varbuf_end_str(&depprobwhy); fprintf(stderr, _("dpkg: regarding %s containing %s, pre-dependency problem:\n%s"), pfilename, pkgbin_name(pkg, &pkg->available, pnaw_nonambig), depprobwhy.buf); if (!force_depends(dsearch->list)) ohshit(_("pre-dependency problem - not installing %.250s"), pkgbin_name(pkg, &pkg->available, pnaw_nonambig)); warning(_("ignoring pre-dependency problem!")); } } } } /* Look for things that conflict with us. */ for (psearch = pkg->set->depended.installed; psearch; psearch = psearch->rev_next) { if (psearch->up->type != dep_conflicts) continue; check_conflict(psearch->up, pkg, pfilename); } ensure_allinstfiles_available(); filesdbinit(); trig_file_interests_ensure(); if (pkg->status != stat_notinstalled && pkg->status != stat_configfiles) { printf(_("Preparing to replace %s %s (using %s) ...\n"), pkg_name(pkg, pnaw_nonambig), versiondescribe(&pkg->installed.version,vdew_nonambig), pfilename); log_action("upgrade", pkg, &pkg->installed); } else { printf(_("Unpacking %s (from %s) ...\n"), pkgbin_name(pkg, &pkg->available, pnaw_nonambig), pfilename); log_action("install", pkg, &pkg->available); } if (f_noact) { pop_cleanup(ehflag_normaltidy); return; } /* * OK, we're going ahead. */ trig_activate_packageprocessing(pkg); strcpy(cidirrest, TRIGGERSCIFILE); trig_parse_ci(cidir, NULL, trig_cicb_statuschange_activate, pkg, &pkg->available); /* Read the conffiles, and copy the hashes across. */ newconffiles = NULL; newconffileslastp = &newconffiles; push_cleanup(cu_fileslist, ~0, NULL, 0, 0); strcpy(cidirrest,CONFFILESFILE); conff= fopen(cidir,"r"); if (conff) { push_cleanup(cu_closestream, ehflag_bombout, NULL, 0, 1, (void *)conff); while (fgets(conffilenamebuf,MAXCONFFILENAME-2,conff)) { struct filepackages_iterator *iter; p= conffilenamebuf + strlen(conffilenamebuf); assert(p != conffilenamebuf); if (p[-1] != '\n') ohshit(_("name of conffile (starting `%.250s') is too long (>%d characters)"), conffilenamebuf, MAXCONFFILENAME); while (p > conffilenamebuf && isspace(p[-1])) --p; if (p == conffilenamebuf) continue; *p = '\0'; namenode= findnamenode(conffilenamebuf, 0); namenode->oldhash= NEWCONFFILEFLAG; newconff= newconff_append(&newconffileslastp, namenode); /* Let's see if any packages have this file. If they do we * check to see if they listed it as a conffile, and if they did * we copy the hash across. Since (for plain file conffiles, * which is the only kind we are supposed to have) there will * only be one package which ‘has’ the file, this will usually * mean we only look in the package which we're installing now. * The ‘conffiles’ data in the status file is ignored when a * package isn't also listed in the file ownership database as * having that file. If several packages are listed as owning * the file we pick one at random. */ searchconff = NULL; iter = filepackages_iter_new(newconff->namenode); while ((otherpkg = filepackages_iter_next(iter))) { debug(dbg_conffdetail, "process_archive conffile `%s' in package %s - conff ?", newconff->namenode->name, pkg_name(otherpkg, pnaw_nonambig)); for (searchconff = otherpkg->installed.conffiles; searchconff && strcmp(newconff->namenode->name, searchconff->name); searchconff = searchconff->next) debug(dbg_conffdetail, "process_archive conffile `%s' in package %s - conff ? not `%s'", newconff->namenode->name, pkg_name(otherpkg, pnaw_nonambig), searchconff->name); if (searchconff) { debug(dbg_conff, "process_archive conffile `%s' package=%s %s hash=%s", newconff->namenode->name, pkg_name(otherpkg, pnaw_nonambig), otherpkg == pkg ? "same" : "different!", searchconff->hash); if (otherpkg == pkg) break; } } filepackages_iter_free(iter); if (searchconff) { newconff->namenode->oldhash= searchconff->hash; /* We don't copy ‘obsolete’; it's not obsolete in the new package. */ } else { debug(dbg_conff,"process_archive conffile `%s' no package, no hash", newconff->namenode->name); } newconff->namenode->flags |= fnnf_new_conff; } if (ferror(conff)) ohshite(_("read error in %.250s"),cidir); pop_cleanup(ehflag_normaltidy); /* conff = fopen() */ if (fclose(conff)) ohshite(_("error closing %.250s"),cidir); } else { if (errno != ENOENT) ohshite(_("error trying to open %.250s"),cidir); } /* All the old conffiles are marked with a flag, so that we don't delete * them if they seem to disappear completely. */ oldconffsetflags(pkg->installed.conffiles); for (i = 0 ; i < cflict_index ; i++) { oldconffsetflags(conflictor[i]->installed.conffiles); } oldversionstatus= pkg->status; assert(oldversionstatus <= stat_installed); debug(dbg_general,"process_archive oldversionstatus=%s", statusstrings[oldversionstatus]); if (oldversionstatus == stat_halfconfigured || oldversionstatus == stat_triggersawaited || oldversionstatus == stat_triggerspending || oldversionstatus == stat_installed) { pkg_set_eflags(pkg, eflag_reinstreq); pkg_set_status(pkg, stat_halfconfigured); modstatdb_note(pkg); push_cleanup(cu_prermupgrade, ~ehflag_normaltidy, NULL, 0, 1, (void *)pkg); if (versioncompare(&pkg->available.version, &pkg->installed.version) >= 0) /* Upgrade or reinstall */ maintainer_script_alternative(pkg, PRERMFILE, "pre-removal", cidir, cidirrest, "upgrade", "failed-upgrade"); else /* Downgrade => no fallback */ maintainer_script_installed(pkg, PRERMFILE, "pre-removal", "upgrade", versiondescribe(&pkg->available.version, vdew_nonambig), NULL); pkg_set_status(pkg, stat_unpacked); oldversionstatus= stat_unpacked; modstatdb_note(pkg); } for (deconpil= deconfigure; deconpil; deconpil= deconpil->next) { struct pkginfo *removing = deconpil->pkg_removal; if (removing) printf(_("De-configuring %s, to allow removal of %s ...\n"), pkg_name(deconpil->pkg, pnaw_nonambig), pkg_name(removing, pnaw_nonambig)); else printf(_("De-configuring %s ...\n"), pkg_name(deconpil->pkg, pnaw_nonambig)); trig_activate_packageprocessing(deconpil->pkg); pkg_set_status(deconpil->pkg, stat_halfconfigured); modstatdb_note(deconpil->pkg); /* This means that we *either* go and run postinst abort-deconfigure, * *or* queue the package for later configure processing, depending * on which error cleanup route gets taken. */ push_cleanup(cu_prermdeconfigure, ~ehflag_normaltidy, ok_prermdeconfigure, ehflag_normaltidy, 3, (void*)deconpil->pkg, (void*)removing, (void*)pkg); if (removing) { maintainer_script_installed(deconpil->pkg, PRERMFILE, "pre-removal", "deconfigure", "in-favour", pkg->set->name, versiondescribe(&pkg->available.version, vdew_nonambig), "removing", removing->set->name, versiondescribe(&removing->installed.version, vdew_nonambig), NULL); } else { maintainer_script_installed(deconpil->pkg, PRERMFILE, "pre-removal", "deconfigure", "in-favour", pkg->set->name, versiondescribe(&pkg->available.version, vdew_nonambig), NULL); } } for (i = 0 ; i < cflict_index; i++) { if (!(conflictor[i]->status == stat_halfconfigured || conflictor[i]->status == stat_triggersawaited || conflictor[i]->status == stat_triggerspending || conflictor[i]->status == stat_installed)) continue; trig_activate_packageprocessing(conflictor[i]); pkg_set_status(conflictor[i], stat_halfconfigured); modstatdb_note(conflictor[i]); push_cleanup(cu_prerminfavour, ~ehflag_normaltidy, NULL, 0, 2,(void*)conflictor[i],(void*)pkg); maintainer_script_installed(conflictor[i], PRERMFILE, "pre-removal", "remove", "in-favour", pkg->set->name, versiondescribe(&pkg->available.version, vdew_nonambig), NULL); pkg_set_status(conflictor[i], stat_halfinstalled); modstatdb_note(conflictor[i]); } pkg_set_eflags(pkg, eflag_reinstreq); if (pkg->status == stat_notinstalled) pkg->installed.version= pkg->available.version; pkg_set_status(pkg, stat_halfinstalled); modstatdb_note(pkg); if (oldversionstatus == stat_notinstalled) { push_cleanup(cu_preinstverynew, ~ehflag_normaltidy, NULL, 0, 3,(void*)pkg,(void*)cidir,(void*)cidirrest); maintainer_script_new(pkg, PREINSTFILE, "pre-installation", cidir, cidirrest, "install", NULL); } else if (oldversionstatus == stat_configfiles) { push_cleanup(cu_preinstnew, ~ehflag_normaltidy, NULL, 0, 3,(void*)pkg,(void*)cidir,(void*)cidirrest); maintainer_script_new(pkg, PREINSTFILE, "pre-installation", cidir, cidirrest, "install", versiondescribe(&pkg->installed.version, vdew_nonambig), NULL); } else { push_cleanup(cu_preinstupgrade, ~ehflag_normaltidy, NULL, 0, 4,(void*)pkg,(void*)cidir,(void*)cidirrest,(void*)&oldversionstatus); maintainer_script_new(pkg, PREINSTFILE, "pre-installation", cidir, cidirrest, "upgrade", versiondescribe(&pkg->installed.version, vdew_nonambig), NULL); printf(_("Unpacking replacement %.250s ...\n"), pkgbin_name(pkg, &pkg->available, pnaw_nonambig)); } /* * Now we unpack the archive, backing things up as we go. * For each file, we check to see if it already exists. * There are several possibilities: * * + We are trying to install a non-directory ... * - It doesn't exist. In this case we simply extract it. * - It is a plain file, device, symlink, &c. We do an ‘atomic * overwrite’ using link() and rename(), but leave a backup copy. * Later, when we delete the backup, we remove it from any other * packages' lists. * - It is a directory. In this case it depends on whether we're * trying to install a symlink or something else. * = If we're not trying to install a symlink we move the directory * aside and extract the node. Later, when we recursively remove * the backed-up directory, we remove it from any other packages' * lists. * = If we are trying to install a symlink we do nothing - ie, * dpkg will never replace a directory tree with a symlink. This * is to avoid embarrassing effects such as replacing a directory * tree with a link to a link to the original directory tree. * + We are trying to install a directory ... * - It doesn't exist. We create it with the appropriate modes. * - It exists as a directory or a symlink to one. We do nothing. * - It is a plain file or a symlink (other than to a directory). * We move it aside and create the directory. Later, when we * delete the backup, we remove it from any other packages' lists. * * Install non-dir Install symlink Install dir * Exists not X X X * File/node/symlink LXR LXR BXR * Directory BXR - - * * X: extract file/node/link/directory * LX: atomic overwrite leaving backup * B: ordinary backup * R: later remove from other packages' lists * -: do nothing * * After we've done this we go through the remaining things in the * lists of packages we're trying to remove (including the old * version of the current package). This happens in reverse order, * so that we process files before the directories (or symlinks-to- * directories) containing them. * * + If the thing is a conffile then we leave it alone for the purge * operation. * + Otherwise, there are several possibilities too: * - The listed thing does not exist. We ignore it. * - The listed thing is a directory or a symlink to a directory. * We delete it only if it isn't listed in any other package. * - The listed thing is not a directory, but was part of the package * that was upgraded, we check to make sure the files aren't the * same ones from the old package by checking dev/inode * - The listed thing is not a directory or a symlink to one (ie, * it's a plain file, device, pipe, &c, or a symlink to one, or a * dangling symlink). We delete it. * * The removed packages' list becomes empty (of course, the new * version of the package we're installing will have a new list, * which replaces the old version's list). * * If at any stage we remove a file from a package's list, and the * package isn't one we're already processing, and the package's * list becomes empty as a result, we ‘vanish’ the package. This * means that we run its postrm with the ‘disappear’ argument, and * put the package in the ‘not-installed’ state. If it had any * conffiles, their hashes and ownership will have been transferred * already, so we just ignore those and forget about them from the * point of view of the disappearing package. * * NOTE THAT THE OLD POSTRM IS RUN AFTER THE NEW PREINST, since the * files get replaced ‘as we go’. */ m_pipe(p1); push_cleanup(cu_closepipe, ehflag_bombout, NULL, 0, 1, (void *)&p1[0]); pid = subproc_fork(); if (pid == 0) { m_dup2(p1[1],1); close(p1[0]); close(p1[1]); execlp(BACKEND, BACKEND, "--fsys-tarfile", filename, NULL); ohshite(_("unable to execute %s (%s)"), _("package filesystem archive extraction"), BACKEND); } close(p1[1]); p1[1] = -1; newfileslist = NULL; tc.newfilesp = &newfileslist; push_cleanup(cu_fileslist, ~0, NULL, 0, 0); tc.pkg= pkg; tc.backendpipe= p1[0]; r = tar_extractor(&tc, &tf); if (r) { if (errno) { ohshite(_("error reading dpkg-deb tar output")); } else { ohshit(_("corrupted filesystem tarfile - corrupted package archive")); } } fd_skip(p1[0], -1, _("dpkg-deb: zap possible trailing zeros")); close(p1[0]); p1[0] = -1; subproc_wait_check(pid, BACKEND " --fsys-tarfile", PROCPIPE); tar_deferred_extract(newfileslist, pkg); if (oldversionstatus == stat_halfinstalled || oldversionstatus == stat_unpacked) { /* Packages that were in ‘installed’ and ‘postinstfailed’ have been * reduced to ‘unpacked’ by now, by the running of the prerm script. */ pkg_set_status(pkg, stat_halfinstalled); modstatdb_note(pkg); push_cleanup(cu_postrmupgrade, ~ehflag_normaltidy, NULL, 0, 1, (void *)pkg); maintainer_script_alternative(pkg, POSTRMFILE, "post-removal", cidir, cidirrest, "upgrade", "failed-upgrade"); } /* If anything goes wrong while tidying up it's a bit late to do * anything about it. However, we don't install the new status * info yet, so that a future dpkg installation will put everything * right (we hope). * * If something does go wrong later the ‘conflictor’ package will be * left in the ‘removal_failed’ state. Removing or installing it * will be impossible if it was required because of the conflict with * the package we're installing now and (presumably) the dependency * by other packages. This means that the files it contains in * common with this package will hang around until we successfully * get this package installed, after which point we can trust the * conflicting package's file list, which will have been updated to * remove any files in this package. */ push_checkpoint(~ehflag_bombout, ehflag_normaltidy); /* Now we delete all the files that were in the old version of * the package only, except (old or new) conffiles, which we leave * alone. */ reversefilelist_init(&rlistit,pkg->clientdata->files); while ((namenode= reversefilelist_next(&rlistit))) { struct filenamenode *usenode; if ((namenode->flags & fnnf_new_conff) || (namenode->flags & fnnf_new_inarchive)) continue; usenode = namenodetouse(namenode, pkg, &pkg->installed); trig_file_activate(usenode, pkg); varbuf_trunc(&fnamevb, fnameidlu); varbuf_add_str(&fnamevb, usenode->name); varbuf_end_str(&fnamevb); if (!stat(namenode->name,&stab) && S_ISDIR(stab.st_mode)) { debug(dbg_eachfiledetail, "process_archive: %s is a directory", namenode->name); if (dir_is_used_by_others(namenode, pkg)) continue; } if (lstat(fnamevb.buf, &oldfs)) { if (!(errno == ENOENT || errno == ELOOP || errno == ENOTDIR)) warning(_("could not stat old file '%.250s' so not deleting it: %s"), fnamevb.buf, strerror(errno)); continue; } if (S_ISDIR(oldfs.st_mode)) { if (rmdir(fnamevb.buf)) { warning(_("unable to delete old directory '%.250s': %s"), namenode->name, strerror(errno)); } else if ((namenode->flags & fnnf_old_conff)) { warning(_("old conffile '%.250s' was an empty directory " "(and has now been deleted)"), namenode->name); } } else { struct fileinlist *sameas = NULL; static struct stat empty_stat; struct varbuf cfilename = VARBUF_INIT; /* * Ok, it's an old file, but is it really not in the new package? * It might be known by a different name because of symlinks. * * We need to check to make sure, so we stat the file, then compare * it to the new list. If we find a dev/inode match, we assume they * are the same file, and leave it alone. NOTE: we don't check in * other packages for sanity reasons (we don't want to stat _all_ * the files on the system). * * We run down the list of _new_ files in this package. This keeps * the process a little leaner. We are only worried about new ones * since ones that stayed the same don't really apply here. */ /* If we can't stat the old or new file, or it's a directory, * we leave it up to the normal code. */ debug(dbg_eachfile, "process_archive: checking %s for same files on " "upgrade/downgrade", fnamevb.buf); for (cfile= newfileslist; cfile; cfile= cfile->next) { /* If the file has been filtered then treat it as if it didn't exist * on the file system. */ if (cfile->namenode->flags & fnnf_filtered) continue; if (!cfile->namenode->filestat) { struct stat tmp_stat; varbuf_reset(&cfilename); varbuf_add_str(&cfilename, instdir); varbuf_add_char(&cfilename, '/'); varbuf_add_str(&cfilename, cfile->namenode->name); varbuf_end_str(&cfilename); if (lstat(cfilename.buf, &tmp_stat) == 0) { cfile->namenode->filestat = nfmalloc(sizeof(struct stat)); memcpy(cfile->namenode->filestat, &tmp_stat, sizeof(struct stat)); } else { if (!(errno == ENOENT || errno == ELOOP || errno == ENOTDIR)) ohshite(_("unable to stat other new file `%.250s'"), cfile->namenode->name); cfile->namenode->filestat = &empty_stat; continue; } } if (cfile->namenode->filestat == &empty_stat) continue; if (oldfs.st_dev == cfile->namenode->filestat->st_dev && oldfs.st_ino == cfile->namenode->filestat->st_ino) { if (sameas) warning(_("old file '%.250s' is the same as several new files! " "(both '%.250s' and '%.250s')"), fnamevb.buf, sameas->namenode->name, cfile->namenode->name); sameas= cfile; debug(dbg_eachfile, "process_archive: not removing %s," " since it matches %s", fnamevb.buf, cfile->namenode->name); } } varbuf_destroy(&cfilename); if ((namenode->flags & fnnf_old_conff)) { if (sameas) { if (sameas->namenode->flags & fnnf_new_conff) { if (!strcmp(sameas->namenode->oldhash, NEWCONFFILEFLAG)) { sameas->namenode->oldhash= namenode->oldhash; debug(dbg_eachfile, "process_archive: old conff %s" " is same as new conff %s, copying hash", namenode->name, sameas->namenode->name); } else { debug(dbg_eachfile, "process_archive: old conff %s" " is same as new conff %s but latter already has hash", namenode->name, sameas->namenode->name); } } } else { debug(dbg_eachfile, "process_archive: old conff %s" " is disappearing", namenode->name); namenode->flags |= fnnf_obs_conff; newconff_append(&newconffileslastp, namenode); addfiletolist(&tc, namenode); } continue; } if (sameas) continue; if (secure_unlink_statted(fnamevb.buf, &oldfs)) { warning(_("unable to securely remove old file '%.250s': %s"), namenode->name, strerror(errno)); } } /* !S_ISDIR */ } /* OK, now we can write the updated files-in-this package list, * since we've done away (hopefully) with all the old junk. */ write_filelist_except(pkg, &pkg->available, newfileslist, 0); /* Trigger interests may have changed. * Firstly we go through the old list of interests deleting them. * Then we go through the new list adding them. */ strcpy(cidirrest, TRIGGERSCIFILE); trig_parse_ci(pkgadminfile(pkg, &pkg->installed, TRIGGERSCIFILE), trig_cicb_interest_delete, NULL, pkg, &pkg->installed); trig_parse_ci(cidir, trig_cicb_interest_add, NULL, pkg, &pkg->available); trig_file_interests_save(); /* We also install the new maintainer scripts, and any other * cruft that may have come along with the package. First * we go through the existing scripts replacing or removing * them as appropriate; then we go through the new scripts * (any that are left) and install them. */ debug(dbg_general, "process_archive updating info directory"); pkg_infodb_update(pkg, cidir, cidirrest); /* * Update the status database. * * This involves copying each field across from the ‘available’ * to the ‘installed’ half of the pkg structure. * For some of the fields we have to do a complicated construction * operation; for others we can just copy the value. * We tackle the fields in the order they appear, so that * we don't miss any out :-). * At least we don't have to copy any strings that are referred * to, because these are never modified and never freed. */ /* The dependencies are the most difficult. We have to build * a whole new forward dependency tree. At least the reverse * links (linking our deppossi's into the reverse chains) * can be done by copy_dependency_links. */ newdeplist = NULL; newdeplistlastp = &newdeplist; for (dep= pkg->available.depends; dep; dep= dep->next) { newdep= nfmalloc(sizeof(struct dependency)); newdep->up= pkg; newdep->next = NULL; newdep->list = NULL; newpossilastp = &newdep->list; for (possi= dep->list; possi; possi= possi->next) { newpossi= nfmalloc(sizeof(struct deppossi)); newpossi->up= newdep; newpossi->ed= possi->ed; newpossi->next = NULL; newpossi->rev_next = newpossi->rev_prev = NULL; newpossi->arch_is_implicit = possi->arch_is_implicit; newpossi->arch = possi->arch; newpossi->verrel= possi->verrel; if (possi->verrel != dvr_none) newpossi->version= possi->version; else blankversion(&newpossi->version); newpossi->cyclebreak = false; *newpossilastp= newpossi; newpossilastp= &newpossi->next; } newdep->type= dep->type; *newdeplistlastp= newdep; newdeplistlastp= &newdep->next; } /* Right, now we've replicated the forward tree, we * get copy_dependency_links to remove all the old dependency * structures from the reverse links and add the new dependency * structures in instead. It also copies the new dependency * structure pointer for this package into the right field. */ copy_dependency_links(pkg,&pkg->installed.depends,newdeplist,0); /* We copy the text fields. */ pkg->installed.essential= pkg->available.essential; pkg->installed.multiarch = pkg->available.multiarch; pkg->installed.description= pkg->available.description; pkg->installed.maintainer= pkg->available.maintainer; pkg->installed.source= pkg->available.source; pkg->installed.arch = pkg->available.arch; pkg->installed.installedsize= pkg->available.installedsize; pkg->installed.version= pkg->available.version; pkg->installed.origin = pkg->available.origin; pkg->installed.bugs = pkg->available.bugs; /* We have to generate our own conffiles structure. */ pkg->installed.conffiles = NULL; iconffileslastp = &pkg->installed.conffiles; for (cfile= newconffiles; cfile; cfile= cfile->next) { newiconff= nfmalloc(sizeof(struct conffile)); newiconff->next = NULL; newiconff->name= nfstrsave(cfile->namenode->name); newiconff->hash= nfstrsave(cfile->namenode->oldhash); newiconff->obsolete= !!(cfile->namenode->flags & fnnf_obs_conff); *iconffileslastp= newiconff; iconffileslastp= &newiconff->next; } /* We can just copy the arbitrary fields list, because it is * never even rearranged. Phew! */ pkg->installed.arbs= pkg->available.arbs; /* Check for disappearing packages: * We go through all the packages on the system looking for ones * whose files are entirely part of the one we've just unpacked * (and which actually *have* some files!). * * Any that we find are removed - we run the postrm with ‘disappear’ * as an argument, and remove their info/... files and status info. * Conffiles are ignored (the new package had better do something * with them!). */ it = pkg_db_iter_new(); while ((otherpkg = pkg_db_iter_next_pkg(it)) != NULL) { ensure_package_clientdata(otherpkg); if (otherpkg == pkg || otherpkg->status == stat_notinstalled || otherpkg->status == stat_configfiles || otherpkg->clientdata->istobe == itb_remove || !otherpkg->clientdata->files) continue; debug(dbg_veryverbose, "process_archive checking disappearance %s", pkg_name(otherpkg, pnaw_nonambig)); assert(otherpkg->clientdata->istobe == itb_normal || otherpkg->clientdata->istobe == itb_deconfigure); for (cfile= otherpkg->clientdata->files; cfile && !strcmp(cfile->namenode->name,"/."); cfile= cfile->next); if (!cfile) { debug(dbg_stupidlyverbose, "process_archive no non-root, no disappear"); continue; } for (cfile= otherpkg->clientdata->files; cfile && !filesavespackage(cfile,otherpkg,pkg); cfile= cfile->next); if (cfile) continue; /* So dependency things will give right answers ... */ otherpkg->clientdata->istobe= itb_remove; debug(dbg_veryverbose, "process_archive disappear checking dependencies"); for (pdep = otherpkg->set->depended.installed; pdep; pdep = pdep->rev_next) { if (pdep->up->type != dep_depends && pdep->up->type != dep_predepends && pdep->up->type != dep_recommends) continue; if (depisok(pdep->up, &depprobwhy, NULL, NULL, false)) continue; varbuf_end_str(&depprobwhy); debug(dbg_veryverbose,"process_archive cannot disappear: %s",depprobwhy.buf); break; } if (!pdep) { /* If we haven't found a reason not to yet, let's look some more. */ for (providecheck= otherpkg->installed.depends; providecheck; providecheck= providecheck->next) { if (providecheck->type != dep_provides) continue; for (pdep = providecheck->list->ed->depended.installed; pdep; pdep = pdep->rev_next) { if (pdep->up->type != dep_depends && pdep->up->type != dep_predepends && pdep->up->type != dep_recommends) continue; if (depisok(pdep->up, &depprobwhy, NULL, NULL, false)) continue; varbuf_end_str(&depprobwhy); debug(dbg_veryverbose,"process_archive cannot disappear (provides %s): %s", providecheck->list->ed->name, depprobwhy.buf); goto break_from_both_loops_at_once; } } break_from_both_loops_at_once:; } otherpkg->clientdata->istobe= itb_normal; if (pdep) continue; /* No, we're disappearing it. This is the wrong time to go and * run maintainer scripts and things, as we can't back out. But * what can we do ? It has to be run this late. */ pkg_disappear(otherpkg, pkg); } /* while (otherpkg= ... */ pkg_db_iter_free(it); /* Delete files from any other packages' lists. * We have to do this before we claim this package is in any * sane kind of state, as otherwise we might delete by mistake * a file that we overwrote, when we remove the package which * had the version we overwrote. To prevent this we make * sure that we don't claim this package is OK until we * have claimed ‘ownership’ of all its files. */ for (cfile= newfileslist; cfile; cfile= cfile->next) { struct filepackages_iterator *iter; struct pkgset *divpkgset; if (!(cfile->namenode->flags & fnnf_elide_other_lists)) continue; if (cfile->namenode->divert && cfile->namenode->divert->useinstead) { divpkgset = cfile->namenode->divert->pkgset; if (divpkgset == pkg->set) { debug(dbg_eachfile, "process_archive not overwriting any `%s' (overriding, `%s')", cfile->namenode->name, cfile->namenode->divert->useinstead->name); continue; } else { debug(dbg_eachfile, "process_archive looking for overwriting `%s' (overridden by %s)", cfile->namenode->name, divpkgset ? divpkgset->name : "<local>"); } } else { divpkgset = NULL; debug(dbg_eachfile, "process_archive looking for overwriting `%s'", cfile->namenode->name); } iter = filepackages_iter_new(cfile->namenode); while ((otherpkg = filepackages_iter_next(iter))) { debug(dbg_eachfiledetail, "process_archive ... found in %s", pkg_name(otherpkg, pnaw_nonambig)); /* If !fileslistvalid then it's one of the disappeared packages above * and we don't bother with it here, clearly. */ if (otherpkg == pkg || !otherpkg->clientdata->fileslistvalid) continue; if (otherpkg->set == divpkgset) { debug(dbg_eachfiledetail, "process_archive ... diverted, skipping"); continue; } /* Found one. We delete remove the list entry for this file, * (and any others in the same package) and then mark the package * as requiring a reread. */ write_filelist_except(otherpkg, &otherpkg->installed, otherpkg->clientdata->files, fnnf_elide_other_lists); ensure_package_clientdata(otherpkg); debug(dbg_veryverbose, "process_archive overwrote from %s", pkg_name(otherpkg, pnaw_nonambig)); } filepackages_iter_free(iter); } /* Right, the package we've unpacked is now in a reasonable state. * The only thing that we have left to do with it is remove * backup files, and we can leave the user to fix that if and when * it happens (we leave the reinstall required flag, of course). */ pkg_set_status(pkg, stat_unpacked); modstatdb_note(pkg); /* Now we delete all the backup files that we made when * extracting the archive - except for files listed as conffiles * in the new package. * This time we count it as an error if something goes wrong. * * Note that we don't ever delete things that were in the old * package as a conffile and don't appear at all in the new. * They stay recorded as obsolete conffiles and will eventually * (if not taken over by another package) be forgotten. */ for (cfile= newfileslist; cfile; cfile= cfile->next) { if (cfile->namenode->flags & fnnf_new_conff) continue; varbuf_trunc(&fnametmpvb, fnameidlu); varbuf_add_str(&fnametmpvb, namenodetouse(cfile->namenode, pkg, &pkg->installed)->name); varbuf_add_str(&fnametmpvb, DPKGTEMPEXT); varbuf_end_str(&fnametmpvb); ensure_pathname_nonexisting(fnametmpvb.buf); } /* OK, we're now fully done with the main package. * This is quite a nice state, so we don't unwind past here. */ pkg_reset_eflags(pkg); modstatdb_note(pkg); push_checkpoint(~ehflag_bombout, ehflag_normaltidy); /* Only the removal of the conflictor left to do. * The files list for the conflictor is still a little inconsistent in-core, * as we have not yet updated the filename->packages mappings; however, * the package->filenames mapping is. */ for (i = 0 ; i < cflict_index ; i++) { /* We need to have the most up-to-date info about which files are * what ... */ ensure_allinstfiles_available(); removal_bulk(conflictor[i]); } if (cipaction->arg_int == act_install) add_to_queue(pkg); }
/** * Cycle breaking works recursively down the package dependency tree. * * ‘sofar’ is the list of packages we've descended down already - if we * encounter any of its packages again in a dependency we have found a cycle. */ static bool findbreakcyclerecursive(struct pkginfo *pkg, struct cyclesofarlink *sofar) { struct cyclesofarlink thislink, *sol; struct dependency *dep; struct deppossi *possi, *providelink; struct pkginfo *provider, *pkg_pos; if (pkg->clientdata->color == PKG_CYCLE_BLACK) return false; pkg->clientdata->color = PKG_CYCLE_GRAY; if (debug_has_flag(dbg_depcondetail)) { struct varbuf str_pkgs = VARBUF_INIT; for (sol = sofar; sol; sol = sol->prev) { varbuf_add_str(&str_pkgs, " <- "); varbuf_add_pkgbin_name(&str_pkgs, sol->pkg, &sol->pkg->installed, pnaw_nonambig); } varbuf_end_str(&str_pkgs); debug(dbg_depcondetail, "findbreakcyclerecursive %s %s", pkg_name(pkg, pnaw_always), str_pkgs.buf); varbuf_destroy(&str_pkgs); } thislink.pkg= pkg; thislink.prev = sofar; thislink.possi = NULL; for (dep= pkg->installed.depends; dep; dep= dep->next) { if (dep->type != dep_depends && dep->type != dep_predepends) continue; for (possi= dep->list; possi; possi= possi->next) { struct deppossi_pkg_iterator *possi_iter; /* Don't find the same cycles again. */ if (possi->cyclebreak) continue; thislink.possi= possi; possi_iter = deppossi_pkg_iter_new(possi, wpb_installed); while ((pkg_pos = deppossi_pkg_iter_next(possi_iter))) if (foundcyclebroken(&thislink, sofar, pkg_pos, possi)) { deppossi_pkg_iter_free(possi_iter); return true; } deppossi_pkg_iter_free(possi_iter); /* Right, now we try all the providers ... */ for (providelink = possi->ed->depended.installed; providelink; providelink = providelink->rev_next) { if (providelink->up->type != dep_provides) continue; provider= providelink->up->up; if (provider->clientdata->istobe == PKG_ISTOBE_NORMAL) continue; /* We don't break things at ‘provides’ links, so ‘possi’ is * still the one we use. */ if (foundcyclebroken(&thislink, sofar, provider, possi)) return true; } } } /* Nope, we didn't find a cycle to break. */ pkg->clientdata->color = PKG_CYCLE_BLACK; return false; }
int commandfd(const char *const *argv) { struct varbuf linevb = VARBUF_INIT; const char * pipein; const char **newargs = NULL; char *ptr, *endptr; FILE *in; long infd; int ret = 0; int c, lno, i; bool skipchar; pipein = *argv++; if (pipein == NULL || *argv) badusage(_("--%s takes exactly one argument"), cipaction->olong); infd = dpkg_options_parse_arg_int(cipaction, pipein); in = fdopen(infd, "r"); if (in == NULL) ohshite(_("couldn't open '%i' for stream"), (int)infd); for (;;) { bool mode = false; int argc= 1; lno= 0; push_error_context(); do { c = getc(in); if (c == '\n') lno++; } while (c != EOF && c_isspace(c)); if (c == EOF) break; if (c == '#') { do { c= getc(in); if (c == '\n') lno++; } while (c != EOF && c != '\n'); continue; } varbuf_reset(&linevb); do { varbuf_add_char(&linevb, c); c= getc(in); if (c == '\n') lno++; /* This isn't fully accurate, but overestimating can't hurt. */ if (c_isspace(c)) argc++; } while (c != EOF && c != '\n'); if (c == EOF) ohshit(_("unexpected end of file before end of line %d"), lno); if (!argc) continue; varbuf_end_str(&linevb); newargs = m_realloc(newargs, sizeof(const char *) * (argc + 1)); argc= 1; ptr= linevb.buf; endptr = ptr + linevb.used + 1; skipchar = false; while(ptr < endptr) { if (skipchar) { skipchar = false; } else if (*ptr == '\\') { memmove(ptr, (ptr+1), (linevb.used-(linevb.buf - ptr)-1)); endptr--; skipchar = true; continue; } else if (c_isspace(*ptr)) { if (mode == true) { *ptr = '\0'; mode = false; } } else { if (mode == false) { newargs[argc]= ptr; argc++; mode = true; } } ptr++; } *ptr = '\0'; newargs[argc++] = NULL; /* We strdup() each argument, but never free it, because the * error messages contain references back to these strings. * Freeing them, and reusing the memory, would make those * error messages confusing, to say the least. */ for(i=1;i<argc;i++) if (newargs[i]) newargs[i] = m_strdup(newargs[i]); setaction(NULL, NULL); dpkg_options_parse((const char *const **)&newargs, cmdinfos, printforhelp); if (!cipaction) badusage(_("need an action option")); ret |= cipaction->action(newargs); pop_error_context(ehflag_normaltidy); } return ret; }
int setselections(const char *const *argv) { const struct namevalue *nv; struct pkginfo *pkg; const char *e; int c, lno; struct varbuf namevb = VARBUF_INIT; struct varbuf selvb = VARBUF_INIT; if (*argv) badusage(_("--%s takes no arguments"), cipaction->olong); modstatdb_open(msdbrw_write | msdbrw_available_readonly); lno= 1; for (;;) { do { c= getchar(); if (c == '\n') lno++; } while (c != EOF && isspace(c)); if (c == EOF) break; if (c == '#') { do { c= getchar(); if (c == '\n') lno++; } while (c != EOF && c != '\n'); continue; } varbuf_reset(&namevb); while (!isspace(c)) { varbuf_add_char(&namevb, c); c= getchar(); if (c == EOF) ohshit(_("unexpected eof in package name at line %d"),lno); if (c == '\n') ohshit(_("unexpected end of line in package name at line %d"),lno); } varbuf_end_str(&namevb); while (c != EOF && isspace(c)) { c= getchar(); if (c == EOF) ohshit(_("unexpected eof after package name at line %d"),lno); if (c == '\n') ohshit(_("unexpected end of line after package name at line %d"),lno); } varbuf_reset(&selvb); while (c != EOF && !isspace(c)) { varbuf_add_char(&selvb, c); c= getchar(); } varbuf_end_str(&selvb); while (c != EOF && c != '\n') { c= getchar(); if (!isspace(c)) ohshit(_("unexpected data after package and selection at line %d"),lno); } e = pkg_name_is_illegal(namevb.buf); if (e) ohshit(_("illegal package name at line %d: %.250s"),lno,e); nv = namevalue_find_by_name(wantinfos, selvb.buf); if (nv == NULL) ohshit(_("unknown wanted status at line %d: %.250s"), lno, selvb.buf); pkg = pkg_db_find(namevb.buf); pkg_set_want(pkg, nv->value); if (c == EOF) break; lno++; } if (ferror(stdin)) ohshite(_("read error on standard input")); modstatdb_shutdown(); varbuf_destroy(&namevb); varbuf_destroy(&selvb); return 0; }
/* * Does cycle checking. Doesn't mind if pkg has no triggers pending - in * that case does nothing but fix up any stale awaiters. */ void trigproc(struct pkginfo *pkg, enum trigproc_type type) { static struct varbuf namesarg; struct varbuf depwhynot = VARBUF_INIT; struct trigpend *tp; struct pkginfo *gaveup; debug(dbg_triggers, "trigproc %s", pkg_name(pkg, pnaw_always)); if (pkg->clientdata->trigprocdeferred) pkg->clientdata->trigprocdeferred->pkg = NULL; pkg->clientdata->trigprocdeferred = NULL; if (pkg->trigpend_head) { enum dep_check ok; assert(pkg->status == PKG_STAT_TRIGGERSPENDING || pkg->status == PKG_STAT_TRIGGERSAWAITED); if (dependtry > 1) { gaveup = check_trigger_cycle(pkg); if (gaveup == pkg) return; if (findbreakcycle(pkg)) sincenothing = 0; } ok = dependencies_ok(pkg, NULL, &depwhynot); if (ok == DEP_CHECK_DEFER) { varbuf_destroy(&depwhynot); enqueue_package(pkg); return; } else if (ok == DEP_CHECK_HALT) { /* We cannot process this package on this dpkg run, * and we can get here repeatedly if this package is * required to make progress for other packages. So * reset the trigger cycles tracking to avoid bogus * cycle detections. */ trigproc_reset_cycle(); /* When doing opportunistic trigger processig, nothing * requires us to be able to make progress; skip the * package and silently ignore the error due to * unsatisfiable dependencies. */ if (type == TRIGPROC_TRY) { varbuf_destroy(&depwhynot); return; } sincenothing = 0; varbuf_end_str(&depwhynot); notice(_("dependency problems prevent processing " "triggers for %s:\n%s"), pkg_name(pkg, pnaw_nonambig), depwhynot.buf); varbuf_destroy(&depwhynot); ohshit(_("dependency problems - leaving triggers unprocessed")); } else if (depwhynot.used) { varbuf_end_str(&depwhynot); notice(_("%s: dependency problems, but processing " "triggers anyway as you requested:\n%s"), pkg_name(pkg, pnaw_nonambig), depwhynot.buf); varbuf_destroy(&depwhynot); } if (dependtry <= 1) { gaveup = check_trigger_cycle(pkg); if (gaveup == pkg) return; } printf(_("Processing triggers for %s (%s) ...\n"), pkg_name(pkg, pnaw_nonambig), versiondescribe(&pkg->installed.version, vdew_nonambig)); log_action("trigproc", pkg, &pkg->installed); varbuf_reset(&namesarg); for (tp = pkg->trigpend_head; tp; tp = tp->next) { varbuf_add_char(&namesarg, ' '); varbuf_add_str(&namesarg, tp->name); } varbuf_end_str(&namesarg); /* Setting the status to half-configured * causes modstatdb_note to clear pending triggers. */ pkg_set_status(pkg, PKG_STAT_HALFCONFIGURED); modstatdb_note(pkg); if (!f_noact) { sincenothing = 0; maintscript_postinst(pkg, "triggered", namesarg.buf + 1, NULL); } post_postinst_tasks(pkg, PKG_STAT_INSTALLED); } else { /* In other branch is done by modstatdb_note(), from inside * post_postinst_tasks(). */ trig_clear_awaiters(pkg); } }
/** * Print a single package which: * (a) is the target of one or more relevant predependencies. * (b) has itself no unsatisfied pre-dependencies. * * If such a package is present output is the Packages file entry, * which can be massaged as appropriate. * * Exit status: * 0 = a package printed, OK * 1 = no suitable package available * 2 = error */ int predeppackage(const char *const *argv) { static struct varbuf vb; struct pkgiterator *it; struct pkginfo *pkg = NULL, *startpkg, *trypkg; struct dependency *dep; struct deppossi *possi, *provider; if (*argv) badusage(_("--%s takes no arguments"), cipaction->olong); modstatdb_open(msdbrw_readonly | msdbrw_available_readonly); /* We use clientdata->istobe to detect loops. */ clear_istobes(); dep = NULL; it = pkg_db_iter_new(); while (!dep && (pkg = pkg_db_iter_next_pkg(it))) { /* Ignore packages user doesn't want. */ if (pkg->want != PKG_WANT_INSTALL) continue; /* Ignore packages not available. */ if (!pkg->files) continue; pkg->clientdata->istobe = PKG_ISTOBE_PREINSTALL; for (dep= pkg->available.depends; dep; dep= dep->next) { if (dep->type != dep_predepends) continue; if (depisok(dep, &vb, NULL, NULL, true)) continue; /* This will leave dep non-NULL, and so exit the loop. */ break; } pkg->clientdata->istobe = PKG_ISTOBE_NORMAL; /* If dep is NULL we go and get the next package. */ } pkg_db_iter_free(it); if (!dep) return 1; /* Not found. */ assert(pkg); startpkg= pkg; pkg->clientdata->istobe = PKG_ISTOBE_PREINSTALL; /* OK, we have found an unsatisfied predependency. * Now go and find the first thing we need to install, as a first step * towards satisfying it. */ do { /* We search for a package which would satisfy dep, and put it in pkg. */ for (possi = dep->list, pkg = NULL; !pkg && possi; possi=possi->next) { struct deppossi_pkg_iterator *possi_iter; possi_iter = deppossi_pkg_iter_new(possi, wpb_available); while (!pkg && (trypkg = deppossi_pkg_iter_next(possi_iter))) { if (trypkg->files && trypkg->clientdata->istobe == PKG_ISTOBE_NORMAL && versionsatisfied(&trypkg->available, possi)) { pkg = trypkg; break; } for (provider = possi->ed->depended.available; !pkg && provider; provider = provider->next) { if (provider->up->type != dep_provides) continue; if (!pkg_virtual_deppossi_satisfied(possi, provider)) continue; trypkg = provider->up->up; if (!trypkg->files) continue; if (trypkg->clientdata->istobe == PKG_ISTOBE_NORMAL) { pkg = trypkg; break; } } } deppossi_pkg_iter_free(possi_iter); } if (!pkg) { varbuf_reset(&vb); describedepcon(&vb,dep); varbuf_end_str(&vb); notice(_("cannot see how to satisfy pre-dependency:\n %s"), vb.buf); ohshit(_("cannot satisfy pre-dependencies for %.250s (wanted due to %.250s)"), pkgbin_name(dep->up, &dep->up->available, pnaw_nonambig), pkgbin_name(startpkg, &startpkg->available, pnaw_nonambig)); } pkg->clientdata->istobe = PKG_ISTOBE_PREINSTALL; for (dep= pkg->available.depends; dep; dep= dep->next) { if (dep->type != dep_predepends) continue; if (depisok(dep, &vb, NULL, NULL, true)) continue; /* This will leave dep non-NULL, and so exit the loop. */ break; } } while (dep); /* OK, we've found it - pkg has no unsatisfied pre-dependencies! */ writerecord(stdout, _("<standard output>"), pkg, &pkg->available); m_output(stdout, _("<standard output>")); return 0; }
/* * Checks [Pre]-Depends only. */ enum dep_check dependencies_ok(struct pkginfo *pkg, struct pkginfo *removing, struct varbuf *aemsgs) { /* Valid values: 2 = ok, 1 = defer, 0 = halt. */ enum dep_check ok; /* Valid values: 0 = none, 1 = defer, 2 = withwarning, 3 = ok. */ enum found_status found, thisf; int interestingwarnings; bool matched, anycannotfixbytrig; struct varbuf oemsgs = VARBUF_INIT; struct dependency *dep; struct deppossi *possi, *provider; struct pkginfo *possfixbytrig, *canfixbytrig; interestingwarnings= 0; ok = DEP_CHECK_OK; debug(dbg_depcon,"checking dependencies of %s (- %s)", pkg_name(pkg, pnaw_always), removing ? pkg_name(removing, pnaw_always) : "<none>"); anycannotfixbytrig = false; canfixbytrig = NULL; for (dep= pkg->installed.depends; dep; dep= dep->next) { if (dep->type != dep_depends && dep->type != dep_predepends) continue; debug(dbg_depcondetail," checking group ..."); matched = false; varbuf_reset(&oemsgs); found = FOUND_NONE; possfixbytrig = NULL; for (possi = dep->list; found != FOUND_OK && possi; possi = possi->next) { struct deppossi_pkg_iterator *possi_iter; struct pkginfo *pkg_pos; debug(dbg_depcondetail," checking possibility -> %s",possi->ed->name); if (possi->cyclebreak) { debug(dbg_depcondetail," break cycle so ok and found"); found = FOUND_OK; break; } thisf = FOUND_NONE; possi_iter = deppossi_pkg_iter_new(possi, wpb_installed); while ((pkg_pos = deppossi_pkg_iter_next(possi_iter))) { thisf = deppossi_ok_found(pkg_pos, pkg, removing, NULL, &possfixbytrig, &matched, possi, &interestingwarnings, &oemsgs); if (thisf > found) found = thisf; if (found == FOUND_OK) break; } deppossi_pkg_iter_free(possi_iter); if (found != FOUND_OK) { for (provider = possi->ed->depended.installed; found != FOUND_OK && provider; provider = provider->rev_next) { if (provider->up->type != dep_provides) continue; debug(dbg_depcondetail, " checking provider %s", pkg_name(provider->up->up, pnaw_always)); if (!deparchsatisfied(&provider->up->up->installed, provider->arch, possi)) { debug(dbg_depcondetail, " provider does not satisfy arch"); continue; } thisf = deppossi_ok_found(provider->up->up, pkg, removing, provider, &possfixbytrig, &matched, possi, &interestingwarnings, &oemsgs); if (thisf == FOUND_DEFER && provider->up->up == pkg && !removing) { /* IOW, if the pkg satisfies its own dep (via a provide), then * we let it pass, even if it isn't configured yet (as we're * installing it). */ thisf = FOUND_OK; } if (thisf > found) found = thisf; } } debug(dbg_depcondetail," found %d",found); if (thisf > found) found= thisf; } if (in_force(FORCE_DEPENDS)) { thisf = found_forced_on(DEPEND_TRY_FORCE_DEPENDS); if (thisf > found) { found = thisf; debug(dbg_depcondetail, " rescued by force-depends, found %d", found); } } debug(dbg_depcondetail, " found %d matched %d possfixbytrig %s", found, matched, possfixbytrig ? pkg_name(possfixbytrig, pnaw_always) : "-"); if (removing && !matched) continue; switch (found) { case FOUND_NONE: anycannotfixbytrig = true; ok = DEP_CHECK_HALT; /* Fall through. */ case FOUND_FORCED: varbuf_add_str(aemsgs, " "); varbuf_add_pkgbin_name(aemsgs, pkg, &pkg->installed, pnaw_nonambig); varbuf_add_str(aemsgs, _(" depends on ")); varbufdependency(aemsgs, dep); if (interestingwarnings) { /* Don't print the line about the package to be removed if * that's the only line. */ varbuf_end_str(&oemsgs); varbuf_add_str(aemsgs, _("; however:\n")); varbuf_add_str(aemsgs, oemsgs.buf); } else { varbuf_add_str(aemsgs, ".\n"); } break; case FOUND_DEFER: if (possfixbytrig) canfixbytrig = possfixbytrig; else anycannotfixbytrig = true; if (ok > DEP_CHECK_DEFER) ok = DEP_CHECK_DEFER; break; case FOUND_OK: break; default: internerr("unknown value for found '%d'", found); } } if (ok == DEP_CHECK_HALT && (pkg->clientdata && pkg->clientdata->istobe == PKG_ISTOBE_REMOVE)) ok = DEP_CHECK_DEFER; if (!anycannotfixbytrig && canfixbytrig) progress_bytrigproc = canfixbytrig; varbuf_destroy(&oemsgs); debug(dbg_depcon,"ok %d msgs >>%.*s<<", ok, (int)aemsgs->used, aemsgs->buf); return ok; }