static void doRmSource(Spec spec) /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/ /*@modifies rpmGlobalMacroContext, fileSystem, internalState @*/ { struct Source *sp; int rc; #if 0 rc = Unlink(spec->specFile); #endif for (sp = spec->sources; sp != NULL; sp = sp->next) { const char *dn, *fn; if (sp->flags & RPMFILE_GHOST) continue; #if defined(RPM_VENDOR_OPENPKG) /* splitted-source-directory */ if (! (dn = getSourceDir(sp->flags, sp->source))) #else if (! (dn = getSourceDir(sp->flags))) #endif continue; fn = rpmGenPath(NULL, dn, sp->source); rc = Unlink(fn); fn = _free(fn); } }
FD_t rpmMkTempFile(const char * prefix, char **fn) { const char *tpmacro = "%{_tmppath}"; /* always set from rpmrc */ char *tempfn; static int _initialized = 0; FD_t tfd = NULL; if (!prefix) prefix = ""; /* Create the temp directory if it doesn't already exist. */ if (!_initialized) { _initialized = 1; tempfn = rpmGenPath(prefix, tpmacro, NULL); if (rpmioMkpath(tempfn, 0755, (uid_t) -1, (gid_t) -1)) goto exit; free(tempfn); } tempfn = rpmGetPath(prefix, tpmacro, "/rpm-tmp.XXXXXX", NULL); tfd = rpmMkTemp(tempfn); if (tfd == NULL || Ferror(tfd)) { rpmlog(RPMLOG_ERR, _("error creating temporary file %s: %m\n"), tempfn); goto exit; } exit: if (tfd != NULL && fn) *fn = tempfn; else free(tempfn); return tfd; }
/* * Source rpms only contain basenames, on install the full paths are * constructed with %{_specdir} and %{_sourcedir} macros. Because * of that regular relocation wont work, we need to do it the hard * way. Return spec file index on success, -1 on errors. */ int rpmRelocateSrpmFileList(Header h, const char *rootDir) { int specix = headerFindSpec(h); if (specix >= 0) { const char *bn; struct rpmtd_s filenames; /* save original file names */ saveOrig(h); headerDel(h, RPMTAG_BASENAMES); headerDel(h, RPMTAG_DIRNAMES); headerDel(h, RPMTAG_DIRINDEXES); /* Macros need to be added before trying to create directories */ rpmInstallLoadMacros(h, 1); /* ALLOC is needed as we modify the header */ headerGet(h, RPMTAG_ORIGBASENAMES, &filenames, HEADERGET_ALLOC); for (int i = 0; (bn = rpmtdNextString(&filenames)); i++) { int spec = (i == specix); char *fn = rpmGenPath(rootDir, spec ? "%{_specdir}" : "%{_sourcedir}", bn); headerPutString(h, RPMTAG_OLDFILENAMES, fn); free(fn); } rpmtdFreeData(&filenames); headerConvert(h, HEADERCONV_COMPRESSFILELIST); rpmInstallLoadMacros(h, 0); } return specix; }
rpmlua rpmluaNew() { rpmlua lua = (rpmlua) xcalloc(1, sizeof(*lua)); struct stat st; const luaL_Reg *lib; char *initlua = rpmGenPath(rpmConfigDir(), "init.lua", NULL); static const luaL_Reg extlibs[] = { {"posix", luaopen_posix}, {"rex", luaopen_rex}, {"rpm", luaopen_rpm}, {"os", luaopen_rpm_os}, {NULL, NULL}, }; lua_State *L = lua_open(); luaL_openlibs(L); lua->L = L; for (lib = extlibs; lib->name; lib++) { lua_pushcfunction(L, lib->func); lua_pushstring(L, lib->name); lua_call(L, 1, 0); lua_settop(L, 0); } #ifndef LUA_GLOBALSINDEX lua_pushglobaltable(L); #endif lua_pushliteral(L, "LUA_PATH"); lua_pushfstring(L, "%s/%s", rpmConfigDir(), "/lua/?.lua"); #ifdef LUA_GLOBALSINDEX lua_rawset(L, LUA_GLOBALSINDEX); #else lua_settable(L, -3); #endif lua_pushliteral(L, "print"); lua_pushcfunction(L, rpm_print); #ifdef LUA_GLOBALSINDEX lua_rawset(L, LUA_GLOBALSINDEX); #else lua_settable(L, -3); #endif #ifndef LUA_GLOBALSINDEX lua_pop(L, 1); #endif rpmluaSetData(lua, "lua", lua); if (stat(initlua, &st) != -1) (void)rpmluaRunScriptFile(lua, initlua); free(initlua); return lua; }
rpmtxn rpmtxnBegin(rpmts ts, rpmtxnFlags flags) { static const char * const rpmlock_path_default = "%{?_rpmlock_path}"; rpmtxn txn = NULL; if (ts == NULL) return NULL; if (ts->lockPath == NULL) { const char *rootDir = rpmtsRootDir(ts); char *t; if (!rootDir || rpmChrootDone()) rootDir = "/"; t = rpmGenPath(rootDir, rpmlock_path_default, NULL); if (t == NULL || *t == '\0' || *t == '%') { free(t); t = xstrdup(RPMLOCK_PATH); } ts->lockPath = xstrdup(t); (void) rpmioMkpath(dirname(t), 0755, getuid(), getgid()); free(t); } if (ts->lock == NULL) ts->lock = rpmlockNew(ts->lockPath, _("transaction")); if (rpmlockAcquire(ts->lock)) { txn = xcalloc(1, sizeof(*txn)); txn->lock = ts->lock; txn->flags = flags; txn->ts = rpmtsLink(ts); } return txn; }
void rpmRunFileTriggers(const char * rootDir) { miRE matches_any = mireNew(RPMMIRE_DEFAULT, 0); int nft = 0; struct filetrigger *list = NULL; const char * fn = NULL; FD_t fd = NULL; FILE * fp = NULL; int xx; rpmlog(RPMLOG_DEBUG, D_("[filetriggers] starting\n")); fn = rpmGenPath(rootDir, files_awaiting_filetriggers, NULL); if (!filetriggers_dir()) goto exit; getFiletriggers(rootDir, matches_any, &nft, &list); if (nft <= 0) goto exit; fd = Fopen(fn, "r.fpio"); if (fd == NULL) goto exit; fp = fdGetFILE(fd); if (fp != NULL) { void (*oldhandler)(int) = signal(SIGPIPE, SIG_IGN); char tmp[BUFSIZ]; int i; rpmlog(RPMLOG_DEBUG, D_("[filetriggers] testing files from list: %s\n"), fn); while (fgets(tmp, (int)sizeof(tmp), fp)) { size_t tmplen = strlen(tmp); if (tmplen > 0 && tmp[tmplen-1] == '\n') tmp[--tmplen] = '\0'; if (!is_regexp_matching(matches_any, tmp)) continue; rpmlog(RPMLOG_DEBUG, D_("[filetriggers] matches-any regexp found %s\n"), tmp); for (i = 0; i < nft; i++) { ssize_t nw; if (!is_regexp_matching(list[i].mire, tmp)) /*@innercontinue@*/ continue; rpmlog(RPMLOG_DEBUG, D_("[filetriggers] file name '%s' matches pattern '%s'\n"), tmp, list[i].mire->pattern); mayStartFiletrigger(rootDir, &list[i]); nw = write(list[i].command_pipe, tmp, tmplen); } } xx = Fclose(fd); fd = NULL; fp = NULL; for (i = 0; i < nft; i++) { int status; if (list[i].command_pipe) { pid_t pid; xx = close(list[i].command_pipe); rpmlog(RPMLOG_DEBUG, D_("[filetriggers] waiting for %s to end\n"), list[i].name); pid = waitpid(list[i].command_pid, &status, 0); list[i].command_pipe = 0; } } freeFiletriggers(matches_any, nft, list); oldhandler = signal(SIGPIPE, oldhandler); } exit: if (fn != NULL) xx = unlink(fn); fn = _free(fn); }
/** * Parse %setup macro. * @todo FIXME: Option -q broken when not immediately after %setup. * @param spec build info * @param line current line from spec file * @return RPMRC_OK on success */ static int doSetupMacro(rpmSpec spec, const char *line) { char *buf = NULL; StringBuf before = newStringBuf(); StringBuf after = newStringBuf(); poptContext optCon = NULL; int argc; const char ** argv = NULL; int arg; const char * optArg; int xx; rpmRC rc = RPMRC_FAIL; uint32_t num; int leaveDirs = 0, skipDefaultAction = 0; int createDir = 0, quietly = 0; const char * dirName = NULL; struct poptOption optionsTable[] = { { NULL, 'a', POPT_ARG_STRING, NULL, 'a', NULL, NULL}, { NULL, 'b', POPT_ARG_STRING, NULL, 'b', NULL, NULL}, { NULL, 'c', 0, &createDir, 0, NULL, NULL}, { NULL, 'D', 0, &leaveDirs, 0, NULL, NULL}, { NULL, 'n', POPT_ARG_STRING, &dirName, 0, NULL, NULL}, { NULL, 'T', 0, &skipDefaultAction, 0, NULL, NULL}, { NULL, 'q', 0, &quietly, 0, NULL, NULL}, { 0, 0, 0, 0, 0, NULL, NULL} }; if ((xx = poptParseArgvString(line, &argc, &argv))) { rpmlog(RPMLOG_ERR, _("Error parsing %%setup: %s\n"), poptStrerror(xx)); goto exit; } optCon = poptGetContext(NULL, argc, argv, optionsTable, 0); while ((arg = poptGetNextOpt(optCon)) > 0) { optArg = poptGetOptArg(optCon); /* We only parse -a and -b here */ if (parseUnsignedNum(optArg, &num)) { rpmlog(RPMLOG_ERR, _("line %d: Bad arg to %%setup: %s\n"), spec->lineNum, (optArg ? optArg : "???")); goto exit; } { char *chptr = doUntar(spec, num, quietly); if (chptr == NULL) goto exit; appendLineStringBuf((arg == 'a' ? after : before), chptr); free(chptr); } } if (arg < -1) { rpmlog(RPMLOG_ERR, _("line %d: Bad %%setup option %s: %s\n"), spec->lineNum, poptBadOption(optCon, POPT_BADOPTION_NOALIAS), poptStrerror(arg)); goto exit; } if (dirName) { spec->buildSubdir = xstrdup(dirName); } else { rasprintf(&spec->buildSubdir, "%s-%s", headerGetString(spec->packages->header, RPMTAG_NAME), headerGetString(spec->packages->header, RPMTAG_VERSION)); } addMacro(spec->macros, "buildsubdir", NULL, spec->buildSubdir, RMIL_SPEC); /* cd to the build dir */ { char * buildDir = rpmGenPath(spec->rootDir, "%{_builddir}", ""); rasprintf(&buf, "cd '%s'", buildDir); appendLineStringBuf(spec->prep, buf); free(buf); free(buildDir); } /* delete any old sources */ if (!leaveDirs) { rasprintf(&buf, "rm -rf '%s'", spec->buildSubdir); appendLineStringBuf(spec->prep, buf); free(buf); } /* if necessary, create and cd into the proper dir */ if (createDir) { rasprintf(&buf, RPM_MKDIR_P " %s\ncd '%s'", spec->buildSubdir, spec->buildSubdir); appendLineStringBuf(spec->prep, buf); free(buf); } /* do the default action */ if (!createDir && !skipDefaultAction) { char *chptr = doUntar(spec, 0, quietly); if (!chptr) goto exit; appendLineStringBuf(spec->prep, chptr); free(chptr); } appendStringBuf(spec->prep, getStringBuf(before)); if (!createDir) { rasprintf(&buf, "cd '%s'", spec->buildSubdir); appendLineStringBuf(spec->prep, buf); free(buf); } if (createDir && !skipDefaultAction) { char *chptr = doUntar(spec, 0, quietly); if (chptr == NULL) goto exit; appendLineStringBuf(spec->prep, chptr); free(chptr); } appendStringBuf(spec->prep, getStringBuf(after)); /* Fix the permissions of the setup build tree */ { char *fix = rpmExpand("%{_fixperms} .", NULL); if (fix && *fix != '%') { appendLineStringBuf(spec->prep, fix); } free(fix); } rc = RPMRC_OK; exit: freeStringBuf(before); freeStringBuf(after); poptFreeContext(optCon); free(argv); return rc; }
rpmRC rpmInstallSourcePackage(rpmts ts, FD_t fd, char ** specFilePtr, char ** cookie) { rpmfi fi = NULL; char * specFile = NULL; const char *rootdir = rpmtsRootDir(ts); Header h = NULL; rpmpsm psm = NULL; rpmte te = NULL; rpmRC rpmrc; int specix = -1; struct rpmtd_s filenames; rpmtdReset(&filenames); rpmrc = rpmReadPackageFile(ts, fd, NULL, &h); switch (rpmrc) { case RPMRC_NOTTRUSTED: case RPMRC_NOKEY: case RPMRC_OK: break; default: goto exit; break; } if (h == NULL) goto exit; rpmrc = RPMRC_FAIL; /* assume failure */ if (!headerIsSource(h)) { rpmlog(RPMLOG_ERR, _("source package expected, binary found\n")); goto exit; } /* src.rpm install can require specific rpmlib features, check them */ if (!rpmlibDeps(h)) goto exit; if (headerGet(h, RPMTAG_BASENAMES, &filenames, HEADERGET_ALLOC)) { struct rpmtd_s td; const char *str; const char *_cookie = headerGetString(h, RPMTAG_COOKIE); if (cookie && _cookie) *cookie = xstrdup(_cookie); /* Try to find spec by file flags */ if (_cookie && headerGet(h, RPMTAG_FILEFLAGS, &td, HEADERGET_MINMEM)) { rpmfileAttrs *flags; while (specix < 0 && (flags = rpmtdNextUint32(&td))) { if (*flags & RPMFILE_SPECFILE) specix = rpmtdGetIndex(&td); } } /* Still no spec? Look by filename. */ while (specix < 0 && (str = rpmtdNextString(&filenames))) { if (rpmFileHasSuffix(str, ".spec")) specix = rpmtdGetIndex(&filenames); } } if (rootdir && rstreq(rootdir, "/")) rootdir = NULL; /* Macros need to be added before trying to create directories */ rpmInstallLoadMacros(h); if (specix >= 0) { const char *bn; headerDel(h, RPMTAG_BASENAMES); headerDel(h, RPMTAG_DIRNAMES); headerDel(h, RPMTAG_DIRINDEXES); rpmtdInit(&filenames); for (int i = 0; (bn = rpmtdNextString(&filenames)); i++) { int spec = (i == specix); char *fn = rpmGenPath(rpmtsRootDir(ts), spec ? "%{_specdir}" : "%{_sourcedir}", bn); headerPutString(h, RPMTAG_OLDFILENAMES, fn); if (spec) specFile = xstrdup(fn); free(fn); } headerConvert(h, HEADERCONV_COMPRESSFILELIST); } else { rpmlog(RPMLOG_ERR, _("source package contains no .spec file\n")); goto exit; }; if (rpmtsAddInstallElement(ts, h, NULL, 0, NULL)) { goto exit; } te = rpmtsElement(ts, 0); if (te == NULL) { /* XXX can't happen */ goto exit; } rpmteSetFd(te, fd); rpmteSetHeader(te, h); fi = rpmfiNew(ts, h, RPMTAG_BASENAMES, RPMFI_KEEPHEADER); h = headerFree(h); if (fi == NULL) { goto exit; } fi->apath = filenames.data; /* Ick */ rpmteSetFI(te, fi); fi = rpmfiFree(fi); if (rpmMkdirs(rpmtsRootDir(ts), "%{_topdir}:%{_sourcedir}:%{_specdir}")) { goto exit; } { /* set all files to be installed */ rpmfs fs = rpmteGetFileStates(te); int i; unsigned int fc = rpmfiFC(fi); for (i=0; i<fc; i++) rpmfsSetAction(fs, i, FA_CREATE); } psm = rpmpsmNew(ts, te); psm->goal = PKG_INSTALL; /* FIX: psm->fi->dnl should be owned. */ if (rpmpsmStage(psm, PSM_PROCESS) == RPMRC_OK) rpmrc = RPMRC_OK; (void) rpmpsmStage(psm, PSM_FINI); rpmpsmFree(psm); exit: if (specFilePtr && specFile && rpmrc == RPMRC_OK) *specFilePtr = specFile; else free(specFile); headerFree(h); rpmfiFree(fi); /* XXX nuke the added package(s). */ rpmtsClean(ts); return rpmrc; }
/** * Check that all sources/patches/icons exist locally, fetching if necessary. */ static int prepFetch(Spec spec) /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/ /*@modifies rpmGlobalMacroContext, fileSystem, internalState @*/ { #if defined(RPM_VENDOR_OPENPKG) /* splitted-source-directory */ const char *Smacro; #endif const char *Lmacro, *Lurlfn = NULL; const char *Rmacro, *Rurlfn = NULL; struct Source *sp; struct stat st; rpmRC rpmrc; int ec, rc; char *cp; /* XXX insure that %{_sourcedir} exists */ rpmrc = RPMRC_OK; Lurlfn = rpmGenPath(NULL, "%{?_sourcedir}", NULL); if (Lurlfn != NULL && *Lurlfn != '\0') rpmrc = rpmMkdirPath(Lurlfn, "_sourcedir"); Lurlfn = _free(Lurlfn); if (rpmrc != RPMRC_OK) return -1; /* XXX insure that %{_patchdir} exists */ rpmrc = RPMRC_OK; Lurlfn = rpmGenPath(NULL, "%{?_patchdir}", NULL); if (Lurlfn != NULL && *Lurlfn != '\0') rpmrc = rpmMkdirPath(Lurlfn, "_patchdir"); Lurlfn = _free(Lurlfn); if (rpmrc != RPMRC_OK) return -1; /* XXX insure that %{_icondir} exists */ rpmrc = RPMRC_OK; Lurlfn = rpmGenPath(NULL, "%{?_icondir}", NULL); if (Lurlfn != NULL && *Lurlfn != '\0') rpmrc = rpmMkdirPath(Lurlfn, "_icondir"); Lurlfn = _free(Lurlfn); if (rpmrc != RPMRC_OK) return -1; if (rpmIsVerbose() && !quietly && (rpmBTArgs.buildAmount & RPMBUILD_FETCHSOURCE)) rpmlog(RPMLOG_NOTICE, "Checking source and patch file(s):\n"); ec = 0; for (sp = spec->sources; sp != NULL; sp = sp->next) { #if defined(RPM_VENDOR_OPENPKG) /* splitted-source-directory */ Smacro = "%{?_specdir}/"; #endif #if defined(RPM_VENDOR_OPENPKG) /* splitted-source-directory */ if (! (Lmacro = getSourceDir(sp->flags, sp->source))) #else if (! (Lmacro = getSourceDir(sp->flags))) #endif continue; if (sp->flags & RPMFILE_SOURCE) { Rmacro = "%{?_Rsourcedir}/"; } else if (sp->flags & RPMFILE_PATCH) { Rmacro = "%{?_Rpatchdir}/"; } else if (sp->flags & RPMFILE_ICON) { Rmacro = "%{?_Ricondir}/"; } else continue; #if defined(RPM_VENDOR_OPENPKG) /* splitted-source-directory */ /* support splitted source directories, i.e., source files which are alternatively placed into the .spec directory and picked up from there, too. */ Lurlfn = rpmGenPath(NULL, Smacro, sp->source); rc = Lstat(Lurlfn, &st); if (rc == 0) { prepFetchVerbose(sp, &st); goto bottom; } #endif Lurlfn = rpmGenPath(NULL, Lmacro, sp->source); rc = Lstat(Lurlfn, &st); if (rc == 0) { /*@-noeffect@*/ prepFetchVerbose(sp, &st); /*@=noeffect@*/ goto bottom; } /*@-noeffect@*/ prepFetchVerbose(sp, NULL); /*@=noeffect@*/ if (errno != ENOENT) { ec++; rpmlog(RPMLOG_ERR, _("Missing %s%d %s: %s\n"), ((sp->flags & RPMFILE_SOURCE) ? "Source" : "Patch"), sp->num, sp->source, strerror(ENOENT)); goto bottom; } /* try to fetch via macro-controlled remote locations */ cp = rpmExpand(Rmacro, NULL); if (cp != NULL && strcmp(cp, "/") != 0) { cp = _free(cp); Rurlfn = rpmGenPath(NULL, Rmacro, sp->source); if (!(Rurlfn == NULL || Rurlfn[0] == '\0' || !strcmp(Rurlfn, "/") || !strcmp(Lurlfn, Rurlfn))) { rpmlog(RPMLOG_NOTICE, _("Fetching(%s%d): %s\n"), (sp->flags & RPMFILE_SOURCE) ? "Source" : "Patch", sp->num, Rurlfn); rc = urlGetFile(Rurlfn, Lurlfn); if (rc == 0) goto bottom; else { rpmlog(RPMLOG_ERR, _("Fetching %s%d failed: %s\n"), (sp->flags & RPMFILE_SOURCE) ? "Source" : "Patch", sp->num, ftpStrerror(rc)); ec++; } } } cp = _free(cp); /* try to fetch from original location */ rpmlog(RPMLOG_NOTICE, _("Fetching(%s%d): %s\n"), (sp->flags & RPMFILE_SOURCE) ? "Source" : "Patch", sp->num, sp->fullSource); rc = urlGetFile(sp->fullSource, Lurlfn); if (rc == 0) goto bottom; else { rpmlog(RPMLOG_ERR, _("Fetching %s%d failed: %s\n"), (sp->flags & RPMFILE_SOURCE) ? "Source" : "Patch", sp->num, ftpStrerror(rc)); ec++; } rpmlog(RPMLOG_ERR, _("Missing %s%d: %s: %s\n"), ((sp->flags & RPMFILE_SOURCE) ? "Source" : "Patch"), sp->num, sp->source, strerror(ENOENT)); ec++; bottom: Lurlfn = _free(Lurlfn); Rurlfn = _free(Rurlfn); } return ec; }
/** * Parse %setup macro. * @todo FIXME: Option -q broken when not immediately after %setup. * @param spec build info * @param line current line from spec file * @return 0 on success */ static int doSetupMacro(Spec spec, const char * line) /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/ /*@modifies spec->buildSubdir, spec->macros, spec->prep, spec->packages->header, rpmGlobalMacroContext, fileSystem, internalState @*/ { char buf[BUFSIZ]; rpmiob before = NULL; rpmiob after = NULL; poptContext optCon; int argc; const char ** argv; int arg; const char * optArg; int rc; rpmuint32_t num; rpmRC ec = RPMRC_FAIL; /* XXX assume failure */ /*@-mods@*/ leaveDirs = skipDefaultAction = 0; createDir = quietly = 0; dirName = NULL; /*@=mods@*/ if ((rc = poptParseArgvString(line, &argc, &argv))) { rpmlog(RPMLOG_ERR, _("Error parsing %%setup: %s\n"), poptStrerror(rc)); goto exit; } before = rpmiobNew(0); after = rpmiobNew(0); optCon = poptGetContext(NULL, argc, argv, optionsTable, 0); while ((arg = poptGetNextOpt(optCon)) > 0) { optArg = poptGetOptArg(optCon); /* We only parse -a and -b here */ if (parseNum(optArg, &num)) { rpmlog(RPMLOG_ERR, _("line %d: Bad arg to %%setup: %s\n"), spec->lineNum, (optArg ? optArg : "???")); optCon = poptFreeContext(optCon); argv = _free(argv); goto exit; } { const char *chptr = doUntar(spec, num, quietly); if (chptr == NULL) goto exit; (void) rpmiobAppend((arg == 'a' ? after : before), chptr, 1); } } if (arg < -1) { rpmlog(RPMLOG_ERR, _("line %d: Bad %%setup option %s: %s\n"), spec->lineNum, poptBadOption(optCon, POPT_BADOPTION_NOALIAS), poptStrerror(arg)); optCon = poptFreeContext(optCon); argv = _free(argv); goto exit; } if (dirName) { spec->buildSubdir = xstrdup(dirName); } else { const char *N, *V; (void) headerNEVRA(spec->packages->header, &N, NULL, &V, NULL, NULL); (void) snprintf(buf, sizeof(buf), "%s-%s", N, V); buf[sizeof(buf)-1] = '\0'; N = _free(N); V = _free(V); spec->buildSubdir = xstrdup(buf); } addMacro(spec->macros, "buildsubdir", NULL, spec->buildSubdir, RMIL_SPEC); optCon = poptFreeContext(optCon); argv = _free(argv); /* cd to the build dir */ { const char * buildDirURL = rpmGenPath(spec->rootURL, "%{_builddir}", ""); const char *buildDir; (void) urlPath(buildDirURL, &buildDir); rc = rpmioMkpath(buildDir, 0755, -1, -1); sprintf(buf, "cd '%s'", buildDir); spec->prep = rpmiobAppend(spec->prep, buf, 1); buildDirURL = _free(buildDirURL); } /* delete any old sources */ if (!leaveDirs) { sprintf(buf, "rm -rf '%s'", spec->buildSubdir); spec->prep = rpmiobAppend(spec->prep, buf, 1); } /* check if source is a ruby gem */ { struct Source *sp; for (sp = spec->sources; sp != NULL; sp = sp->next) { if ((sp->flags & RPMFILE_SOURCE) && (sp->num == 0)) { break; } } if (sp != NULL) { char *t = strrchr(sp->source, '.'); if(t && !strcasecmp(t, ".gem")) createDir = 1; } } /* if necessary, create and cd into the proper dir */ if (createDir) { char *mkdir_p; mkdir_p = rpmExpand("%{?__mkdir_p}%{!?__mkdir_p:mkdir -p}", NULL); if (!mkdir_p) mkdir_p = xstrdup("mkdir -p"); sprintf(buf, "%s '%s'\ncd '%s'", mkdir_p, spec->buildSubdir, spec->buildSubdir); mkdir_p = _free(mkdir_p); spec->prep = rpmiobAppend(spec->prep, buf, 1); } /* do the default action */ if (!createDir && !skipDefaultAction) { const char *chptr = doUntar(spec, 0, quietly); if (chptr == NULL) goto exit; spec->prep = rpmiobAppend(spec->prep, chptr, 1); } spec->prep = rpmiobAppend(spec->prep, rpmiobStr(before), 0); if (!createDir) { sprintf(buf, "cd '%s'", spec->buildSubdir); spec->prep = rpmiobAppend(spec->prep, buf, 1); } if (createDir && !skipDefaultAction) { const char * chptr = doUntar(spec, 0, quietly); if (chptr == NULL) goto exit; spec->prep = rpmiobAppend(spec->prep, chptr, 1); } spec->prep = rpmiobAppend(spec->prep, rpmiobStr(after), 0); /* XXX FIXME: owner & group fixes were conditioned on !geteuid() */ /* Fix the owner, group, and permissions of the setup build tree */ { /*@observer@*/ static const char *fixmacs[] = { "%{_fixowner}", "%{_fixgroup}", "%{_fixperms}", NULL }; const char ** fm; for (fm = fixmacs; *fm; fm++) { const char *fix; fix = rpmExpand(*fm, " .", NULL); if (fix && *fix != '%') spec->prep = rpmiobAppend(spec->prep, fix, 1); fix = _free(fix); } } ec = RPMRC_OK; exit: before = rpmiobFree(before); after = rpmiobFree(after); return ec; }
/*@observer@*/ static const char *doUntar(Spec spec, rpmuint32_t c, int quietly) /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/ /*@modifies rpmGlobalMacroContext, fileSystem, internalState @*/ { const char *fn, *Lurlfn; static char buf[BUFSIZ]; char taropts[8]; char *t = NULL; struct Source *sp; rpmCompressedMagic compressed = COMPRESSED_NOT; int urltype; const char *tar; int rubygem = 0; for (sp = spec->sources; sp != NULL; sp = sp->next) { if ((sp->flags & RPMFILE_SOURCE) && (sp->num == c)) { break; } } if (sp == NULL) { rpmlog(RPMLOG_ERR, _("No source number %d\n"), c); return NULL; } t = strrchr(sp->source, '.'); if(t && !strcasecmp(t, ".gem")) rubygem = 1; t = stpcpy(taropts, "-x"); /*@-internalglobs@*/ /* FIX: shrug */ if(rpmIsVerbose() && !quietly) t = stpcpy(t, "vv"); if(rubygem) t = stpcpy(t, "m"); t = stpcpy(t, "f"); /*@=internalglobs@*/ #if defined(RPM_VENDOR_OPENPKG) /* splitted-source-directory */ Lurlfn = rpmGenPath(NULL, getSourceDir(sp->flags, sp->source), sp->source); #else Lurlfn = rpmGenPath(NULL, getSourceDir(sp->flags), sp->source); #endif /* XXX On non-build parse's, file cannot be stat'd or read */ if (!spec->force && (isCompressed(Lurlfn, &compressed) || checkOwners(Lurlfn))) { Lurlfn = _free(Lurlfn); return NULL; } fn = NULL; urltype = urlPath(Lurlfn, &fn); switch (urltype) { case URL_IS_HTTPS: /* XXX WRONG WRONG WRONG */ case URL_IS_HTTP: /* XXX WRONG WRONG WRONG */ case URL_IS_FTP: /* XXX WRONG WRONG WRONG */ case URL_IS_HKP: /* XXX WRONG WRONG WRONG */ case URL_IS_MONGO: /* XXX FIXME */ case URL_IS_PATH: case URL_IS_UNKNOWN: break; case URL_IS_DASH: Lurlfn = _free(Lurlfn); return NULL; /*@notreached@*/ break; } #ifdef NOTYET { rpmmg mg; _rpmmg_debug = 1; mg = rpmmgNew(NULL, 0); t = (char *) rpmmgFile(mg, fn); mg = rpmmgFree(mg); fprintf(stderr, "==> %s: %s\n", fn, t); t = _free(t); _rpmmg_debug = 0; } #endif tar = rpmGetPath("%{?__tar}", NULL); if (!(tar && *tar != '\0')) { tar = _free(tar); tar = xstrdup("tar"); } #if defined(RPM_VENDOR_ARK) /* use-gnu-tar-compression-detection */ /* We leave compression handling for all tar based files up to GNU tar */ if (compressed == COMPRESSED_ZIP) #else if (compressed != COMPRESSED_NOT) #endif { const char *zipper; int needtar = 1; switch (compressed) { case COMPRESSED_NOT: /* XXX can't happen */ case COMPRESSED_OTHER: t = "%{__gzip} -dc"; break; case COMPRESSED_BZIP2: t = "%{__bzip2} -dc"; break; case COMPRESSED_LZOP: t = "%{__lzop} -dc"; break; case COMPRESSED_LZMA: t = "%{__lzma} -dc"; break; case COMPRESSED_XZ: t = "%{__xz} -dc"; break; case COMPRESSED_LZIP: t = "%{__lzip} -dc"; break; case COMPRESSED_LRZIP: t = "%{__lrzip} -dqo-"; break; case COMPRESSED_7ZIP: t = "%{__7zip} x"; needtar = 0; break; case COMPRESSED_ZIP: #if defined(RPM_VENDOR_OPENPKG) /* use-bsdtar-for-zip-files */ t = "%{__bsdtar} -x -f"; #else if (rpmIsVerbose() && !quietly) t = "%{__unzip}"; else t = "%{__unzip} -qq"; #endif needtar = 0; break; } zipper = rpmGetPath(t, NULL); buf[0] = '\0'; t = stpcpy(buf, zipper); zipper = _free(zipper); *t++ = ' '; *t++ = '\''; t = stpcpy(t, fn); *t++ = '\''; if (needtar) { t = stpcpy(t, " | "); t = stpcpy(t, tar); t = stpcpy(t, " "); t = stpcpy(t, taropts); t = stpcpy(t, " -"); } t = stpcpy(t, "\n" "STATUS=$?\n" "if [ $STATUS -ne 0 ]; then\n" " exit $STATUS\n" "fi"); } else { buf[0] = '\0'; t = stpcpy(buf, tar); t = stpcpy(t, " "); t = stpcpy(t, taropts); *t++ = ' '; t = stpcpy(t, fn); if(rubygem) { t = stpcpy(t, "\n" "if [ -f data.tar.gz ]; then\n" " tar "); t = stpcpy(t, taropts); t = stpcpy(t, " data.tar.gz\n" "fi"); } } tar = _free(tar); Lurlfn = _free(Lurlfn); return buf; }
/* * @todo Single use by %%doc in files.c prevents static. */ rpmRC doScript(rpmSpec spec, rpmBuildFlags what, const char *name, const char *sb, int test) { const char * rootDir = spec->rootDir; char *scriptName = NULL; char * buildDir = rpmGenPath(rootDir, "%{_builddir}", ""); char * buildCmd = NULL; char * buildTemplate = NULL; char * buildPost = NULL; const char * mTemplate = NULL; const char * mCmd = NULL; const char * mPost = NULL; int argc = 0; const char **argv = NULL; FILE * fp = NULL; FD_t fd; FD_t xfd; pid_t pid; pid_t child; int status; rpmRC rc; switch (what) { case RPMBUILD_PREP: mTemplate = "%{__spec_prep_template}"; mPost = "%{__spec_prep_post}"; mCmd = "%{__spec_prep_cmd}"; break; case RPMBUILD_BUILD: mTemplate = "%{__spec_build_template}"; mPost = "%{__spec_build_post}"; mCmd = "%{__spec_build_cmd}"; break; case RPMBUILD_INSTALL: mTemplate = "%{__spec_install_template}"; mPost = "%{__spec_install_post}"; mCmd = "%{__spec_install_cmd}"; break; case RPMBUILD_CHECK: mTemplate = "%{__spec_check_template}"; mPost = "%{__spec_check_post}"; mCmd = "%{__spec_check_cmd}"; break; case RPMBUILD_CLEAN: mTemplate = "%{__spec_clean_template}"; mPost = "%{__spec_clean_post}"; mCmd = "%{__spec_clean_cmd}"; break; case RPMBUILD_RMBUILD: mTemplate = "%{__spec_clean_template}"; mPost = "%{__spec_clean_post}"; mCmd = "%{__spec_clean_cmd}"; break; case RPMBUILD_STRINGBUF: default: mTemplate = "%{___build_template}"; mPost = "%{___build_post}"; mCmd = "%{___build_cmd}"; break; } if ((what != RPMBUILD_RMBUILD) && sb == NULL) { rc = RPMRC_OK; goto exit; } fd = rpmMkTempFile(rootDir, &scriptName); if (fd == NULL || Ferror(fd)) { rpmlog(RPMLOG_ERR, _("Unable to open temp file.\n")); rc = RPMRC_FAIL; goto exit; } if (fdGetFILE(fd) == NULL) xfd = Fdopen(fd, "w.fpio"); else xfd = fd; if ((fp = fdGetFILE(xfd)) == NULL) { rc = RPMRC_FAIL; goto exit; } if (*rootDir == '\0') rootDir = "/"; buildTemplate = rpmExpand(mTemplate, NULL); buildPost = rpmExpand(mPost, NULL); (void) fputs(buildTemplate, fp); if (what != RPMBUILD_PREP && what != RPMBUILD_RMBUILD && spec->buildSubdir) fprintf(fp, "cd '%s'\n", spec->buildSubdir); if (what == RPMBUILD_RMBUILD) { if (spec->buildSubdir) fprintf(fp, "rm -rf '%s'\n", spec->buildSubdir); } else if (sb != NULL) fprintf(fp, "%s", sb); (void) fputs(buildPost, fp); (void) Fclose(xfd); if (test) { rc = RPMRC_OK; goto exit; } if (buildDir && buildDir[0] != '/') { rc = RPMRC_FAIL; goto exit; } buildCmd = rpmExpand(mCmd, " ", scriptName, NULL); (void) poptParseArgvString(buildCmd, &argc, &argv); rpmlog(RPMLOG_NOTICE, _("Executing(%s): %s\n"), name, buildCmd); if (!(child = fork())) { /* NSPR messes with SIGPIPE, reset to default for the kids */ signal(SIGPIPE, SIG_DFL); errno = 0; (void) execvp(argv[0], (char *const *)argv); rpmlog(RPMLOG_ERR, _("Exec of %s failed (%s): %s\n"), scriptName, name, strerror(errno)); _exit(127); /* exit 127 for compatibility with bash(1) */ } pid = waitpid(child, &status, 0); if (!WIFEXITED(status) || WEXITSTATUS(status)) { rpmlog(RPMLOG_ERR, _("Bad exit status from %s (%s)\n"), scriptName, name); rc = RPMRC_FAIL; } else rc = RPMRC_OK; exit: if (scriptName) { if (rc == RPMRC_OK) (void) unlink(scriptName); scriptName = _free(scriptName); } argv = _free(argv); buildCmd = _free(buildCmd); buildTemplate = _free(buildTemplate); buildPost = _free(buildPost); buildDir = _free(buildDir); return rc; }
static rpmRC handlePreambleTag(Spec spec, Package pkg, rpmTag tag, const char *macro, const char *lang) /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/ /*@modifies spec->macros, spec->st, spec->sources, spec->numSources, spec->noSource, spec->sourceHeader, spec->BANames, spec->BACount, spec->line, pkg->header, pkg->autoProv, pkg->autoReq, pkg->noarch, rpmGlobalMacroContext, fileSystem, internalState @*/ { HE_t he = memset(alloca(sizeof(*he)), 0, sizeof(*he)); char * field = spec->line; char * end; int multiToken = 0; rpmsenseFlags tagflags; int len; rpmuint32_t num; int rc; int xx; if (field == NULL) return RPMRC_FAIL; /* XXX can't happen */ /* Find the start of the "field" and strip trailing space */ while ((*field) && (*field != ':')) field++; if (*field != ':') { rpmlog(RPMLOG_ERR, _("line %d: Malformed tag: %s\n"), spec->lineNum, spec->line); return RPMRC_FAIL; } field++; SKIPSPACE(field); if (!*field) { /* Empty field */ rpmlog(RPMLOG_ERR, _("line %d: Empty tag: %s\n"), spec->lineNum, spec->line); return RPMRC_FAIL; } end = findLastChar(field); /* Validate tag data content. */ if (tagValidate(spec, tag, field) != RPMRC_OK) return RPMRC_FAIL; /* See if this is multi-token */ end = field; SKIPNONSPACE(end); if (*end != '\0') multiToken = 1; switch (tag) { case RPMTAG_NAME: case RPMTAG_VERSION: case RPMTAG_RELEASE: case RPMTAG_DISTEPOCH: case RPMTAG_URL: case RPMTAG_DISTTAG: case RPMTAG_REPOTAG: case RPMTAG_CVSID: case RPMTAG_BUGURL: SINGLE_TOKEN_ONLY; /* These macros are for backward compatibility */ if (tag == RPMTAG_VERSION) { if (strchr(field, '-') != NULL) { rpmlog(RPMLOG_ERR, _("line %d: Illegal char '-' in %s: %s\n"), spec->lineNum, "version", spec->line); return RPMRC_FAIL; } addMacro(spec->macros, "PACKAGE_VERSION", NULL, field, RMIL_OLDSPEC); } else if (tag == RPMTAG_RELEASE) { if (strchr(field, '-') != NULL) { rpmlog(RPMLOG_ERR, _("line %d: Illegal char '-' in %s: %s\n"), spec->lineNum, "release", spec->line); return RPMRC_FAIL; } addMacro(spec->macros, "PACKAGE_RELEASE", NULL, field, RMIL_OLDSPEC-1); } he->tag = tag; he->t = RPM_STRING_TYPE; he->p.str = field; he->c = 1; xx = headerPut(pkg->header, he, 0); break; case RPMTAG_GROUP: case RPMTAG_SUMMARY: #if defined(RPM_VENDOR_OPENPKG) /* make-class-available-as-macro */ case RPMTAG_CLASS: #endif (void) stashSt(spec, pkg->header, tag, lang); /*@fallthrough@*/ case RPMTAG_DISTRIBUTION: case RPMTAG_VENDOR: case RPMTAG_LICENSE: case RPMTAG_PACKAGER: if (!*lang) { he->tag = tag; he->t = RPM_STRING_TYPE; he->p.str = field; he->c = 1; xx = headerPut(pkg->header, he, 0); } else if (!(noLang && strcmp(lang, RPMBUILD_DEFAULT_LANG))) { (void) headerAddI18NString(pkg->header, tag, field, lang); } break; /* XXX silently ignore BuildRoot: */ case RPMTAG_BUILDROOT: SINGLE_TOKEN_ONLY; macro = NULL; #ifdef DYING buildRootURL = rpmGenPath(spec->rootURL, "%{?buildroot}", NULL); (void) urlPath(buildRootURL, &buildRoot); if (*buildRoot == '\0') buildRoot = "/"; if (!strcmp(buildRoot, "/")) { rpmlog(RPMLOG_ERR, _("BuildRoot can not be \"/\": %s\n"), spec->buildRootURL); buildRootURL = _free(buildRootURL); return RPMRC_FAIL; } buildRootURL = _free(buildRootURL); #endif break; case RPMTAG_KEYWORDS: case RPMTAG_VARIANTS: case RPMTAG_PREFIXES: addOrAppendListEntry(pkg->header, tag, field); he->tag = tag; xx = headerGet(pkg->header, he, 0); if (tag == RPMTAG_PREFIXES) while (he->c--) { if (he->p.argv[he->c][0] != '/') { rpmlog(RPMLOG_ERR, _("line %d: Prefixes must begin with \"/\": %s\n"), spec->lineNum, spec->line); he->p.ptr = _free(he->p.ptr); return RPMRC_FAIL; } len = (int)strlen(he->p.argv[he->c]); if (he->p.argv[he->c][len - 1] == '/' && len > 1) { rpmlog(RPMLOG_ERR, _("line %d: Prefixes must not end with \"/\": %s\n"), spec->lineNum, spec->line); he->p.ptr = _free(he->p.ptr); return RPMRC_FAIL; } } he->p.ptr = _free(he->p.ptr); break; case RPMTAG_DOCDIR: SINGLE_TOKEN_ONLY; if (field[0] != '/') { rpmlog(RPMLOG_ERR, _("line %d: Docdir must begin with '/': %s\n"), spec->lineNum, spec->line); return RPMRC_FAIL; } macro = NULL; delMacro(NULL, "_docdir"); addMacro(NULL, "_docdir", NULL, field, RMIL_SPEC); break; case RPMTAG_XMAJOR: case RPMTAG_XMINOR: case RPMTAG_EPOCH: SINGLE_TOKEN_ONLY; if (parseNum(field, &num)) { rpmlog(RPMLOG_ERR, _("line %d: %s takes an integer value: %s\n"), spec->lineNum, tagName(tag), spec->line); return RPMRC_FAIL; } he->tag = tag; he->t = RPM_UINT32_TYPE; he->p.ui32p = # he->c = 1; xx = headerPut(pkg->header, he, 0); break; case RPMTAG_AUTOREQPROV: pkg->autoReq = parseYesNo(field); pkg->autoProv = pkg->autoReq; break; case RPMTAG_AUTOREQ: pkg->autoReq = parseYesNo(field); break; case RPMTAG_AUTOPROV: pkg->autoProv = parseYesNo(field); break; case RPMTAG_SOURCE: case RPMTAG_PATCH: SINGLE_TOKEN_ONLY; macro = NULL; if ((rc = addSource(spec, pkg, field, tag))) return rc; break; case RPMTAG_ICON: SINGLE_TOKEN_ONLY; macro = NULL; if ((rc = addSource(spec, pkg, field, tag))) return rc; /* XXX the fetch/load of icon needs to be elsewhere. */ if ((rc = doIcon(spec, pkg->header))) return rc; break; case RPMTAG_NOSOURCE: case RPMTAG_NOPATCH: spec->noSource = 1; if ((rc = parseNoSource(spec, field, tag))) return rc; break; case RPMTAG_BUILDPREREQ: case RPMTAG_BUILDREQUIRES: if ((rc = parseBits(lang, buildScriptBits, &tagflags))) { rpmlog(RPMLOG_ERR, _("line %d: Bad %s: qualifiers: %s\n"), spec->lineNum, tagName(tag), spec->line); return rc; } if ((rc = parseRCPOT(spec, pkg, field, tag, 0, tagflags))) return rc; break; case RPMTAG_PREREQ: case RPMTAG_REQUIREFLAGS: if ((rc = parseBits(lang, installScriptBits, &tagflags))) { rpmlog(RPMLOG_ERR, _("line %d: Bad %s: qualifiers: %s\n"), spec->lineNum, tagName(tag), spec->line); return rc; } if ((rc = parseRCPOT(spec, pkg, field, tag, 0, tagflags))) return rc; break; /* Aliases for BuildRequires(hint): */ case RPMTAG_BUILDSUGGESTS: case RPMTAG_BUILDENHANCES: tagflags = RPMSENSE_MISSINGOK; if ((rc = parseRCPOT(spec, pkg, field, tag, 0, tagflags))) return rc; break; /* Aliases for Requires(hint): */ case RPMTAG_SUGGESTSFLAGS: case RPMTAG_ENHANCESFLAGS: tag = RPMTAG_REQUIREFLAGS; tagflags = RPMSENSE_MISSINGOK; if ((rc = parseRCPOT(spec, pkg, field, tag, 0, tagflags))) return rc; break; case RPMTAG_BUILDOBSOLETES: case RPMTAG_BUILDPROVIDES: case RPMTAG_BUILDCONFLICTS: case RPMTAG_CONFLICTFLAGS: case RPMTAG_OBSOLETEFLAGS: case RPMTAG_PROVIDEFLAGS: tagflags = RPMSENSE_ANY; if ((rc = parseRCPOT(spec, pkg, field, tag, 0, tagflags))) return rc; break; case RPMTAG_BUILDPLATFORMS: /* XXX needs pattern parsing */ case RPMTAG_EXCLUDEARCH: case RPMTAG_EXCLUSIVEARCH: case RPMTAG_EXCLUDEOS: case RPMTAG_EXCLUSIVEOS: addOrAppendListEntry(spec->sourceHeader, tag, field); break; case RPMTAG_BUILDARCHS: { const char ** BANames = NULL; int BACount = 0; if ((rc = poptParseArgvString(field, &BACount, &BANames))) { rpmlog(RPMLOG_ERR, _("line %d: Bad BuildArchitecture format: %s\n"), spec->lineNum, spec->line); return RPMRC_FAIL; } if (spec->toplevel) { if (BACount > 0 && BANames != NULL) { spec->BACount = BACount; spec->BANames = BANames; BANames = NULL; /* XXX don't free. */ } } else { if (BACount != 1 || strcmp(BANames[0], "noarch")) { rpmlog(RPMLOG_ERR, _("line %d: Only \"noarch\" sub-packages are supported: %s\n"), spec->lineNum, spec->line); BANames = _free(BANames); return RPMRC_FAIL; } pkg->noarch = 1; } BANames = _free(BANames); } break; default: macro = NULL; he->tag = tag; he->t = RPM_STRING_ARRAY_TYPE; he->p.argv= (const char **) &field; /* XXX NOCAST */ he->c = 1; he->append = 1; xx = headerPut(pkg->header, he, 0); he->append = 0; break; } /*@-usereleased@*/ if (macro) addMacro(spec->macros, macro, NULL, field, RMIL_SPEC); /*@=usereleased@*/ return RPMRC_OK; }
static int doIcon(Spec spec, Header h) /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/ /*@modifies h, rpmGlobalMacroContext, fileSystem, internalState @*/ { static size_t iconsize = 0; HE_t he = memset(alloca(sizeof(*he)), 0, sizeof(*he)); const char *fn, *Lurlfn = NULL; struct Source *sp; size_t nb; rpmuint8_t * icon; FD_t fd = NULL; int rc = RPMRC_FAIL; /* assume error */ int urltype; int xx; if (iconsize == 0) { iconsize = rpmExpandNumeric("%{?_build_iconsize}"); if (iconsize < 2048) iconsize = 2048; } icon = alloca(iconsize+1); for (sp = spec->sources; sp != NULL; sp = sp->next) { if (sp->flags & RPMFILE_ICON) break; } if (sp == NULL) { rpmlog(RPMLOG_ERR, _("No icon file in sources\n")); goto exit; } #if defined(RPM_VENDOR_OPENPKG) /* splitted-source-directory */ /* support splitted source directories, i.e., source files which are alternatively placed into the .spec directory and picked up from there, too. */ Lurlfn = rpmGenPath(NULL, "%{_specdir}/", sp->source); if (access(Lurlfn, F_OK) == -1) { Lurlfn = _free(Lurlfn); Lurlfn = rpmGenPath(NULL, "%{_icondir}/", sp->source); } #else Lurlfn = rpmGenPath(NULL, "%{_icondir}/", sp->source); #endif fn = NULL; urltype = urlPath(Lurlfn, &fn); switch (urltype) { case URL_IS_HTTPS: case URL_IS_HTTP: case URL_IS_FTP: case URL_IS_PATH: case URL_IS_UNKNOWN: break; case URL_IS_DASH: case URL_IS_HKP: case URL_IS_MONGO: /* XXX FIXME */ rpmlog(RPMLOG_ERR, _("Invalid icon URL: %s\n"), Lurlfn); goto exit; /*@notreached@*/ break; } fd = Fopen(fn, "r%{?_rpmgio}"); if (fd == NULL || Ferror(fd)) { rpmlog(RPMLOG_ERR, _("Unable to open icon %s: %s\n"), fn, Fstrerror(fd)); rc = RPMRC_FAIL; goto exit; } *icon = '\0'; nb = Fread(icon, sizeof(icon[0]), iconsize, fd); if (Ferror(fd) || nb == 0) { rpmlog(RPMLOG_ERR, _("Unable to read icon %s: %s\n"), fn, Fstrerror(fd)); goto exit; } if (nb >= iconsize) { rpmlog(RPMLOG_ERR, _("Icon %s is too big (max. %d bytes)\n"), fn, (int)iconsize); goto exit; } if (icon[0] == 'G' && icon[1] == 'I' && icon[2] == 'F') he->tag = RPMTAG_GIF; else if (icon[0] == '/' && icon[1] == '*' && icon[2] == ' ' && icon[3] == 'X' && icon[4] == 'P' && icon[5] == 'M') he->tag = RPMTAG_XPM; else he->tag = tagValue("Icon"); he->t = RPM_BIN_TYPE; he->p.ui8p = icon; he->c = (rpmTagCount)nb; xx = headerPut(h, he, 0); rc = 0; exit: if (fd) { (void) Fclose(fd); fd = NULL; } Lurlfn = _free(Lurlfn); return rc; }
/*@observer@*/ static char *doPatch(Spec spec, rpmuint32_t c, int strip, const char *db, int reverse, int removeEmpties, int fuzz, const char *subdir) /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/ /*@modifies rpmGlobalMacroContext, fileSystem, internalState @*/ { const char *fn, *Lurlfn; static char buf[BUFSIZ]; char args[BUFSIZ], *t = args; struct Source *sp; rpmCompressedMagic compressed = COMPRESSED_NOT; int urltype; const char *patch, *flags; *t = '\0'; if (db) t = stpcpy( stpcpy(t, "-b --suffix "), db); #if defined(RPM_VENDOR_OPENPKG) /* always-backup-on-patching */ /* always create backup files in OpenPKG */ else t = stpcpy(t, "-b --suffix .orig "); #endif if (subdir) t = stpcpy( stpcpy(t, "-d "), subdir); if (fuzz >= 0) { t = stpcpy(t, "-F "); sprintf(t, "%10.10d", fuzz); t += strlen(t); } if (reverse) t = stpcpy(t, " -R"); if (removeEmpties) t = stpcpy(t, " -E"); for (sp = spec->sources; sp != NULL; sp = sp->next) { if ((sp->flags & RPMFILE_PATCH) && (sp->num == c)) break; } if (sp == NULL) { rpmlog(RPMLOG_ERR, _("No patch number %d\n"), c); return NULL; } Lurlfn = rpmGenPath(NULL, "%{_patchdir}/", sp->source); /* XXX On non-build parse's, file cannot be stat'd or read */ if (!spec->force && (isCompressed(Lurlfn, &compressed) || checkOwners(Lurlfn))) { Lurlfn = _free(Lurlfn); return NULL; } fn = NULL; urltype = urlPath(Lurlfn, &fn); switch (urltype) { case URL_IS_HTTPS: /* XXX WRONG WRONG WRONG */ case URL_IS_HTTP: /* XXX WRONG WRONG WRONG */ case URL_IS_FTP: /* XXX WRONG WRONG WRONG */ case URL_IS_HKP: /* XXX WRONG WRONG WRONG */ case URL_IS_MONGO: /* XXX FIXME */ case URL_IS_PATH: case URL_IS_UNKNOWN: break; case URL_IS_DASH: Lurlfn = _free(Lurlfn); return NULL; /*@notreached@*/ break; } patch = rpmGetPath("%{?__patch}", NULL); if (!(patch && *patch != '\0')) { patch = _free(patch); patch = xstrdup("patch"); } flags = rpmExpand("%{?_default_patch_flags}%{!?_default_patch_flags:-s}", NULL); if (compressed) { const char *zipper; switch (compressed) { default: case COMPRESSED_NOT: /* XXX can't happen */ case COMPRESSED_OTHER: case COMPRESSED_ZIP: /* XXX wrong */ zipper = "%{__gzip}"; break; case COMPRESSED_BZIP2: zipper = "%{__bzip2}"; break; case COMPRESSED_LZOP: zipper = "%{__lzop}"; break; case COMPRESSED_LZMA: zipper = "%{__lzma}"; break; case COMPRESSED_XZ: zipper = "%{__xz}"; break; } zipper = rpmGetPath(zipper, NULL); sprintf(buf, "echo \"Patch #%d (%s):\"\n" "%s -d < '%s' | %s -p%d %s %s\n" "STATUS=$?\n" "if [ $STATUS -ne 0 ]; then\n" " exit $STATUS\n" "fi", c, /*@-moduncon@*/ (const char *) basename((char *)fn), /*@=moduncon@*/ zipper, fn, patch, strip, args, flags); zipper = _free(zipper); } else { sprintf(buf, "echo \"Patch #%d (%s):\"\n" "%s -p%d %s %s < '%s'", c, /*@-moduncon@*/ (const char *) basename((char *)fn), /*@=moduncon@*/ patch, strip, args, flags, fn); } patch = _free(patch); flags = _free(flags); Lurlfn = _free(Lurlfn); return buf; }
/* * Create a spec file object from a spec file * @param [String] filename Spec file path * @return [Spec] */ static VALUE spec_s_open(VALUE klass, VALUE filename) { #if RPM_VERSION_CODE < RPM_VERSION(4,1,0) Spec rspec; #else rpmts ts = NULL; #endif if (TYPE(filename) != T_STRING) { rb_raise(rb_eTypeError, "illegal argument type"); } #if RPM_VERSION_CODE < RPM_VERSION(4,1,0) switch (parseSpec(&rspec, RSTRING_PTR(filename), "/", NULL, 0, "", NULL, 1, 1)) { case 0: if (rspec != NULL) { break; } default: rb_raise(rb_eRuntimeError, "specfile `%s' parsing failed", RSTRING_PTR(filename)); } return Data_Wrap_Struct(klass, NULL, spec_free, rspec); #else ts = rpmtsCreate(); #if RPM_VERSION_CODE < RPM_VERSION(4,4,8) switch (parseSpec(ts, RSTRING_PTR(filename), "/", NULL, 0, "", NULL, 1, 1)) { #elif RPM_VERSION_CODE < RPM_VERSION(4,5,90) switch (parseSpec(ts, RSTRING_PTR(filename), "/", 0, "", NULL, 1, 1, 0)) { #elif RPM_VERSION_CODE < RPM_VERSION(5,0,0) switch (parseSpec(ts, RSTRING_PTR(filename), "/", NULL, 0, "", NULL, 1, 1)) { #else switch (parseSpec(ts, RSTRING_PTR(filename), "/", 0, "", NULL, 1, 1, 0)) { #endif case 0: if (ts != NULL) { break; } default: rb_raise(rb_eRuntimeError, "specfile `%s' parsing failed", RSTRING_PTR(filename)); } return Data_Wrap_Struct(klass, NULL, ts_free, ts); #endif } /* * * Alias for Spec#open */ VALUE rpm_spec_open(const char* filename) { return spec_s_open(rpm_cSpec, rb_str_new2(filename)); } /* * @return [String] Return Build root defined in the spec file */ VALUE rpm_spec_get_buildroot(VALUE spec) { #if RPM_VERSION_CODE < RPM_VERSION(4,5,90) if (RPM_SPEC(spec)->buildRootURL) { return rb_str_new2(RPM_SPEC(spec)->buildRootURL); } #elif RPM_VERSION_CODE < RPM_VERSION(4,5,90) if (RPM_SPEC(spec)->rootURL) { return rb_str_new2(RPM_SPEC(spec)->rootURL); } #elif RPM_VERSION_CODE < RPM_VERSION(5,0,0) if (RPM_SPEC(spec)->buildRoot) { return rb_str_new2(RPM_SPEC(spec)->buildRoot); } #else const char *buildRootURL = rpmGenPath(RPM_SPEC(spec)->rootURL, "%{?buildroot}", NULL); VALUE result = rb_str_new2(buildRootURL); buildRootURL = _free(buildRootURL); return result; #endif return Qnil; } /* * @return [String] Return Build subdirectory defined in the spec file */ VALUE rpm_spec_get_buildsubdir(VALUE spec) { if (RPM_SPEC(spec)->buildSubdir) { return rb_str_new2(RPM_SPEC(spec)->buildSubdir); } return Qnil; } /* * @return [Array<String>] Return Build architectures defined in the spec file */ VALUE rpm_spec_get_buildarchs(VALUE spec) { VALUE ba = rb_ivar_get(spec, id_ba); if (NIL_P(ba)) { register int i; ba = rb_ary_new(); for (i = 0; i < RPM_SPEC(spec)->BACount; i++) { rb_ary_push(ba, rb_str_new2(RPM_SPEC(spec)->BANames[i])); } rb_ivar_set(spec, id_ba, ba); } return ba; } /* * @return [Array<RPM::Require>] Return Build requires defined in the spec file */ VALUE rpm_spec_get_buildrequires(VALUE spec) { VALUE br = rb_ivar_get(spec, id_br); #if RPM_VERSION_CODE < RPM_VERSION(4,6,0) || RPM_VERSION_CODE >= RPM_VERSION(5,0,0) if (NIL_P(br)) { const char** names; const char** vers; int_32* flags; int_32 count; rpmTagType nt, vt, type; register int i; br = rb_ary_new(); if (!headerGetEntryMinMemory(RPM_SPEC(spec)->buildRestrictions, RPMTAG_REQUIRENAME, (hTYP_t)&nt, (hPTR_t*)&names, (hCNT_t)&count)) { goto leave; } get_entry(RPM_SPEC(spec)->buildRestrictions, RPMTAG_REQUIREVERSION, &vt, (void*)&vers); get_entry(RPM_SPEC(spec)->buildRestrictions, RPMTAG_REQUIREFLAGS, &type, (void*)&flags); for (i = 0; i < count; i++) { rb_ary_push(br, rpm_require_new(names[i], rpm_version_new(vers[i]), flags[i], spec)); } release_entry(nt, names); release_entry(vt, vers); rb_ivar_set(spec, id_br, br); } leave: return br; #else rpmtd nametd = rpmtdNew(); rpmtd versiontd = rpmtdNew(); rpmtd flagtd = rpmtdNew(); if (NIL_P(br)) { br = rb_ary_new(); if (!headerGet(RPM_SPEC(spec)->buildRestrictions, RPMTAG_REQUIRENAME, nametd, HEADERGET_MINMEM)) { goto leave; } get_entry(RPM_SPEC(spec)->buildRestrictions, RPMTAG_REQUIREVERSION, versiontd); get_entry(RPM_SPEC(spec)->buildRestrictions, RPMTAG_REQUIREFLAGS, flagtd); rpmtdInit(nametd); while ( rpmtdNext(nametd) != -1 ) { rb_ary_push(br, rpm_require_new(rpmtdGetString(nametd), rpm_version_new(rpmtdNextString(versiontd)), *rpmtdNextUint32(flagtd), spec)); } rb_ivar_set(spec, id_br, br); } leave: rpmtdFree(nametd); rpmtdFree(versiontd); rpmtdFree(flagtd); return br; #endif } /* * @return [Array<RPM::Conflict>] Return Build conflicts defined in the spec file */ VALUE rpm_spec_get_buildconflicts(VALUE spec) { VALUE bc = rb_ivar_get(spec, id_bc); #if RPM_VERSION_CODE < RPM_VERSION(4,6,0) || RPM_VERSION_CODE >= RPM_VERSION(5,0,0) if (NIL_P(bc)) { const char** names; const char** vers; int_32* flags; int_32 count; rpmTagType nt, vt, type; register int i; bc = rb_ary_new(); if (!headerGetEntryMinMemory(RPM_SPEC(spec)->buildRestrictions, RPMTAG_CONFLICTNAME, (hTYP_t)&nt, (hPTR_t*)&names, (hCNT_t)&count)) { goto leave; } get_entry(RPM_SPEC(spec)->buildRestrictions, RPMTAG_CONFLICTVERSION, &vt, (void*)&vers); get_entry(RPM_SPEC(spec)->buildRestrictions, RPMTAG_CONFLICTFLAGS, &type, (void*)&flags); for (i = 0; i < count; i++) { rb_ary_push(bc, rpm_conflict_new(names[i], rpm_version_new(vers[i]), flags[i], spec)); } release_entry(nt, names); release_entry(vt, vers); rb_ivar_set(spec, id_bc, bc); } leave: return bc; #else rpmtd nametd = rpmtdNew(); rpmtd versiontd = rpmtdNew(); rpmtd flagtd = rpmtdNew(); if (NIL_P(bc)) { bc = rb_ary_new(); if (!headerGet(RPM_SPEC(spec)->buildRestrictions, RPMTAG_CONFLICTNAME, nametd, HEADERGET_MINMEM)) { goto leave; } get_entry(RPM_SPEC(spec)->buildRestrictions, RPMTAG_CONFLICTVERSION, versiontd); get_entry(RPM_SPEC(spec)->buildRestrictions, RPMTAG_CONFLICTFLAGS, flagtd); rpmtdInit(nametd); while ( rpmtdNext(nametd) != -1) { rb_ary_push(bc, rpm_conflict_new(rpmtdGetString(nametd), rpm_version_new(rpmtdNextString(versiontd)), *rpmtdNextUint32(flagtd), spec)); } rb_ivar_set(spec, id_bc, bc); } leave: rpmtdFree(nametd); rpmtdFree(versiontd); rpmtdFree(flagtd); return bc; #endif }
static int db_init(dbiIndex dbi, const char * dbhome, const char * dbfile, const char * dbsubfile, DB_ENV ** dbenvp) { rpmdb rpmdb = dbi->dbi_rpmdb; DB_ENV *dbenv = NULL; int eflags; int rc; if (dbenvp == NULL) return 1; /* XXX HACK */ if (rpmdb->db_errfile == NULL) rpmdb->db_errfile = stderr; eflags = (dbi->dbi_oeflags | dbi->dbi_eflags); if (eflags & DB_JOINENV) eflags &= DB_JOINENV; if (dbfile) { char *dbiflags = prDbiOpenFlags(eflags, 1); rpmlog(RPMLOG_DEBUG, "opening db environment %s/%s %s\n", dbhome, dbfile, dbiflags); free(dbiflags); } /* XXX Can't do RPC w/o host. */ if (dbi->dbi_host == NULL) dbi->dbi_ecflags &= ~DB_CLIENT; /* XXX Set a default shm_key. */ if ((dbi->dbi_eflags & DB_SYSTEM_MEM) && dbi->dbi_shmkey == 0) { #if defined(HAVE_FTOK) dbi->dbi_shmkey = ftok(dbhome, 0); #else dbi->dbi_shmkey = 0x44631380; #endif } rc = db_env_create(&dbenv, dbi->dbi_ecflags); rc = cvtdberr(dbi, "db_env_create", rc, _debug); if (dbenv == NULL || rc) goto errxit; { int xx; /* 4.1: dbenv->set_app_dispatch(???) */ /* 4.1: dbenv->set_alloc(???) */ /* 4.1: dbenv->set_data_dir(???) */ /* 4.1: dbenv->set_encrypt(???) */ dbenv->set_errcall(dbenv, (void *) rpmdb->db_errcall); dbenv->set_errfile(dbenv, rpmdb->db_errfile); dbenv->set_errpfx(dbenv, rpmdb->db_errpfx); /* 4.1: dbenv->set_feedback(???) */ /* 4.1: dbenv->set_flags(???) */ /* dbenv->set_paniccall(???) */ #if (DB_VERSION_MAJOR >= 4 && DB_VERSION_MINOR >= 5) /* * These enable automatic stale lock removal. * thread_count 8 is some kind of "magic minimum" value... */ dbenv->set_thread_count(dbenv, 8); dbenv->set_isalive(dbenv, db3isalive); #endif if ((dbi->dbi_ecflags & DB_CLIENT) && dbi->dbi_host) { const char * home; int retry = 0; if ((home = strrchr(dbhome, '/')) != NULL) dbhome = ++home; while (retry++ < 5) { xx = dbenv->set_rpc_server(dbenv, NULL, dbi->dbi_host, dbi->dbi_cl_timeout, dbi->dbi_sv_timeout, 0); xx = cvtdberr(dbi, "dbenv->set_server", xx, _debug); if (!xx) break; (void) sleep(15); } } else { #if !(DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 3) xx = dbenv->set_verbose(dbenv, DB_VERB_CHKPOINT, (dbi->dbi_verbose & DB_VERB_CHKPOINT)); #endif xx = dbenv->set_verbose(dbenv, DB_VERB_DEADLOCK, (dbi->dbi_verbose & DB_VERB_DEADLOCK)); xx = dbenv->set_verbose(dbenv, DB_VERB_RECOVERY, (dbi->dbi_verbose & DB_VERB_RECOVERY)); xx = dbenv->set_verbose(dbenv, DB_VERB_WAITSFOR, (dbi->dbi_verbose & DB_VERB_WAITSFOR)); if (dbi->dbi_mmapsize) { xx = dbenv->set_mp_mmapsize(dbenv, dbi->dbi_mmapsize); xx = cvtdberr(dbi, "dbenv->set_mp_mmapsize", xx, _debug); } if (dbi->dbi_tmpdir) { const char * root; char * tmpdir; root = (dbi->dbi_root ? dbi->dbi_root : rpmdb->db_root); if ((root[0] == '/' && root[1] == '\0') || rpmdb->db_chrootDone) root = NULL; tmpdir = rpmGenPath(root, dbi->dbi_tmpdir, NULL); xx = dbenv->set_tmp_dir(dbenv, tmpdir); xx = cvtdberr(dbi, "dbenv->set_tmp_dir", xx, _debug); tmpdir = _free(tmpdir); } } /* dbenv->set_lk_conflicts(???) */ /* dbenv->set_lk_detect(???) */ /* 4.1: dbenv->set_lk_max_lockers(???) */ /* 4.1: dbenv->set_lk_max_locks(???) */ /* 4.1: dbenv->set_lk_max_objects(???) */ /* 4.1: dbenv->set_lg_bsize(???) */ /* 4.1: dbenv->set_lg_dir(???) */ /* 4.1: dbenv->set_lg_max(???) */ /* 4.1: dbenv->set_lg_regionmax(???) */ if (dbi->dbi_cachesize) { xx = dbenv->set_cachesize(dbenv, 0, dbi->dbi_cachesize, 0); xx = cvtdberr(dbi, "dbenv->set_cachesize", xx, _debug); } /* 4.1 dbenv->set_timeout(???) */ /* dbenv->set_tx_max(???) */ /* 4.1: dbenv->set_tx_timestamp(???) */ /* dbenv->set_tx_recover(???) */ /* dbenv->set_rep_transport(???) */ /* dbenv->set_rep_limit(???) */ if (dbi->dbi_no_fsync) { xx = db_env_set_func_fsync(db3_fsync_disable); xx = cvtdberr(dbi, "db_env_set_func_fsync", xx, _debug); } if (dbi->dbi_shmkey) { xx = dbenv->set_shm_key(dbenv, dbi->dbi_shmkey); xx = cvtdberr(dbi, "dbenv->set_shm_key", xx, _debug); } } rc = (dbenv->open)(dbenv, dbhome, eflags, dbi->dbi_perms); rc = cvtdberr(dbi, "dbenv->open", rc, _debug); if (rc) goto errxit; #if (DB_VERSION_MAJOR >= 4 && DB_VERSION_MINOR >= 5) /* stale lock removal */ rc = dbenv->failchk(dbenv, 0); rc = cvtdberr(dbi, "dbenv->failchk", rc, _debug); if (rc) goto errxit; #endif *dbenvp = dbenv; return 0; errxit: if (dbenv) { int xx; xx = dbenv->close(dbenv, 0); xx = cvtdberr(dbi, "dbenv->close", xx, _debug); } return rc; }
poptContext rpmcliInit(int argc, char *const argv[], struct poptOption * optionsTable) { poptContext optCon; int rc; const char *ctx, *execPath; setprogname(argv[0]); /* Retrofit glibc __progname */ /* XXX glibc churn sanity */ if (__progname == NULL) { if ((__progname = strrchr(argv[0], '/')) != NULL) __progname++; else __progname = argv[0]; } #if defined(ENABLE_NLS) (void) setlocale(LC_ALL, "" ); (void) bindtextdomain(PACKAGE, LOCALEDIR); (void) textdomain(PACKAGE); #endif rpmSetVerbosity(RPMLOG_NOTICE); if (optionsTable == NULL) { /* Read rpm configuration (if not already read). */ rpmcliConfigured(); return NULL; } /* XXX hack to get popt working from build tree wrt lt-foo names */ ctx = rstreqn(__progname, "lt-", 3) ? __progname + 3 : __progname; optCon = poptGetContext(ctx, argc, (const char **)argv, optionsTable, 0); { char *poptfile = rpmGenPath(rpmConfigDir(), LIBRPMALIAS_FILENAME, NULL); (void) poptReadConfigFile(optCon, poptfile); free(poptfile); } (void) poptReadDefaultConfig(optCon, 1); if ((execPath = getenv("RPM_POPTEXEC_PATH")) == NULL) execPath = LIBRPMALIAS_EXECPATH; poptSetExecPath(optCon, execPath, 1); /* Process all options, whine if unknown. */ while ((rc = poptGetNextOpt(optCon)) > 0) { fprintf(stderr, _("%s: option table misconfigured (%d)\n"), __progname, rc); exit(EXIT_FAILURE); } if (rc < -1) { fprintf(stderr, "%s: %s: %s\n", __progname, poptBadOption(optCon, POPT_BADOPTION_NOALIAS), poptStrerror(rc)); exit(EXIT_FAILURE); } /* Read rpm configuration (if not already read). */ rpmcliConfigured(); if (_debug) { rpmIncreaseVerbosity(); rpmIncreaseVerbosity(); } return optCon; }
static int db3close(dbiIndex dbi, unsigned int flags) { rpmdb rpmdb = dbi->dbi_rpmdb; const char * root; const char * home; char * dbhome; const char * dbfile; const char * dbsubfile; DB * db = dbi->dbi_db; int _printit; int rc = 0, xx; flags = 0; /* XXX unused */ /* * Get the prefix/root component and directory path. */ root = (dbi->dbi_root ? dbi->dbi_root : rpmdb->db_root); if ((root[0] == '/' && root[1] == '\0') || rpmdb->db_chrootDone) root = NULL; home = (dbi->dbi_home ? dbi->dbi_home : rpmdb->db_home); dbhome = rpmGenPath(root, home, NULL); if (dbi->dbi_temporary) { dbfile = NULL; dbsubfile = NULL; } else { #ifdef HACK /* XXX necessary to support dbsubfile */ dbfile = (dbi->dbi_file ? dbi->dbi_file : db3basename); dbsubfile = (dbi->dbi_subfile ? dbi->dbi_subfile : rpmTagGetName(dbi->dbi_rpmtag)); #else dbfile = (dbi->dbi_file ? dbi->dbi_file : rpmTagGetName(dbi->dbi_rpmtag)); dbsubfile = NULL; #endif } if (db) { rc = db->close(db, 0); /* XXX ignore not found error messages. */ _printit = (rc == ENOENT ? 0 : _debug); rc = cvtdberr(dbi, "db->close", rc, _printit); db = dbi->dbi_db = NULL; rpmlog(RPMLOG_DEBUG, "closed db index %s/%s\n", dbhome, (dbfile ? dbfile : rpmTagGetName(dbi->dbi_rpmtag))); } if (rpmdb->db_dbenv != NULL && dbi->dbi_use_dbenv) { if (rpmdb->db_opens == 1) { xx = db_fini(dbi, (dbhome ? dbhome : ""), dbfile, dbsubfile); rpmdb->db_dbenv = NULL; } rpmdb->db_opens--; } if (dbi->dbi_verify_on_close && !dbi->dbi_temporary) { DB_ENV * dbenv = NULL; rc = db_env_create(&dbenv, 0); rc = cvtdberr(dbi, "db_env_create", rc, _debug); if (rc || dbenv == NULL) goto exit; dbenv->set_errcall(dbenv, (void *) rpmdb->db_errcall); dbenv->set_errfile(dbenv, rpmdb->db_errfile); dbenv->set_errpfx(dbenv, rpmdb->db_errpfx); /* dbenv->set_paniccall(???) */ #if !(DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 3) xx = dbenv->set_verbose(dbenv, DB_VERB_CHKPOINT, (dbi->dbi_verbose & DB_VERB_CHKPOINT)); #endif xx = dbenv->set_verbose(dbenv, DB_VERB_DEADLOCK, (dbi->dbi_verbose & DB_VERB_DEADLOCK)); xx = dbenv->set_verbose(dbenv, DB_VERB_RECOVERY, (dbi->dbi_verbose & DB_VERB_RECOVERY)); xx = dbenv->set_verbose(dbenv, DB_VERB_WAITSFOR, (dbi->dbi_verbose & DB_VERB_WAITSFOR)); if (dbi->dbi_tmpdir) { char * tmpdir = rpmGenPath(root, dbi->dbi_tmpdir, NULL); rc = dbenv->set_tmp_dir(dbenv, tmpdir); rc = cvtdberr(dbi, "dbenv->set_tmp_dir", rc, _debug); tmpdir = _free(tmpdir); if (rc) goto exit; } rc = (dbenv->open)(dbenv, dbhome, DB_CREATE | DB_INIT_MPOOL | DB_PRIVATE | DB_USE_ENVIRON, 0); rc = cvtdberr(dbi, "dbenv->open", rc, _debug); if (rc) goto exit; rc = db_create(&db, dbenv, 0); rc = cvtdberr(dbi, "db_create", rc, _debug); if (db != NULL) { char * dbf = rpmGetPath(dbhome, "/", dbfile, NULL); rc = db->verify(db, dbf, NULL, NULL, flags); rc = cvtdberr(dbi, "db->verify", rc, _debug); rpmlog(RPMLOG_DEBUG, "verified db index %s/%s\n", (dbhome ? dbhome : ""), (dbfile ? dbfile : rpmTagGetName(dbi->dbi_rpmtag))); /* * The DB handle may not be accessed again after * DB->verify is called, regardless of its return. */ db = NULL; dbf = _free(dbf); } xx = dbenv->close(dbenv, 0); xx = cvtdberr(dbi, "dbenv->close", xx, _debug); if (rc == 0 && xx) rc = xx; } exit: dbi->dbi_db = NULL; free(dbhome); dbi = db3Free(dbi); return rc; }
/* * @todo Single use by %%doc in files.c prevents static. */ rpmRC doScript(Spec spec, int what, const char *name, rpmiob iob, int test) { const char * rootURL = spec->rootURL; const char * rootDir; const char * scriptName = NULL; const char * buildDirURL = rpmGenPath(rootURL, "%{_builddir}", ""); const char * buildScript; const char * buildCmd = NULL; const char * buildTemplate = NULL; const char * buildPost = NULL; const char * mTemplate = NULL; const char * mCmd = NULL; const char * mPost = NULL; int argc = 0; const char **argv = NULL; FILE * fp = NULL; urlinfo u = NULL; rpmop op = NULL; int ix = -1; FD_t fd; FD_t xfd; int status; rpmRC rc; size_t i; switch (what) { case RPMBUILD_PREP: name = "%prep"; iob = spec->prep; op = memset(alloca(sizeof(*op)), 0, sizeof(*op)); ix = RPMSCRIPT_PREP; mTemplate = "%{__spec_prep_template}"; mPost = "%{__spec_prep_post}"; mCmd = "%{__spec_prep_cmd}"; break; case RPMBUILD_BUILD: name = "%build"; iob = spec->build; op = memset(alloca(sizeof(*op)), 0, sizeof(*op)); ix = RPMSCRIPT_BUILD; mTemplate = "%{__spec_build_template}"; mPost = "%{__spec_build_post}"; mCmd = "%{__spec_build_cmd}"; break; case RPMBUILD_INSTALL: name = "%install"; iob = spec->install; op = memset(alloca(sizeof(*op)), 0, sizeof(*op)); ix = RPMSCRIPT_INSTALL; mTemplate = "%{__spec_install_template}"; mPost = "%{__spec_install_post}"; mCmd = "%{__spec_install_cmd}"; break; case RPMBUILD_CHECK: name = "%check"; iob = spec->check; op = memset(alloca(sizeof(*op)), 0, sizeof(*op)); ix = RPMSCRIPT_CHECK; mTemplate = "%{__spec_check_template}"; mPost = "%{__spec_check_post}"; mCmd = "%{__spec_check_cmd}"; break; case RPMBUILD_CLEAN: name = "%clean"; iob = spec->clean; mTemplate = "%{__spec_clean_template}"; mPost = "%{__spec_clean_post}"; mCmd = "%{__spec_clean_cmd}"; break; case RPMBUILD_RMBUILD: name = "--clean"; mTemplate = "%{__spec_clean_template}"; mPost = "%{__spec_clean_post}"; mCmd = "%{__spec_clean_cmd}"; break; /* support "%track" script/section */ case RPMBUILD_TRACK: name = "%track"; iob = NULL; if (spec->foo) for (i = 0; i < spec->nfoo; i++) { if (spec->foo[i].str == NULL || spec->foo[i].iob == NULL) continue; if (xstrcasecmp(spec->foo[i].str, "track")) continue; iob = spec->foo[i].iob; /*@loopbreak@*/ break; } mTemplate = "%{__spec_track_template}"; mPost = "%{__spec_track_post}"; mCmd = "%{__spec_track_cmd}"; break; case RPMBUILD_STRINGBUF: default: mTemplate = "%{___build_template}"; mPost = "%{___build_post}"; mCmd = "%{___build_cmd}"; break; } assert(name != NULL); if ((what != RPMBUILD_RMBUILD) && iob == NULL) { rc = RPMRC_OK; goto exit; } if (rpmTempFile(rootURL, &scriptName, &fd) || fd == NULL || Ferror(fd)) { rpmlog(RPMLOG_ERR, _("Unable to open temp file.\n")); rc = RPMRC_FAIL; goto exit; } if (fdGetFp(fd) == NULL) xfd = Fdopen(fd, "w.fpio"); else xfd = fd; /*@-type@*/ /* FIX: cast? */ if ((fp = fdGetFp(xfd)) == NULL) { rc = RPMRC_FAIL; goto exit; } /*@=type@*/ (void) urlPath(rootURL, &rootDir); if (*rootDir == '\0') rootDir = "/"; (void) urlPath(scriptName, &buildScript); buildTemplate = rpmExpand(mTemplate, NULL); buildPost = rpmExpand(mPost, NULL); (void) fputs(buildTemplate, fp); /* support "%track" script/section */ if (what != RPMBUILD_PREP && what != RPMBUILD_RMBUILD && spec->buildSubdir && what != RPMBUILD_TRACK) fprintf(fp, "cd '%s'\n", spec->buildSubdir); if (what == RPMBUILD_RMBUILD) { if (spec->buildSubdir) fprintf(fp, "rm -rf '%s'\n", spec->buildSubdir); } else if (iob != NULL) fprintf(fp, "%s", rpmiobStr(iob)); (void) fputs(buildPost, fp); (void) Fclose(xfd); if (test) { rc = RPMRC_OK; goto exit; } if (buildDirURL && buildDirURL[0] != '/' && (urlSplit(buildDirURL, &u) != 0)) { rc = RPMRC_FAIL; goto exit; } switch (urlType(u)) { case URL_IS_HTTPS: case URL_IS_HTTP: case URL_IS_FTP: addMacro(spec->macros, "_remsh", NULL, "%{__remsh}", RMIL_SPEC); addMacro(spec->macros, "_remhost", NULL, u->host, RMIL_SPEC); if (strcmp(rootDir, "/")) addMacro(spec->macros, "_remroot", NULL, rootDir, RMIL_SPEC); break; case URL_IS_UNKNOWN: case URL_IS_DASH: case URL_IS_PATH: case URL_IS_HKP: default: break; } buildCmd = rpmExpand(mCmd, " ", buildScript, NULL); (void) poptParseArgvString(buildCmd, &argc, &argv); if (what != RPMBUILD_TRACK) /* support "%track" script/section */ rpmlog(RPMLOG_NOTICE, _("Executing(%s): %s\n"), name, buildCmd); /* Run the script with a stopwatch. */ if (op != NULL) (void) rpmswEnter(op, 0); status = rpmsqExecve(argv); if (ix >= 0 && ix < RPMSCRIPT_MAX) spec->sstates[ix] = (RPMSCRIPT_STATE_EXEC | RPMSCRIPT_STATE_REAPED) | (status & 0xffff); if (!WIFEXITED(status) || WEXITSTATUS(status)) { rpmlog(RPMLOG_ERR, _("Bad exit status from %s (%s)\n"), scriptName, name); rc = RPMRC_FAIL; } else rc = RPMRC_OK; if (op != NULL) { static unsigned int scale = 1000; (void) rpmswExit(op, 0); if (ix >= 0 && ix < RPMSCRIPT_MAX) spec->smetrics[ix] += op->usecs / scale; } exit: if (scriptName) { #if defined(RPM_VENDOR_OPENPKG) /* always-remove-tempfiles */ /* Unconditionally remove temporary files ("rpm-tmp.XXXXX") which were generated for the executed scripts. In OpenPKG we run the scripts in debug mode ("set -x") anyway, so we never need to see the whole generated script -- not even if it breaks. Instead we would just have temporary files staying around forever. */ #else if (rc == RPMRC_OK) #endif (void) Unlink(scriptName); scriptName = _free(scriptName); } switch (urlType(u)) { case URL_IS_HTTPS: case URL_IS_HTTP: case URL_IS_FTP: delMacro(spec->macros, "_remsh"); delMacro(spec->macros, "_remhost"); if (strcmp(rootDir, "/")) delMacro(spec->macros, "_remroot"); break; case URL_IS_UNKNOWN: case URL_IS_DASH: case URL_IS_PATH: case URL_IS_HKP: default: break; } argv = _free(argv); buildCmd = _free(buildCmd); buildTemplate = _free(buildTemplate); buildPost = _free(buildPost); buildDirURL = _free(buildDirURL); return rc; }
static int db3open(rpmdb rpmdb, rpmTag rpmtag, dbiIndex * dbip) { extern const struct _dbiVec db3vec; const char * root; const char * home; char * dbhome; const char * dbfile; const char * dbsubfile; dbiIndex dbi = NULL; int rc = 0; int xx; DB * db = NULL; DB_ENV * dbenv = NULL; DB_TXN * txnid = NULL; uint32_t oflags; int _printit; if (dbip) *dbip = NULL; /* * Parse db configuration parameters. */ if ((dbi = db3New(rpmdb, rpmtag)) == NULL) return 1; dbi->dbi_api = DB_VERSION_MAJOR; /* * Get the prefix/root component and directory path. */ root = (dbi->dbi_root ? dbi->dbi_root : rpmdb->db_root); if ((root[0] == '/' && root[1] == '\0') || rpmdb->db_chrootDone) root = NULL; home = (dbi->dbi_home ? dbi->dbi_home : rpmdb->db_home); dbhome = rpmGenPath(root, home, NULL); if (dbi->dbi_temporary) { dbfile = NULL; dbsubfile = NULL; } else { #ifdef HACK /* XXX necessary to support dbsubfile */ dbfile = (dbi->dbi_file ? dbi->dbi_file : db3basename); dbsubfile = (dbi->dbi_subfile ? dbi->dbi_subfile : rpmTagGetName(dbi->dbi_rpmtag)); #else dbfile = (dbi->dbi_file ? dbi->dbi_file : rpmTagGetName(dbi->dbi_rpmtag)); dbsubfile = NULL; #endif } oflags = (dbi->dbi_oeflags | dbi->dbi_oflags); oflags &= ~DB_TRUNCATE; /* XXX this is dangerous */ #if 0 /* XXX rpmdb: illegal flag combination specified to DB->open */ if ( dbi->dbi_mode & O_EXCL) oflags |= DB_EXCL; #endif /* * Map open mode flags onto configured database/environment flags. */ if (dbi->dbi_temporary) { oflags |= DB_CREATE; dbi->dbi_oeflags |= DB_CREATE; oflags &= ~DB_RDONLY; dbi->dbi_oflags &= ~DB_RDONLY; } else { if ((dbi->dbi_mode & O_ACCMODE) == O_RDONLY) oflags |= DB_RDONLY; if (dbi->dbi_mode & O_CREAT) { oflags |= DB_CREATE; dbi->dbi_oeflags |= DB_CREATE; } #ifdef DANGEROUS if ( dbi->dbi_mode & O_TRUNC) oflags |= DB_TRUNCATE; #endif } /* * Create the /var/lib/rpm directory if it doesn't exist (root only). */ (void) rpmioMkpath(dbhome, 0755, getuid(), getgid()); /* * Avoid incompatible DB_CREATE/DB_RDONLY flags on DBENV->open. */ if (dbi->dbi_use_dbenv) { if (access(dbhome, W_OK) == -1) { /* dbhome is unwritable, don't attempt DB_CREATE on DB->open ... */ oflags &= ~DB_CREATE; /* ... but DBENV->open might still need DB_CREATE ... */ if (dbi->dbi_eflags & DB_PRIVATE) { dbi->dbi_eflags &= ~DB_JOINENV; } else { dbi->dbi_eflags |= DB_JOINENV; dbi->dbi_oeflags &= ~DB_CREATE; dbi->dbi_oeflags &= ~DB_THREAD; /* ... but, unless DB_PRIVATE is used, skip DBENV. */ dbi->dbi_use_dbenv = 0; } /* ... DB_RDONLY maps dbhome perms across files ... */ if (dbi->dbi_temporary) { oflags |= DB_CREATE; dbi->dbi_oeflags |= DB_CREATE; oflags &= ~DB_RDONLY; dbi->dbi_oflags &= ~DB_RDONLY; } else { oflags |= DB_RDONLY; /* ... and DB_WRITECURSOR won't be needed ... */ dbi->dbi_oflags |= DB_RDONLY; } } else { /* dbhome is writable, check for persistent dbenv. */ char * dbf = rpmGetPath(dbhome, "/__db.001", NULL); if (access(dbf, F_OK) == -1) { /* ... non-existent (or unwritable) DBENV, will create ... */ dbi->dbi_oeflags |= DB_CREATE; dbi->dbi_eflags &= ~DB_JOINENV; } else { /* ... pre-existent (or bogus) DBENV, will join ... */ if (dbi->dbi_eflags & DB_PRIVATE) { dbi->dbi_eflags &= ~DB_JOINENV; } else { dbi->dbi_eflags |= DB_JOINENV; dbi->dbi_oeflags &= ~DB_CREATE; dbi->dbi_oeflags &= ~DB_THREAD; } } dbf = _free(dbf); } } /* * Avoid incompatible DB_CREATE/DB_RDONLY flags on DB->open. */ if ((oflags & DB_CREATE) && (oflags & DB_RDONLY)) { /* dbhome is writable, and DB->open flags may conflict. */ const char * dbfn = (dbfile ? dbfile : rpmTagGetName(dbi->dbi_rpmtag)); char * dbf = rpmGetPath(dbhome, "/", dbfn, NULL); if (access(dbf, F_OK) == -1) { /* File does not exist, DB->open might create ... */ oflags &= ~DB_RDONLY; } else { /* File exists, DB->open need not create ... */ oflags &= ~DB_CREATE; } /* Only writers need DB_WRITECURSOR ... */ if (!(oflags & DB_RDONLY) && access(dbf, W_OK) == 0) { dbi->dbi_oflags &= ~DB_RDONLY; } else { dbi->dbi_oflags |= DB_RDONLY; } dbf = _free(dbf); } /* * Turn off verify-on-close if opening read-only. */ if (oflags & DB_RDONLY) dbi->dbi_verify_on_close = 0; if (dbi->dbi_use_dbenv) { if (rpmdb->db_dbenv == NULL) { rc = db_init(dbi, dbhome, dbfile, dbsubfile, &dbenv); if (rc == 0) { rpmdb->db_dbenv = dbenv; rpmdb->db_opens = 1; } } else { dbenv = rpmdb->db_dbenv; rpmdb->db_opens++; } } { char *dbiflags = prDbiOpenFlags(oflags, 0); rpmlog(RPMLOG_DEBUG, "opening db index %s/%s %s mode=0x%x\n", dbhome, (dbfile ? dbfile : rpmTagGetName(dbi->dbi_rpmtag)), dbiflags, dbi->dbi_mode); free(dbiflags); } if (rc == 0) { static int _lockdbfd = 0; rc = db_create(&db, dbenv, dbi->dbi_cflags); rc = cvtdberr(dbi, "db_create", rc, _debug); if (rc == 0 && db != NULL) { if (rc == 0 && rpmdb->db_malloc && rpmdb->db_realloc && rpmdb->db_free) { rc = db->set_alloc(db, rpmdb->db_malloc, rpmdb->db_realloc, rpmdb->db_free); rc = cvtdberr(dbi, "db->set_alloc", rc, _debug); } /* 4.1: db->set_cache_priority(???) */ if (rc == 0 && !dbi->dbi_use_dbenv && dbi->dbi_cachesize) { rc = db->set_cachesize(db, 0, dbi->dbi_cachesize, 0); rc = cvtdberr(dbi, "db->set_cachesize", rc, _debug); } /* 4.1: db->set_encrypt(???) */ /* 4.1: db->set_errcall(dbenv, rpmdb->db_errcall); */ /* 4.1: db->set_errfile(dbenv, rpmdb->db_errfile); */ /* 4.1: db->set_errpfx(dbenv, rpmdb->db_errpfx); */ /* 4.1: db->set_feedback(???) */ if (rc == 0 && dbi->dbi_lorder) { rc = db->set_lorder(db, dbi->dbi_lorder); rc = cvtdberr(dbi, "db->set_lorder", rc, _debug); } if (rc == 0 && dbi->dbi_pagesize) { rc = db->set_pagesize(db, dbi->dbi_pagesize); rc = cvtdberr(dbi, "db->set_pagesize", rc, _debug); } /* 4.1: db->set_paniccall(???) */ if (rc == 0 && oflags & DB_CREATE) { switch(dbi->dbi_type) { default: case DB_HASH: if (dbi->dbi_h_ffactor) { rc = db->set_h_ffactor(db, dbi->dbi_h_ffactor); rc = cvtdberr(dbi, "db->set_h_ffactor", rc, _debug); if (rc) break; } if (dbi->dbi_h_nelem) { rc = db->set_h_nelem(db, dbi->dbi_h_nelem); rc = cvtdberr(dbi, "db->set_h_nelem", rc, _debug); if (rc) break; } if (dbi->dbi_h_flags) { rc = db->set_flags(db, dbi->dbi_h_flags); rc = cvtdberr(dbi, "db->set_h_flags", rc, _debug); if (rc) break; } if (dbi->dbi_h_hash_fcn) { rc = db->set_h_hash(db, dbi->dbi_h_hash_fcn); rc = cvtdberr(dbi, "db->set_h_hash", rc, _debug); if (rc) break; } if (dbi->dbi_h_dup_compare_fcn) { rc = db->set_dup_compare(db, dbi->dbi_h_dup_compare_fcn); rc = cvtdberr(dbi, "db->set_dup_compare", rc, _debug); if (rc) break; } break; case DB_BTREE: /* 4.1: db->set_append_recno(???) */ if (dbi->dbi_bt_flags) { rc = db->set_flags(db, dbi->dbi_bt_flags); rc = cvtdberr(dbi, "db->set_bt_flags", rc, _debug); if (rc) break; } if (dbi->dbi_bt_minkey) { rc = db->set_bt_minkey(db, dbi->dbi_bt_minkey); rc = cvtdberr(dbi, "db->set_bt_minkey", rc, _debug); if (rc) break; } if (dbi->dbi_bt_compare_fcn) { rc = db->set_bt_compare(db, dbi->dbi_bt_compare_fcn); rc = cvtdberr(dbi, "db->set_bt_compare", rc, _debug); if (rc) break; } if (dbi->dbi_bt_dup_compare_fcn) { rc = db->set_dup_compare(db, dbi->dbi_bt_dup_compare_fcn); rc = cvtdberr(dbi, "db->set_dup_compare", rc, _debug); if (rc) break; } if (dbi->dbi_bt_prefix_fcn) { rc = db->set_bt_prefix(db, dbi->dbi_bt_prefix_fcn); rc = cvtdberr(dbi, "db->set_bt_prefix", rc, _debug); if (rc) break; } break; case DB_RECNO: if (dbi->dbi_re_delim) { /* 4.1: db->set_append_recno(???) */ rc = db->set_re_delim(db, dbi->dbi_re_delim); rc = cvtdberr(dbi, "db->set_re_selim", rc, _debug); if (rc) break; } if (dbi->dbi_re_len) { rc = db->set_re_len(db, dbi->dbi_re_len); rc = cvtdberr(dbi, "db->set_re_len", rc, _debug); if (rc) break; } if (dbi->dbi_re_pad) { rc = db->set_re_pad(db, dbi->dbi_re_pad); rc = cvtdberr(dbi, "db->set_re_pad", rc, _debug); if (rc) break; } if (dbi->dbi_re_source) { rc = db->set_re_source(db, dbi->dbi_re_source); rc = cvtdberr(dbi, "db->set_re_source", rc, _debug); if (rc) break; } break; case DB_QUEUE: if (dbi->dbi_q_extentsize) { rc = db->set_q_extentsize(db, dbi->dbi_q_extentsize); rc = cvtdberr(dbi, "db->set_q_extentsize", rc, _debug); if (rc) break; } break; } } if (rc == 0) { char * fullpath; const char * dbpath; fullpath = rpmGetPath(dbhome, "/", dbfile ? dbfile : "", NULL); #ifdef HACK /* XXX necessary to support dbsubfile */ dbpath = (!dbi->dbi_use_dbenv && !dbi->dbi_temporary) ? fullpath : dbfile; #else dbpath = (!dbi->dbi_temporary) ? fullpath : dbfile; #endif rc = (db->open)(db, txnid, dbpath, dbsubfile, dbi->dbi_type, oflags, dbi->dbi_perms); if (rc == 0 && dbi->dbi_type == DB_UNKNOWN) { DBTYPE dbi_type = DB_UNKNOWN; xx = db->get_type(db, &dbi_type); if (xx == 0) dbi->dbi_type = dbi_type; } free(fullpath); } /* XXX return rc == errno without printing */ _printit = (rc > 0 ? 0 : _debug); xx = cvtdberr(dbi, "db->open", rc, _printit); dbi->dbi_txnid = NULL; /* * Lock a file using fcntl(2). Traditionally this is Packages, * the file used to store metadata of installed header(s), * as Packages is always opened, and should be opened first, * for any rpmdb access. * * If no DBENV is used, then access is protected with a * shared/exclusive locking scheme, as always. * * With a DBENV, the fcntl(2) lock is necessary only to keep * the riff-raff from playing where they don't belong, as * the DBENV should provide it's own locking scheme. So try to * acquire a lock, but permit failures, as some other * DBENV player may already have acquired the lock. * * With NPTL posix mutexes, revert to fcntl lock on non-functioning * glibc/kernel combinations. */ if (rc == 0 && dbi->dbi_lockdbfd && !((dbi->dbi_ecflags & DB_CLIENT) && dbi->dbi_host) && (!dbi->dbi_use_dbenv || _lockdbfd++ == 0)) { int fdno = -1; if (!(db->fd(db, &fdno) == 0 && fdno >= 0)) { rc = 1; } else { struct flock l; memset(&l, 0, sizeof(l)); l.l_whence = 0; l.l_start = 0; l.l_len = 0; l.l_type = (dbi->dbi_mode & O_ACCMODE) == O_RDONLY ? F_RDLCK : F_WRLCK; l.l_pid = 0; rc = fcntl(fdno, F_SETLK, (void *) &l); if (rc) { /* Warning iff using non-private CDB locking. */ rc = ((dbi->dbi_use_dbenv && (dbi->dbi_eflags & DB_INIT_CDB) && !(dbi->dbi_eflags & DB_PRIVATE)) ? 0 : 1); rpmlog( (rc ? RPMLOG_ERR : RPMLOG_WARNING), _("cannot get %s lock on %s/%s\n"), ((dbi->dbi_mode & O_ACCMODE) == O_RDONLY) ? _("shared") : _("exclusive"), dbhome, (dbfile ? dbfile : "")); } else if (dbfile) { rpmlog(RPMLOG_DEBUG, "locked db index %s/%s\n", dbhome, dbfile); } } } } } dbi->dbi_db = db; if (rc == 0 && dbi->dbi_db != NULL && dbip != NULL) { dbi->dbi_vec = &db3vec; *dbip = dbi; } else { dbi->dbi_verify_on_close = 0; (void) db3close(dbi, 0); } free(dbhome); return rc; }
static ModuleRec newModule(const char *path, const char *name, const char *types, uint32_t flags) { ModuleRec mod; uint8_t *raw = NULL; ssize_t rawlen = 0; const char *buildDir = "%{_builddir}/%{?buildsubdir}/"; if (!path) { rpmlog(RPMLOG_ERR, _("%%semodule requires a file path\n")); return NULL; } mod = xcalloc(1, sizeof(*mod)); mod->path = rpmGenPath(buildDir, NULL, path); if ((rpmioSlurp(mod->path, &raw, &rawlen)) != 0 || raw == NULL) { rpmlog(RPMLOG_ERR, _("Failed to read policy file: %s\n"), mod->path); goto err; } mod->data = b64encode(raw, rawlen, -1); if (!mod->data) { rpmlog(RPMLOG_ERR, _("Failed to encode policy file: %s\n"), mod->path); goto err; } if (name) { mod->name = xstrdup(name); } else { /* assume base name (minus extension) if name is not given */ char *tmp = xstrdup(mod->path); char *bname = basename(tmp); char *end = strchr(bname, '.'); if (end) *end = '\0'; if (strlen(bname) > 0) { mod->name = xstrdup(bname); } else { rpmlog(RPMLOG_ERR, _("Failed to determine a policy name: %s\n"), mod->path); _free(tmp); goto err; } _free(tmp); } if (types) { mod->types = argvSplitString(types, ",", ARGV_SKIPEMPTY); argvSort(mod->types, NULL); if (argvSearch(mod->types, RPMPOL_TYPE_DEFAULT, NULL) && argvCount(mod->types) > 1) { rpmlog(RPMLOG_WARNING, _("'%s' type given with other types in %%semodule %s. Compacting types to '%s'.\n"), RPMPOL_TYPE_DEFAULT, mod->path, RPMPOL_TYPE_DEFAULT); mod->types = argvFree(mod->types); argvAdd(&mod->types, RPMPOL_TYPE_DEFAULT); } } else { argvAdd(&mod->types, RPMPOL_TYPE_DEFAULT); } mod->flags = flags; return mod; err: freeModule(mod); return NULL; }
int addSource(Spec spec, /*@unused@*/ Package pkg, const char *field, rpmTag tag) { struct Source *p; #if defined(RPM_VENDOR_OPENPKG) /* regular-ordered-sources */ struct Source *p_last; #endif int flag = 0; const char *name = NULL; const char *mdir = NULL; const char *fieldp = NULL; char buf[BUFSIZ]; uint32_t num = 0; buf[0] = '\0'; switch (tag) { case RPMTAG_SOURCE: flag = RPMFILE_SOURCE; name = "source"; fieldp = spec->line + strlen(name); break; case RPMTAG_PATCH: flag = RPMFILE_PATCH; name = "patch"; fieldp = spec->line + strlen(name); break; case RPMTAG_ICON: flag = RPMFILE_ICON; name = "icon"; fieldp = NULL; break; default: assert(0); /*@notreached@*/ break; } #if !defined(RPM_VENDOR_OPENPKG) /* splitted-source-directory */ mdir = getSourceDir(flag); assert(mdir != NULL); #endif /* Get the number */ if (fieldp != NULL) { char * end = NULL; num = strtoul(fieldp, &end, 10); SKIPSPACE(end); if (*end != ':') { rpmlog(RPMLOG_ERR, _("line %d: No ':' terminator: %s\n"), spec->lineNum, spec->line); return RPMRC_FAIL; } } /* Check whether tags of the same number haven't already been defined */ for (p = spec->sources; p != NULL; p = p->next) { if ( p->num != num ) continue; if ((tag == RPMTAG_SOURCE && p->flags == RPMFILE_SOURCE) || (tag == RPMTAG_PATCH && p->flags == RPMFILE_PATCH)) { rpmlog(RPMLOG_ERR, _("%s %d defined multiple times\n"), name, num); return RPMRC_FAIL; } } /* Create the entry and link it in */ p = xmalloc(sizeof(*p)); p->num = num; p->fullSource = xstrdup(field); p->flags = flag; p->source = strrchr(p->fullSource, '/'); if (p->source) p->source++; else p->source = p->fullSource; #if defined(RPM_VENDOR_OPENPKG) /* regular-ordered-sources */ p->next = NULL; p_last = spec->sources; while (p_last != NULL && p_last->next != NULL) p_last = p_last->next; if (p_last != NULL) p_last->next = p; else spec->sources = p; #else p->next = spec->sources; spec->sources = p; #endif spec->numSources++; /* XXX FIXME: need to add ICON* macros. */ #if defined(RPM_VENDOR_OPENPKG) /* splitted-source-directory */ mdir = getSourceDir(flag, p->source); #endif if (tag != RPMTAG_ICON) { const char *body = rpmGenPath(NULL, mdir, p->source); sprintf(buf, "%s%d", (flag & RPMFILE_PATCH) ? "PATCH" : "SOURCE", num); addMacro(spec->macros, buf, NULL, body, RMIL_SPEC); sprintf(buf, "%sURL%d", (flag & RPMFILE_PATCH) ? "PATCH" : "SOURCE", num); addMacro(spec->macros, buf, NULL, p->fullSource, RMIL_SPEC); #ifdef WITH_LUA if (!spec->recursing) { rpmlua lua = NULL; /* global state */ const char * what = (flag & RPMFILE_PATCH) ? "patches" : "sources"; rpmluav var = rpmluavNew(); rpmluaPushTable(lua, what); rpmluavSetListMode(var, 1); rpmluavSetValue(var, RPMLUAV_STRING, body); rpmluaSetVar(lua, var); /*@-moduncon@*/ var = (rpmluav) rpmluavFree(var); /*@=moduncon@*/ rpmluaPop(lua); } #endif body = _free(body); } return RPMRC_OK; }