static void modstatdb_note_core(struct pkginfo *pkg) { assert(cstatus >= msdbrw_write); varbufreset(&uvb); varbufrecord(&uvb, pkg, &pkg->installed); if (fwrite(uvb.buf, 1, uvb.used, importanttmp) != uvb.used) ohshite(_("unable to write updated status of `%.250s'"), pkg->name); if (fflush(importanttmp)) ohshite(_("unable to flush updated status of `%.250s'"), pkg->name); if (ftruncate(fileno(importanttmp), uvb.used)) ohshite(_("unable to truncate for updated status of `%.250s'"), pkg->name); if (fsync(fileno(importanttmp))) ohshite(_("unable to fsync updated status of `%.250s'"), pkg->name); if (fclose(importanttmp)) ohshite(_("unable to close updated status of `%.250s'"), pkg->name); sprintf(updatefnrest, IMPORTANTFMT, nextupdate); if (rename(importanttmpfile, updatefnbuf)) ohshite(_("unable to install updated status of `%.250s'"), pkg->name); /* Have we made a real mess? */ assert(strlen(updatefnrest) <= IMPORTANTMAXLEN); nextupdate++; if (nextupdate > MAXUPDATES) { modstatdb_checkpoint(); nextupdate = 0; } createimptmp(); }
static void trig_transitional_activate(enum modstatdb_rw cstatus) { /* cstatus might be _read if we're in --no-act mode, in which * case we don't write out all of the interest files etc. * but we do invent all of the activations for our own benefit. */ struct pkgiterator *it; struct pkginfo *pkg; it = iterpkgstart(); while ((pkg = iterpkgnext(it))) { if (pkg->status <= stat_halfinstalled) continue; debug(dbg_triggersdetail, "trig_transitional_activate %s %s", pkg->name, statusinfos[pkg->status].name); pkg->trigpend_head = NULL; trig_parse_ci(pkgadminfile(pkg, TRIGGERSCIFILE), cstatus >= msdbrw_write ? transitional_interest_callback : transitional_interest_callback_ro, NULL, pkg); } iterpkgend(it); if (cstatus >= msdbrw_write) { modstatdb_checkpoint(); trig_file_interests_save(); } }
void modstatdb_shutdown(void) { if (cflags >= msdbrw_available_write) writedb(availablefile, wdb_dump_available); switch (cstatus) { case msdbrw_write: modstatdb_checkpoint(); /* Tidy up a bit, but don't worry too much about failure. */ fclose(importanttmp); unlink(importanttmpfile); varbuf_destroy(&uvb); /* Fall through. */ case msdbrw_needsuperuserlockonly: modstatdb_unlock(); default: break; } modstatdb_done(); }
/* * cstatus might be msdbrw_readonly if we're in --no-act mode, in which * case we don't write out all of the interest files etc. but we do * invent all of the activations for our own benefit. */ static void trig_transitional_activate(enum modstatdb_rw cstatus) { struct pkgiterator *iter; struct pkginfo *pkg; iter = pkg_db_iter_new(); while ((pkg = pkg_db_iter_next_pkg(iter))) { if (pkg->status <= PKG_STAT_HALFINSTALLED) continue; debug(dbg_triggersdetail, "trig_transitional_activate %s %s", pkg_name(pkg, pnaw_always), pkg_status_name(pkg)); pkg->trigpend_head = NULL; trig_parse_ci(pkg_infodb_get_file(pkg, &pkg->installed, TRIGGERSCIFILE), cstatus >= msdbrw_write ? transitional_interest_callback : transitional_interest_callback_ro, NULL, pkg, &pkg->installed); /* Ensure we're not creating incoherent data that can't * be written down. This should never happen in theory but * can happen if you restore an old status file that is * not in sync with the infodb files. */ if (pkg->status < PKG_STAT_TRIGGERSAWAITED) continue; if (pkg->trigaw.head) pkg_set_status(pkg, PKG_STAT_TRIGGERSAWAITED); else if (pkg->trigpend_head) pkg_set_status(pkg, PKG_STAT_TRIGGERSPENDING); else pkg_set_status(pkg, PKG_STAT_INSTALLED); } pkg_db_iter_free(iter); if (cstatus >= msdbrw_write) { modstatdb_checkpoint(); trig_file_interests_save(); } }
/* * cstatus might be msdbrw_readonly if we're in --no-act mode, in which * case we don't write out all of the interest files etc. but we do * invent all of the activations for our own benefit. */ static void trig_transitional_activate(enum modstatdb_rw cstatus) { struct pkgiterator *it; struct pkginfo *pkg; /* Ensure we can use pkgadminfile() even when called at the very * end of modstatdb_open when triggers/Unincorp is missing */ pkg_infodb_init(cstatus); it = pkg_db_iter_new(); while ((pkg = pkg_db_iter_next_pkg(it))) { if (pkg->status <= stat_halfinstalled) continue; debug(dbg_triggersdetail, "trig_transitional_activate %s %s", pkg_describe(pkg, pdo_foreign), statusinfos[pkg->status].name); pkg->trigpend_head = NULL; trig_parse_ci(pkgadminfile(pkg, &pkg->installed, TRIGGERSCIFILE), cstatus >= msdbrw_write ? transitional_interest_callback : transitional_interest_callback_ro, NULL, pkg); /* Ensure we're not creating incoherent data that can't * be written down. This should never happen in theory but * can happen if you restore an old status file that is * not in sync with the infodb files. */ if (pkg->status < stat_triggersawaited) continue; pkg->status = pkg->trigaw.head ? stat_triggersawaited : pkg->trigpend_head ? stat_triggerspending : stat_installed; } pkg_db_iter_free(it); if (cstatus >= msdbrw_write) { modstatdb_checkpoint(); trig_file_interests_save(); } }
void modstatdb_shutdown(void) { const struct fni *fnip; switch (cstatus) { case msdbrw_write: modstatdb_checkpoint(); writedb(availablefile,1,0); /* tidy up a bit, but don't worry too much about failure */ fclose(importanttmp); unlink(importanttmpfile); varbuffree(&uvb); /* fall through */ case msdbrw_needsuperuserlockonly: unlockdatabase(); default: break; } for (fnip=fnis; fnip->suffix; fnip++) { free(*fnip->store); *fnip->store= NULL; } free(updatefnbuf); }