Ejemplo n.º 1
0
Archivo: psm.c Proyecto: OlegGirko/rpm
rpmRC rpmpsmRun(rpmts ts, rpmte te, pkgGoal goal)
{
    rpmpsm psm = NULL;
    rpmRC rc = RPMRC_FAIL;

    /* Psm can't fail in test mode, just return early */
    if (rpmtsFlags(ts) & RPMTRANS_FLAG_TEST)
	return RPMRC_OK;

    psm = rpmpsmNew(ts, te);
    if (rpmChrootIn() == 0) {
	rpmtsOpX op;
	psm->goal = goal;
	psm->goalName = pkgGoalString(goal);

	switch (goal) {
	case PKG_INSTALL:
	case PKG_ERASE:
	    /* Run pre transaction element hook for all plugins */
	    if (rpmpluginsCallPsmPre(rpmtsPlugins(ts), te) != RPMRC_FAIL) {

		op = (goal == PKG_INSTALL) ? RPMTS_OP_INSTALL : RPMTS_OP_ERASE;
		rpmswEnter(rpmtsOp(psm->ts, op), 0);

		rc = rpmpsmNext(psm, PSM_INIT);
		if (!rc) rc = rpmpsmNext(psm, PSM_PRE);
		if (!rc) rc = rpmpsmNext(psm, PSM_PROCESS);
		if (!rc) rc = rpmpsmNext(psm, PSM_POST);
		(void) rpmpsmNext(psm, PSM_FINI);

		rpmswExit(rpmtsOp(psm->ts, op), 0);
	    }

	    /* Run post transaction element hook for all plugins */
	    rpmpluginsCallPsmPost(rpmtsPlugins(ts), te, rc);
	    break;
	case PKG_PRETRANS:
	case PKG_POSTTRANS:
	case PKG_VERIFY:
	    psm->scriptTag = goal;
	    rc = rpmpsmStage(psm, PSM_SCRIPT);
	    break;
	default:
	    break;
	}
	/* XXX an error here would require a full abort */
	(void) rpmChrootOut();
    }
    rpmpsmFree(psm);
    return rc;
}
Ejemplo n.º 2
0
rpmRC rpmpsmRun(rpmts ts, rpmte te, pkgGoal goal)
{
    rpmpsm psm = NULL;
    rpmRC rc = RPMRC_FAIL;

    /* Psm can't fail in test mode, just return early */
    if (rpmtsFlags(ts) & RPMTRANS_FLAG_TEST)
	return RPMRC_OK;

    psm = rpmpsmNew(ts, te, goal);
    if (rpmChrootIn() == 0) {
	/* Run pre transaction element hook for all plugins */
	rc = rpmpluginsCallPsmPre(rpmtsPlugins(ts), te);

	if (!rc) {
	    switch (goal) {
	    case PKG_INSTALL:
		rc = rpmPackageInstall(ts, psm);
		break;
	    case PKG_ERASE:
		rc = rpmPackageErase(ts, psm);
		break;
	    case PKG_PRETRANS:
	    case PKG_POSTTRANS:
	    case PKG_VERIFY:
		rc = runInstScript(psm, goal);
		break;
	    case PKG_TRANSFILETRIGGERIN:
		rc = runImmedFileTriggers(ts, te, RPMSENSE_TRIGGERIN,
					    RPMSCRIPT_TRANSFILETRIGGER, 0);
		break;
	    case PKG_TRANSFILETRIGGERUN:
		rc = runImmedFileTriggers(ts, te, RPMSENSE_TRIGGERUN,
					    RPMSCRIPT_TRANSFILETRIGGER, 0);
		break;
	    default:
		break;
	    }
	}
	/* Run post transaction element hook for all plugins */
	rpmpluginsCallPsmPost(rpmtsPlugins(ts), te, rc);

	/* XXX an error here would require a full abort */
	(void) rpmChrootOut();
    }
    rpmpsmFree(psm);
    return rc;
}
Ejemplo n.º 3
0
rpmRC rpmtsSetupTransactionPlugins(rpmts ts)
{
    rpmRC rc = RPMRC_OK;
    ARGV_t files = NULL;
    int nfiles = 0;
    char *dsoPath = NULL;

    /*
     * Assume allocated equals initialized. There are some oddball cases
     * (verification of non-installed package) where this is not true
     * currently but that's not a new issue.
     */
    if ((rpmtsFlags(ts) & RPMTRANS_FLAG_NOPLUGINS) || ts->plugins != NULL)
	return RPMRC_OK;

    dsoPath = rpmExpand("%{__plugindir}/*.so", NULL);
    if (rpmGlob(dsoPath, &nfiles, &files) == 0) {
	rpmPlugins tsplugins = rpmtsPlugins(ts);
	for (int i = 0; i < nfiles; i++) {
	    char *bn = basename(files[i]);
	    bn[strlen(bn)-strlen(".so")] = '\0';
	    if (rpmpluginsAddPlugin(tsplugins, "transaction", bn) == RPMRC_FAIL)
		rc = RPMRC_FAIL;
	}
	files = argvFree(files);
    }
    free(dsoPath);

    return rc;
}
Ejemplo n.º 4
0
Archivo: psm.c Proyecto: fingunter/rpm
/**
 * Run a scriptlet with args.
 *
 * Run a script with an interpreter. If the interpreter is not specified,
 * /bin/sh will be used. If the interpreter is /bin/sh, then the args from
 * the header will be ignored, passing instead arg1 and arg2.
 *
 * @param ts		transaction set
 * @param te		transaction element
 * @param prefixes	install prefixes
 * @param script	scriptlet from header
 * @param arg1		no. instances of package installed after scriptlet exec
 *			(-1 is no arg)
 * @param arg2		ditto, but for the target package
 * @return		0 on success
 */
