Turn PSM into a complete blackbox
authorPanu Matilainen <pmatilai@redhat.com>
Fri, 12 Mar 2010 07:01:25 +0000 (09:01 +0200)
committerPanu Matilainen <pmatilai@redhat.com>
Fri, 12 Mar 2010 07:04:29 +0000 (09:04 +0200)
- The psm structures aren't stored or passed around by any users,
  so there's no need for them to separately allocate and free the
  struct, bury this all inside rpmpsmRun() which takes care of
  initialization, actual actions and freeing.
- There's also no need for refcounting now as allocations are completely
  contained within the rpmpsmRun() blackbox. Lose psm-debug foo which
  was only used for refcount debugging.
- No functional changes

lib/poptALL.c
lib/psm.c
lib/psm.h
lib/transaction.c
lib/verify.c

index da3f59e..98dfae6 100644 (file)
@@ -258,8 +258,6 @@ struct poptOption rpmcliAllPoptTable[] = {
        NULL, NULL},
  { "prtpkts", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_print_pkts, -1,
        NULL, NULL},
- { "psmdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_psm_debug, -1,
-       N_("debug package state machine"), NULL},
  { "rpmaldebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmal_debug, -1,
        NULL, NULL},
  { "rpmdbdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmdb_debug, -1,
index 441901d..75caf11 100644 (file)
--- a/lib/psm.c
+++ b/lib/psm.c
@@ -26,9 +26,6 @@
 
 #include "debug.h"
 
-#define        _PSM_DEBUG      0
-int _psm_debug = _PSM_DEBUG;
-
 typedef enum pkgStage_e {
     PSM_UNKNOWN                =  0,
     PSM_INIT           =  1,
@@ -56,7 +53,7 @@ typedef enum pkgStage_e {
 
 } pkgStage;
 
-struct rpmpsm_s {
+typedef struct rpmpsm_s {
     rpmts ts;                  /*!< transaction set */
     rpmte te;                  /*!< current transaction element */
     rpmfi fi;                  /*!< transaction element file info */
@@ -76,8 +73,10 @@ struct rpmpsm_s {
     pkgStage nstage;           /*!< Next psm stage. */
 
     int nrefs;                 /*!< Reference count. */
-};
+} * rpmpsm;
 
+static rpmpsm rpmpsmNew(rpmts ts, rpmte te);
+static rpmpsm rpmpsmFree(rpmpsm psm);
 static rpmRC rpmpsmStage(rpmpsm psm, pkgStage stage);
 
 /**
@@ -647,34 +646,11 @@ exit:
     return rc;
 }
 
-rpmpsm rpmpsmUnlink(rpmpsm psm, const char * msg)
-{
-    if (psm == NULL) return NULL;
-if (_psm_debug && msg != NULL)
-fprintf(stderr, "--> psm %p -- %d: %s\n", psm, psm->nrefs, msg);
-    psm->nrefs--;
-    return NULL;
-}
-
-rpmpsm rpmpsmLink(rpmpsm psm, const char * msg)
-{
-    if (psm == NULL) return NULL;
-    psm->nrefs++;
-
-if (_psm_debug && msg != NULL)
-fprintf(stderr, "--> psm %p ++ %d %s\n", psm, psm->nrefs, msg);
-
-    return psm;
-}
-
-rpmpsm rpmpsmFree(rpmpsm psm)
+static rpmpsm rpmpsmFree(rpmpsm psm)
 {
     if (psm == NULL)
        return NULL;
 
-    if (psm->nrefs > 1)
-       return rpmpsmUnlink(psm, RPMDBG_M("rpmpsmFree"));
-
     psm->fi = rpmfiFree(psm->fi);
 #ifdef NOTYET
     psm->te = rpmteFree(psm->te);
@@ -683,15 +659,13 @@ rpmpsm rpmpsmFree(rpmpsm psm)
 #endif
     psm->ts = rpmtsFree(psm->ts);
 
-    (void) rpmpsmUnlink(psm, RPMDBG_M("rpmpsmFree"));
-
     memset(psm, 0, sizeof(*psm));              /* XXX trash and burn */
     psm = _free(psm);
 
     return NULL;
 }
 
-rpmpsm rpmpsmNew(rpmts ts, rpmte te)
+static rpmpsm rpmpsmNew(rpmts ts, rpmte te)
 {
     rpmpsm psm = xcalloc(1, sizeof(*psm));
 
@@ -705,7 +679,7 @@ rpmpsm rpmpsmNew(rpmts ts, rpmte te)
        psm->fi = rpmfiLink(rpmteFI(te), RPMDBG_M("rpmpsmNew"));
     }
 
-    return rpmpsmLink(psm, RPMDBG_M("rpmpsmNew"));
+    return psm;
 }
 
 static int rpmpsmNext(rpmpsm psm, pkgStage nstage)
@@ -1139,8 +1113,9 @@ static const char * pkgGoalString(pkgGoal goal)
     }
 }
 
