int maintainer_script_alternative(struct pkginfo *pkg, const char *scriptname, const char *desc, const char *cidir, char *cidirrest, const char *ifok, const char *iffallback) { struct command cmd; const char *oldscriptpath; struct stat stab; char buf[100]; oldscriptpath = pkgadminfile(pkg, &pkg->installed, scriptname); sprintf(buf, _("old %s script"), desc); command_init(&cmd, oldscriptpath, buf); command_add_args(&cmd, scriptname, ifok, versiondescribe(&pkg->available.version, vdew_nonambig), NULL); if (stat(oldscriptpath,&stab)) { if (errno == ENOENT) { debug(dbg_scripts,"maintainer_script_alternative nonexistent %s `%s'", scriptname,oldscriptpath); command_destroy(&cmd); return 0; } warning(_("unable to stat %s '%.250s': %s"), cmd.name, oldscriptpath, strerror(errno)); } else { if (!do_script(pkg, &pkg->installed, &cmd, &stab, PROCWARN)) { command_destroy(&cmd); post_script_tasks(); return 1; } } fprintf(stderr, _("dpkg - trying script from the new package instead ...\n")); strcpy(cidirrest,scriptname); sprintf(buf, _("new %s script"), desc); command_destroy(&cmd); command_init(&cmd, cidir, buf); command_add_args(&cmd, scriptname, iffallback, versiondescribe(&pkg->installed.version, vdew_nonambig), NULL); if (stat(cidir,&stab)) { command_destroy(&cmd); if (errno == ENOENT) ohshit(_("there is no script in the new version of the package - giving up")); else ohshite(_("unable to stat %s `%.250s'"),buf,cidir); } do_script(pkg, &pkg->available, &cmd, &stab, 0); fprintf(stderr, _("dpkg: ... it looks like that went OK.\n")); command_destroy(&cmd); post_script_tasks(); return 1; }
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(); }