static rpmRC runScript(rpmts ts, rpmte te, ARGV_const_t prefixes, 
		       rpmScript script, int arg1, int arg2)
{
    rpmRC stoprc, rc = RPMRC_OK;
    rpmTagVal stag = rpmScriptTag(script);
    FD_t sfd = NULL;
    int warn_only = (stag != RPMTAG_PREIN &&
		     stag != RPMTAG_PREUN &&
		     stag != RPMTAG_PRETRANS &&
		     stag != RPMTAG_VERIFYSCRIPT);

    sfd = rpmtsNotify(ts, te, RPMCALLBACK_SCRIPT_START, stag, 0);
    if (sfd == NULL)
	sfd = rpmtsScriptFd(ts);

    rpmswEnter(rpmtsOp(ts, RPMTS_OP_SCRIPTLETS), 0);
    rc = rpmScriptRun(script, arg1, arg2, sfd,
		      prefixes, warn_only, rpmtsPlugins(ts));
    rpmswExit(rpmtsOp(ts, RPMTS_OP_SCRIPTLETS), 0);

    /* Map warn-only errors to "notfound" for script stop callback */
    stoprc = (rc != RPMRC_OK && warn_only) ? RPMRC_NOTFOUND : rc;
    rpmtsNotify(ts, te, RPMCALLBACK_SCRIPT_STOP, stag, stoprc);

    /* 
     * Notify callback for all errors. "total" abused for warning/error,
     * rc only reflects whether the condition prevented install/erase 
     * (which is only happens with %prein and %preun scriptlets) or not.
     */
    if (rc != RPMRC_OK) {
	if (warn_only) {
	    rc = RPMRC_OK;
	}
	rpmtsNotify(ts, te, RPMCALLBACK_SCRIPT_ERROR, stag, rc);
    }

    return rc;
}
Ejemplo n.º 5
0
rpmRC rpmtsSetupTransactionPlugins(rpmts ts)
{
    rpmRC rc = RPMRC_OK;
    char *plugins = NULL, *plugin = NULL;
    const char *delims = ",";
    rpmPlugins tsplugins;

    /*
     * Assume allocated equals initialized. There are some oddball cases
     * (verification of non-installed package) where this is not true
     * currently but that's not a new issue.
     */
    if (ts->plugins != NULL)
	return RPMRC_OK;

    plugins = rpmExpand("%{?__transaction_plugins}", NULL);
    if (!plugins || rstreq(plugins, "")) {
	goto exit;
    }

    tsplugins = rpmtsPlugins(ts);
    plugin = strtok(plugins, delims);
    while(plugin != NULL) {
	rpmlog(RPMLOG_DEBUG, "plugin is %s\n", plugin);
	if (!rpmpluginsPluginAdded(tsplugins, plugin)) {
	    if (rpmpluginsAddPlugin(tsplugins, "transaction",
				    plugin) == RPMRC_FAIL) {
		/* any configured plugin failing to load is a failure */
		rc = RPMRC_FAIL;
	    }
	}
	plugin = strtok(NULL, delims);
    }

exit:
    free(plugins);
    return rc;
}
Ejemplo n.º 6
0
int rpmtsRun(rpmts ts, rpmps okProbs, rpmprobFilterFlags ignoreSet)
{
    int rc = -1; /* assume failure */
    tsMembers tsmem = rpmtsMembers(ts);
    rpmtxn txn = NULL;
    rpmps tsprobs = NULL;
    int TsmPreDone = 0; /* TsmPre hook hasn't been called */
    
    /* Force default 022 umask during transaction for consistent results */
    mode_t oldmask = umask(022);

    /* Empty transaction, nothing to do */
    if (rpmtsNElements(ts) <= 0) {
	rc = 0;
	goto exit;
    }

    /* If we are in test mode, then there's no need for transaction lock. */
    if (!(rpmtsFlags(ts) & RPMTRANS_FLAG_TEST)) {
	if (!(txn = rpmtxnBegin(ts, RPMTXN_WRITE))) {
	    goto exit;
	}
    }

    /* Setup flags and such, open the DB */
    if (rpmtsSetup(ts, ignoreSet)) {
	goto exit;
    }

    /* Check package set for problems */
    tsprobs = checkProblems(ts);

    /* Run pre transaction hook for all plugins */
    TsmPreDone = 1;
    if (rpmpluginsCallTsmPre(rpmtsPlugins(ts), ts) == RPMRC_FAIL) {
	goto exit;
    }

    if (!rpmpsNumProblems(tsprobs)) {
	/* Run file triggers in this package other package(s) set off. */
	runFileTriggers(ts, NULL, RPMSENSE_TRIGGERUN,
			RPMSCRIPT_TRANSFILETRIGGER, 0);
	/* Run file triggers in other package(s) this package sets off. */
	runTransScripts(ts, PKG_TRANSFILETRIGGERUN);
    }

    /* Run pre-transaction scripts, but only if there are no known
     * problems up to this point and not disabled otherwise. */
    if (!((rpmtsFlags(ts) & (RPMTRANS_FLAG_BUILD_PROBS|RPMTRANS_FLAG_NOPRETRANS))
     	  || (rpmpsNumProblems(tsprobs)))) {
	rpmlog(RPMLOG_DEBUG, "running pre-transaction scripts\n");
	runTransScripts(ts, PKG_PRETRANS);
    }
    tsprobs = rpmpsFree(tsprobs);

    /* Compute file disposition for each package in transaction set. */
    if (rpmtsPrepare(ts)) {
	goto exit;
    }
    /* Check again for problems (now including file conflicts,  duh */
    tsprobs = rpmtsProblems(ts);

     /* If unfiltered problems exist, free memory and return. */
    if ((rpmtsFlags(ts) & RPMTRANS_FLAG_BUILD_PROBS) || (rpmpsNumProblems(tsprobs))) {
	rc = tsmem->orderCount;
	goto exit;
    }

    /* Free up memory taken by problem sets */
    tsprobs = rpmpsFree(tsprobs);
    rpmtsCleanProblems(ts);

    /*
     * Free up the global string pool unless we expect it to be needed
     * again. During the transaction, private pools will be used for
     * rpmfi's etc.
     */
    if (!(rpmtsFlags(ts) & (RPMTRANS_FLAG_TEST|RPMTRANS_FLAG_BUILD_PROBS)))
	tsmem->pool = rpmstrPoolFree(tsmem->pool);


    /* Actually install and remove packages, get final exit code */
    rc = rpmtsProcess(ts) ? -1 : 0;

    /* Run post-transaction scripts unless disabled */
    if (!(rpmtsFlags(ts) & (RPMTRANS_FLAG_NOPOSTTRANS))) {
	rpmlog(RPMLOG_DEBUG, "running post-transaction scripts\n");
	runTransScripts(ts, PKG_POSTTRANS);
    }

    /* Run file triggers in other package(s) this package sets off. */
    runFileTriggers(ts, NULL, RPMSENSE_TRIGGERIN, RPMSCRIPT_TRANSFILETRIGGER, 0);
    runPostUnTransFileTrigs(ts);

    /* Run file triggers in this package other package(s) set off. */
    runTransScripts(ts, PKG_TRANSFILETRIGGERIN);
exit:
    /* Run post transaction hook for all plugins */
    if (TsmPreDone) /* If TsmPre hook has been called, call the TsmPost hook */
	rpmpluginsCallTsmPost(rpmtsPlugins(ts), ts, rc);

    /* Finish up... */
    (void) umask(oldmask);
    (void) rpmtsFinish(ts);
    rpmpsFree(tsprobs);
    rpmtxnEnd(txn);
    return rc;
}