-rpmRC rpmpsmRun(rpmpsm psm, pkgGoal goal)
+rpmRC rpmpsmRun(rpmts ts, rpmte te, pkgGoal goal)
 {
+    rpmpsm psm = rpmpsmNew(ts, te);
     rpmRC rc = RPMRC_FAIL;
 
     if (psm) {
@@ -1172,5 +1147,6 @@ rpmRC rpmpsmRun(rpmpsm psm, pkgGoal goal)
            break;
        }
     }
+    rpmpsmFree(psm);
     return rc;
 }
index 6e47fac..4576ec3 100644 (file)
--- a/lib/psm.h
+++ b/lib/psm.h
@@ -8,10 +8,6 @@
 
 #include <rpm/rpmte.h>
 
-extern int _psm_debug;
-
-typedef struct rpmpsm_s * rpmpsm;
-
 typedef enum pkgGoal_e {
     PKG_NONE           = 0,
     /* permit using rpmteType() for install + erase goals */
@@ -28,49 +24,14 @@ extern "C" {
 #endif
 
 /**
- * Unreference a package state machine instance.
- * @param psm          package state machine
- * @param msg
- * @return             NULL always
- */
-RPM_GNUC_INTERNAL
-rpmpsm rpmpsmUnlink (rpmpsm psm,
-               const char * msg);
-
-/**
- * Reference a package state machine instance.
- * @param psm          package state machine
- * @param msg
- * @return             new package state machine reference
- */
-RPM_GNUC_INTERNAL
-rpmpsm rpmpsmLink (rpmpsm psm, const char * msg);
-
-/**
- * Destroy a package state machine.
- * @param psm          package state machine
- * @return             NULL always
- */
-RPM_GNUC_INTERNAL
-rpmpsm rpmpsmFree(rpmpsm psm);
-
-/**
- * Create and load a package state machine.
- * @param ts           transaction set
- * @param te           transaction set element
- * @return             new package state machine
- */
-RPM_GNUC_INTERNAL
-rpmpsm rpmpsmNew(rpmts ts, rpmte te);
-
-/**
  * Package state machine driver.
- * @param psm          package state machine data
+ * @param ts           transaction set
+ * @param te           transaction element
  * @param goal         state machine goal
  * @return             0 on success
  */
 RPM_GNUC_INTERNAL
-rpmRC rpmpsmRun(rpmpsm psm, pkgGoal goal);
+rpmRC rpmpsmRun(rpmts ts, rpmte te, pkgGoal goal);
 
 #ifdef __cplusplus
 }
index 129414f..8a2c502 100644 (file)
@@ -1138,7 +1138,6 @@ static int runTransScripts(rpmts ts, rpmTag stag)
 {
     rpmtsi pi; 
     rpmte p;
-    rpmpsm psm;
     int xx;
 
     if (stag != RPMTAG_PRETRANS && stag != RPMTAG_POSTTRANS)
@@ -1151,10 +1150,8 @@ static int runTransScripts(rpmts ts, rpmTag stag)
            continue;
 
        if (rpmteOpen(p, ts, 0)) {
-           psm = rpmpsmNew(ts, p);
            /* XXX should %pretrans failure fail the package install? */
-           xx = rpmpsmRun(psm, stag);
-           psm = rpmpsmFree(psm);
+           xx = rpmpsmRun(ts, p, stag);
            rpmteClose(p, ts, 0);
        }
     }
@@ -1392,9 +1389,7 @@ static int rpmtsProcess(rpmts ts)
                rpmteNEVR(p), rpmteA(p), rpmteO(p), rpmteColor(p));
 
        if (rpmteOpen(p, ts, 1)) {
-           rpmpsm psm = rpmpsmNew(ts, p);
-           failed = rpmpsmRun(psm, rpmteType(p));
-           psm = rpmpsmFree(psm);
+           failed = rpmpsmRun(ts, p, rpmteType(p));
            rpmteClose(p, ts, 1);
        }
        if (failed) {
index cb5ee54..b931cf5 100644 (file)
@@ -271,7 +271,6 @@ int rpmVerifyFile(const rpmts ts, const rpmfi fi,
  */
 static int rpmVerifyScript(QVA_t qva, rpmts ts, Header h, FD_t scriptFd)
 {
-    rpmpsm psm = NULL;
     rpmte te = NULL;
     int rc = 0;
 
@@ -283,10 +282,7 @@ static int rpmVerifyScript(QVA_t qva, rpmts ts, Header h, FD_t scriptFd)
     if (scriptFd != NULL)
        rpmtsSetScriptFd(ts, scriptFd);
 
-    /* create psm to run the script */
-    psm = rpmpsmNew(ts, te);
-    rc = rpmpsmRun(psm, PKG_VERIFY);
-    psm = rpmpsmFree(psm);
+    rc = rpmpsmRun(ts, te, PKG_VERIFY);
 
     if (scriptFd != NULL)
        rpmtsSetScriptFd(ts, NULL);