splint fiddles.
authorjbj <devnull@localhost>
Thu, 26 Feb 2004 01:20:52 +0000 (01:20 +0000)
committerjbj <devnull@localhost>
Thu, 26 Feb 2004 01:20:52 +0000 (01:20 +0000)
CVS patchset: 7134
CVS date: 2004/02/26 01:20:52

CHANGES
build/files.c
lib/fsm.c
lib/rpmlock.c
lib/rpmlock.h
lib/rpmsx.c
lib/transaction.c
popt/popthelp.c
rpm.spec.in

diff --git a/CHANGES b/CHANGES
index 4185443..68c86d9 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -23,6 +23,7 @@
        - stable sort for policy specifications, patterns before paths.
        - set "rpm_script_t" exec type for scriptlets iff /bin/sh, else default.
        - force FD_CLOEXEC on 1st 100 inherited fdno's.
+       - serialize rpmtsRun() using fcntl on /var/lock/rpm/transaction.
 
 4.2.1 -> 4.2.2:
        - unify signal handling in librpmio, use condvar to deliver signal.
index 168b5ae..70bd752 100644 (file)
@@ -1767,12 +1767,13 @@ static int processMetadataFile(Package pkg, FileList fl, const char * fileURL,
     } else
        fn = rpmGenPath(buildURL, NULL, fn);
 
