int main(int argc, const char * const *argv) { const char *env_pkgname; int ret; dpkg_locales_init(PACKAGE); dpkg_program_init("dpkg-divert"); dpkg_options_parse(&argv, cmdinfos, printforhelp); admindir = dpkg_db_set_dir(admindir); instdir = dpkg_fsys_set_dir(instdir); env_pkgname = getenv("DPKG_MAINTSCRIPT_PACKAGE"); if (opt_pkgname_match_any && env_pkgname) set_package(NULL, env_pkgname); if (!cipaction) setaction(&cmdinfo_add, NULL); modstatdb_open(msdbrw_readonly); fsys_hash_init(); ensure_diversions(); ret = cipaction->action(argv); modstatdb_shutdown(); dpkg_program_done(); return ret; }
int packages(const char *const *argv) { trigproc_install_hooks(); modstatdb_open(f_noact ? msdbrw_readonly : in_force(FORCE_NON_ROOT) ? msdbrw_write : msdbrw_needsuperuser); checkpath(); pkg_infodb_upgrade(); log_message("startup packages %s", cipaction->olong); if (f_pending) { if (*argv) badusage(_("--%s --pending does not take any non-option arguments"),cipaction->olong); enqueue_pending(); } else { if (!*argv) badusage(_("--%s needs at least one package name argument"), cipaction->olong); enqueue_specified(argv); } ensure_diversions(); process_queue(); trigproc_run_deferred(); modstatdb_shutdown(); return 0; }
static void post_script_tasks(void) { ensure_diversions(); debug(dbg_triggersdetail, "post_script_tasks - ensure_diversions; trig_incorporate"); trig_incorporate(msdbrw_write); }
int maintainer_script_postinst(struct pkginfo *pkg, ...) { int r; va_list args; va_start(args, pkg); r = vmaintainer_script_installed(pkg, POSTINSTFILE, "post-installation", args); va_end(args); if (r) ensure_diversions(); return r; }
int verify(const char *const *argv) { struct pkginfo *pkg; int rc = 0; modstatdb_open(msdbrw_readonly); ensure_diversions(); if (!*argv) { struct pkgiterator *it; it = pkg_db_iter_new(); while ((pkg = pkg_db_iter_next_pkg(it))) verify_package(pkg); pkg_db_iter_free(it); } else { const char *thisarg; while ((thisarg = *argv++)) { pkg = dpkg_options_parse_pkgname(cipaction, thisarg); if (pkg->status == PKG_STAT_NOTINSTALLED) { notice(_("package '%s' is not installed"), pkg_name(pkg, pnaw_nonambig)); rc = 1; continue; } verify_package(pkg); } } modstatdb_shutdown(); m_output(stdout, _("<standard output>")); return rc; }
void archivefiles(const char *const *argv) { const char *volatile thisarg; const char *const *volatile argp; jmp_buf ejbuf; int pi[2], fc, nfiles, c, i, r; FILE *pf; static struct varbuf findoutput; const char **arglist; char *p; trigproc_install_hooks(); modstatdb_init(admindir, f_noact ? msdbrw_readonly : cipaction->arg == act_avail ? msdbrw_write : fc_nonroot ? msdbrw_write : msdbrw_needsuperuser); checkpath(); log_message("startup archives %s", cipaction->olong); if (f_recursive) { if (!*argv) badusage(_("--%s --recursive needs at least one path argument"),cipaction->olong); m_pipe(pi); fc = subproc_fork(); if (!fc) { struct command cmd; const char *const *ap; m_dup2(pi[1],1); close(pi[0]); close(pi[1]); command_init(&cmd, FIND, _("find for dpkg --recursive")); command_add_args(&cmd, FIND, "-L", NULL); for (ap = argv; *ap; ap++) { if (strchr(FIND_EXPRSTARTCHARS,(*ap)[0])) { char *a; a= m_malloc(strlen(*ap)+10); strcpy(a,"./"); strcat(a,*ap); command_add_arg(&cmd, a); } else { command_add_arg(&cmd, (const char *)*ap); } } command_add_args(&cmd, "-name", "*.deb", "-type", "f", "-print0", NULL); command_exec(&cmd); } close(pi[1]); nfiles= 0; pf= fdopen(pi[0],"r"); if (!pf) ohshite(_("failed to fdopen find's pipe")); varbufreset(&findoutput); while ((c= fgetc(pf)) != EOF) { varbufaddc(&findoutput,c); if (!c) nfiles++; } if (ferror(pf)) ohshite(_("error reading find's pipe")); if (fclose(pf)) ohshite(_("error closing find's pipe")); r = subproc_wait_check(fc, "find", PROCNOERR); if (r != 0) ohshit(_("find for --recursive returned unhandled error %i"),r); if (!nfiles) ohshit(_("searched, but found no packages (files matching *.deb)")); varbufaddc(&findoutput,0); varbufaddc(&findoutput,0); arglist= m_malloc(sizeof(char*)*(nfiles+1)); p= findoutput.buf; i=0; while (*p) { arglist[i++]= p; while (*p++ != '\0') ; } arglist[i] = NULL; argp= arglist; } else { if (!*argv) badusage(_("--%s needs at least one package archive file argument"), cipaction->olong); argp= argv; } currenttime = time(NULL); /* Initialize fname variables contents. */ varbufreset(&fnamevb); varbufreset(&fnametmpvb); varbufreset(&fnamenewvb); varbufaddstr(&fnamevb,instdir); varbufaddc(&fnamevb,'/'); varbufaddstr(&fnametmpvb,instdir); varbufaddc(&fnametmpvb,'/'); varbufaddstr(&fnamenewvb,instdir); varbufaddc(&fnamenewvb,'/'); fnameidlu= fnamevb.used; ensure_diversions(); ensure_statoverrides(); while ((thisarg = *argp++) != NULL) { if (setjmp(ejbuf)) { pop_error_context(ehflag_bombout); if (abort_processing) break; continue; } push_error_context_jump(&ejbuf, print_error_perpackage, thisarg); process_archive(thisarg); onerr_abort++; m_output(stdout, _("<standard output>")); m_output(stderr, _("<standard error>")); onerr_abort--; pop_error_context(ehflag_normaltidy); } switch (cipaction->arg) { case act_install: case act_configure: case act_triggers: case act_remove: case act_purge: process_queue(); case act_unpack: case act_avail: break; default: internerr("unknown action '%d'", cipaction->arg); } trigproc_run_deferred(); modstatdb_shutdown(); }