summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPanu Matilainen <pmatilai@redhat.com>2012-04-18 12:34:45 +0300
committerPanu Matilainen <pmatilai@redhat.com>2012-04-18 12:39:25 +0300
commit00db04cf2cfd6d368aa70db316f50cf05f37c38b (patch)
tree2f4972c4e952c4a15bf07e79bbe09a3842e4a3b5
parentdf92175300a9e320136fc2fc4e3f7a9b1274635c (diff)
downloadlibrpm-tizen-00db04cf2cfd6d368aa70db316f50cf05f37c38b.tar.gz
librpm-tizen-00db04cf2cfd6d368aa70db316f50cf05f37c38b.tar.bz2
librpm-tizen-00db04cf2cfd6d368aa70db316f50cf05f37c38b.zip
Sanitize fsm creation/initialization and destruction
- Now that there are no more failing parts requiring return codes, change + rename fsmSetup() into a more regular fsmNew() construct, returning newly "instance" of fsm and similarly fsmTeardown() -> fsmFree() to free the thing. - There's no real need to allocate this stuff on heap, but doing so makes life actually simpler for the three callers and makes the whole thing more consistent with common practises in the codebase.
-rw-r--r--lib/fsm.c38
1 files changed, 13 insertions, 25 deletions
diff --git a/lib/fsm.c b/lib/fsm.c
index 006067d41..155ff472c 100644
--- a/lib/fsm.c
+++ b/lib/fsm.c
@@ -606,14 +606,12 @@ static int checkHardLinks(FSM_t fsm)
return rc;
}
-static int fsmSetup(FSM_t fsm, fileStage goal,
- rpmts ts, rpmte te, rpmfi fi,
- char ** failedFile)
+static FSM_t fsmNew(fileStage goal, rpmts ts, rpmte te, rpmfi fi,
+ char ** failedFile)
{
- int rc = 0;
+ FSM_t fsm = xcalloc(1, sizeof(*fsm));
int isSrc = rpmteIsSource(te);
- memset(fsm, 0, sizeof(*fsm));
fsm->ix = -1;
fsm->goal = goal;
fsm->iter = mapInitIterator(ts, te, fi);
@@ -640,13 +638,11 @@ static int fsmSetup(FSM_t fsm, fileStage goal,
if (fsm->failedFile)
*fsm->failedFile = NULL;
- return rc;
+ return fsm;
}
-static int fsmTeardown(FSM_t fsm)
+static FSM_t fsmFree(FSM_t fsm)
{
- int rc = 0;
-
fsm->buf = _free(fsm->buf);
fsm->bufsize = 0;
@@ -660,7 +656,8 @@ static int fsmTeardown(FSM_t fsm)
fsm->li->next = NULL;
fsm->li = freeHardLink(fsm->li);
}
- return rc;
+ free(fsm);
+ return NULL;
}
/* Find and set file security context */
@@ -1697,16 +1694,12 @@ static const char * fileActionString(rpmFileAction a)
int rpmPackageFilesInstall(rpmts ts, rpmte te, rpmfi fi, FD_t cfd,
rpmpsm psm, char ** failedFile)
{
+ FSM_t fsm = fsmNew(FSM_PKGINSTALL, ts, te, fi, failedFile);
rpmcpio_t archive = NULL;
- struct fsm_s fsm_;
- FSM_t fsm = &fsm_;
struct stat * st = &fsm->sb;
int saveerrno = errno;
-
int rc = 0;
- rc = fsmSetup(fsm, FSM_PKGINSTALL, ts, te, fi, failedFile);
-
if (!rc)
archive = rpmcpioOpen(cfd, O_RDONLY);
@@ -1856,7 +1849,7 @@ int rpmPackageFilesInstall(rpmts ts, rpmte te, rpmfi fi, FD_t cfd,
/* No need to bother with close errors on read */
rpmcpioFree(archive);
- fsmTeardown(fsm);
+ fsmFree(fsm);
return rc;
}
@@ -1865,12 +1858,9 @@ int rpmPackageFilesInstall(rpmts ts, rpmte te, rpmfi fi, FD_t cfd,
int rpmPackageFilesRemove(rpmts ts, rpmte te, rpmfi fi,
rpmpsm psm, char ** failedFile)
{
- struct fsm_s fsm_;
- FSM_t fsm = &fsm_;
+ FSM_t fsm = fsmNew(FSM_PKGERASE, ts, te, fi, failedFile);
int rc = 0;
- rc = fsmSetup(fsm, FSM_PKGERASE, ts, te, fi, failedFile);
-
while (!rc) {
/* Clean fsm, free'ing memory. */
fsmReset(fsm);
@@ -1933,7 +1923,7 @@ int rpmPackageFilesRemove(rpmts ts, rpmte te, rpmfi fi,
rpmpsmNotify(psm, RPMCALLBACK_UNINST_PROGRESS, amount);
}
- fsmTeardown(fsm);
+ fsmFree(fsm);
return rc;
}
@@ -1942,12 +1932,10 @@ int rpmPackageFilesRemove(rpmts ts, rpmte te, rpmfi fi,
int rpmPackageFilesArchive(rpmts ts, rpmte te, rpmfi fi, FD_t cfd,
rpm_loff_t * archiveSize, char ** failedFile)
{
+ FSM_t fsm = fsmNew(FSM_PKGBUILD, ts, te, fi, failedFile);;
rpmcpio_t archive = NULL;
- struct fsm_s fsm_;
- FSM_t fsm = &fsm_;
int rc = 0;
- rc = fsmSetup(fsm, FSM_PKGBUILD, ts, te, fi, failedFile);
if (!rc)
archive = rpmcpioOpen(cfd, O_WRONLY);
@@ -1999,7 +1987,7 @@ int rpmPackageFilesArchive(rpmts ts, rpmte te, rpmfi fi, FD_t cfd,
*archiveSize = (rc == 0) ? rpmcpioTell(archive) : 0;
rpmcpioFree(archive);
- fsmTeardown(fsm);
+ fsmFree(fsm);
return rc;
}