+/*@-branchstate@*/
     switch (tag) {
     default:
        rpmError(RPMERR_BADSPEC, _("%s: can't load unknown tag (%d).\n"),
                fn, tag);
        goto exit;
-       /*@notreached@*/
+       /*@notreached@*/ break;
     case RPMTAG_PUBKEYS:
        if ((rc = pgpReadPkts(fn, &pkt, &pktlen)) <= 0) {
            rpmError(RPMERR_BADSPEC, _("%s: public key read failed.\n"), fn);
@@ -1793,6 +1794,7 @@ static int processMetadataFile(Package pkg, FileList fl, const char * fileURL,
        pkt = NULL;
        break;
     }
+/*@=branchstate@*/
 
     xx = headerAddOrAppendEntry(pkg->header, tag,
                RPM_STRING_ARRAY_TYPE, &apkt, 1);
index f720e22..48bce30 100644 (file)
--- a/lib/fsm.c
+++ b/lib/fsm.c
@@ -1274,7 +1274,9 @@ static int fsmMkdirs(/*@special@*/ /*@partial@*/ FSM_t fsm)
     int dc = dnlCount(dnli);
     int rc = 0;
     int i;
+/*@-compdef@*/
     rpmts ts = fsmGetTs(fsm);
+/*@=compdef@*/
     rpmsx sx = rpmtsREContext(ts);
 
     fsm->path = NULL;
index 031a531..0ac8703 100644 (file)
@@ -26,22 +26,27 @@ enum {
 typedef struct {
        int fd;
        int openmode;
-} rpmlock;
+} rpmlock;
 
-static rpmlock *rpmlock_new(const char *rootdir)
+/*@null@*/
+static rpmlock rpmlock_new(const char *rootdir)
+       /*@globals fileSystem @*/
+       /*@modifies fileSystem @*/
 {
-       rpmlock *lock = (rpmlock *)malloc(sizeof(rpmlock));
+       rpmlock lock = (rpmlock) malloc(sizeof(*lock));
        if (lock) {
                mode_t oldmask = umask(022);
                char *path = (char *)malloc(strlen(rootdir)+
-                                           strlen(RPMLOCK_FILE)+2);
+                                           sizeof(RPMLOCK_FILE)+1);
                if (!path) {
                        free(lock);
                        return NULL;
                }
                sprintf(path, "%s/%s", rootdir, RPMLOCK_FILE);
                lock->fd = open(RPMLOCK_FILE, O_RDWR|O_CREAT, 0644);
-               umask(oldmask);
+               (void) umask(oldmask);
+
+/*@-branchstate@*/
                if (lock->fd == -1) {
                        lock->fd = open(RPMLOCK_FILE, O_RDONLY);
                        if (lock->fd == -1) {
@@ -53,19 +58,25 @@ static rpmlock *rpmlock_new(const char *rootdir)
                } else {
                        lock->openmode = RPMLOCK_WRITE | RPMLOCK_READ;
                }
+/*@=branchstate@*/
        }
+/*@-compdef@*/
        return lock;
+/*@=compdef@*/
 }
 
-static void rpmlock_free(rpmlock *lock)
+static void rpmlock_free(/*@only@*/ /*@null@*/ rpmlock lock)
+       /*@globals fileSystem, internalState @*/
+       /*@modifies lock, fileSystem, internalState @*/
 {
        if (lock) {
-               close(lock->fd);
+               (void) close(lock->fd);
                free(lock);
        }
 }
 
-static int rpmlock_acquire(rpmlock *lock, int mode)
+static int rpmlock_acquire(/*@null@*/ rpmlock lock, int mode)
+       /*@*/
 {
        int res = 0;
        if (lock && (mode & lock->openmode)) {
@@ -82,13 +93,16 @@ static int rpmlock_acquire(rpmlock *lock, int mode)
                info.l_whence = SEEK_SET;
                info.l_start = 0;
                info.l_len = 0;
+               info.l_pid = 0;
                if (fcntl(lock->fd, cmd, &info) != -1)
                        res = 1;
        }
        return res;
 }
 
-static void rpmlock_release(rpmlock *lock)
+static void rpmlock_release(/*@null@*/ rpmlock lock)
+       /*@globals internalState @*/
+       /*@modifies internalState @*/
 {
        if (lock) {
                struct flock info;
@@ -96,7 +110,8 @@ static void rpmlock_release(rpmlock *lock)
                info.l_whence = SEEK_SET;
                info.l_start = 0;
                info.l_len = 0;
-               fcntl(lock->fd, F_SETLK, &info);
+               info.l_pid = 0;
+               (void) fcntl(lock->fd, F_SETLK, &info);
        }
 }
 
@@ -106,10 +121,12 @@ static void rpmlock_release(rpmlock *lock)
 void *rpmtsAcquireLock(rpmts ts)
 {
        const char *rootDir = rpmtsRootDir(ts);
-       rpmlock *lock;
+       rpmlock lock;
+
        if (!rootDir)
                rootDir = "/";
        lock = rpmlock_new(rootDir);
+/*@-branchstate@*/
        if (!lock) {
                rpmMessage(RPMMESS_ERROR, _("can't create transaction lock\n"));
        } else if (!rpmlock_acquire(lock, RPMLOCK_WRITE)) {
@@ -123,13 +140,14 @@ void *rpmtsAcquireLock(rpmts ts)
                        lock = NULL;
                }
        }
+/*@=branchstate@*/
        return lock;
 }
 
 void rpmtsFreeLock(void *lock)
 {
-       rpmlock_release((rpmlock *)lock); /* Not really needed here. */
-       rpmlock_free((rpmlock *)lock);
+       rpmlock_release((rpmlock)lock); /* Not really needed here. */
+       rpmlock_free((rpmlock)lock);
 }
 
 
index cfd84f7..c36566f 100644 (file)
@@ -1,7 +1,12 @@
 #ifndef RPMLOCK_H
 #define RPMLOCK_H 
 
-void *rpmtsAcquireLock(rpmts ts);
-void rpmtsFreeLock(void *lock);
+/*@only@*/ /*@null@*/
+void * rpmtsAcquireLock(rpmts ts)
+       /*@globals fileSystem, internalState @*/
+       /*@modifies fileSystem, internalState @*/;
+void rpmtsFreeLock(/*@only@*/ /*@null@*/ void *lock)
+       /*@globals fileSystem, internalState @*/
+       /*@modifies lock, fileSystem, internalState @*/;
 
 #endif
index f45b7f8..3da2411 100644 (file)
@@ -26,7 +26,7 @@ static void rpmsxSort(rpmsx sx)
     int i, j;
 
     /* Stable sort for policy regex's and paths. */
-    sxp = xmalloc(sizeof(*sxp) * sx->Count);
+    sxp = xcalloc(sx->Count, sizeof(*sxp));
 
     /* Regex patterns first ... */
     j = 0;
index 4bf8486..0b2f06c 100644 (file)
@@ -953,15 +953,16 @@ int rpmtsRun(rpmts ts, rpmps okProbs, rpmprobFilterFlags ignoreSet)
     rpmtsi qi; rpmte q;
     int numAdded;
     int numRemoved;
+    void * lock;
     int xx;
 
     /* XXX programmer error segfault avoidance. */
     if (rpmtsNElements(ts) <= 0)
        return -1;
 
-    void *lock = rpmtsAcquireLock(ts);
-    if (!lock)
-       return -1;
+    lock = rpmtsAcquireLock(ts);
+    if (lock == NULL)
+       return -1;      /* XXX W2DO? */
 
     if (rpmtsFlags(ts) & RPMTRANS_FLAG_NOSCRIPTS)
        (void) rpmtsSetFlags(ts, (rpmtsFlags(ts) | _noTransScripts | _noTransTriggers));
index 872ea79..5f10a5f 100644 (file)
@@ -13,6 +13,7 @@
 #define        POPT_WCHAR_HACK
 #ifdef         POPT_WCHAR_HACK
 #include <wchar.h>                     /* for mbsrtowcs */
+/*@access mbstate_t @*/
 #endif
 #include "poptint.h"
 
@@ -340,11 +341,11 @@ static void singleOptionHelp(FILE * fp, size_t maxLeftCol,
                mbstate_t t;
                size_t n;
 
-               memset (&t, '\0', sizeof (t));  /* In initial state.  */
+               memset ((void *)&t, '\0', sizeof (t));  /* In initial state.  */
                /* Determine number of characters.  */
                n = mbsrtowcs (NULL, &scopy, strlen(scopy), &t);
 
-               displaypad = (lelen-n);
+               displaypad = (int) (lelen-n);
            }
 #endif
        }
@@ -381,7 +382,7 @@ static void singleOptionHelp(FILE * fp, size_t maxLeftCol,
        while (ch > (help + 1) && isspace(*ch)) ch--;
        ch++;
 
-       sprintf(format, "%%.%ds\n%%%ds", (int) (ch - help), indentLength);
+       sprintf(format, "%%.%ds\n%%%ds", (int) (ch - help), (int) indentLength);
        /*@-formatconst@*/
        fprintf(fp, format, help, " ");
        /*@=formatconst@*/
@@ -439,7 +440,9 @@ static size_t maxArgWidth(const struct poptOption * opt,
                mbstate_t t;
                size_t n;
 
-               memset (&t, '\0', sizeof (t));  /* In initial state.  */
+/*@-boundswrite@*/
+               memset ((void *)&t, '\0', sizeof (t));  /* In initial state.  */
+/*@=boundswrite@*/
                /* Determine number of characters.  */
                n = mbsrtowcs (NULL, &scopy, strlen(scopy), &t);
                len += sizeof("=")-1 + n;
@@ -613,7 +616,9 @@ static size_t singleOptionUsage(FILE * fp, size_t cursor,
        mbstate_t t;
        size_t n;
 
-       memset (&t, '\0', sizeof (t));  /* In initial state.  */
+/*@-boundswrite@*/
+       memset ((void *)&t, '\0', sizeof (t));  /* In initial state.  */
+/*@=boundswrite@*/
        /* Determine number of characters.  */
        n = mbsrtowcs (NULL, &scopy, strlen(scopy), &t);
        len += sizeof("=")-1 + n;
index 8505a02..6e3162f 100644 (file)
@@ -482,6 +482,9 @@ exit 0
 %{__includedir}/popt.h
 
 %changelog
+* Wed Feb 25 2004 Jeff Johnson <jbj@jbj.org> 4.3-0.15
+- serialize rpmtsRun() using fcntl on /var/lock/rpm/transaction.
+
 * Sun Feb 22 2004 Jeff Johnson <jbj@jbj.org> 4.3-0.14
 - add ia32e arch.
 - stable sort for policy specifications, patterns before paths.