- fix: register SIGCHLD handler before forking (#73134).
authorjbj <devnull@localhost>
Wed, 4 Sep 2002 18:08:12 +0000 (18:08 +0000)
committerjbj <devnull@localhost>
Wed, 4 Sep 2002 18:08:12 +0000 (18:08 +0000)
CVS patchset: 5704
CVS date: 2002/09/04 18:08:12

CHANGES
lib/psm.c
rpmdb/header.c

diff --git a/CHANGES b/CHANGES
index f339ef1..31b304e 100644 (file)
--- a/CHANGES
+++ b/CHANGES
        - python: typo in NOKEY exception string.
        - fix: parse pgp packets more carefully.
        - fix: parse header data more carefully.
+       - fix: register SIGCHLD handler before forking (#73134).
 
 4.0.3 -> 4.0.4:
        - solaris: translate i86pc to i386 (#57182).
index 026722a..31bcfa8 100644 (file)
--- a/lib/psm.c
+++ b/lib/psm.c
@@ -779,9 +779,31 @@ fprintf(stderr, "   Disable: %p[0:%d:%d] active %d\n", psmtbl.psms, psmtbl.npsms
 }
 
 /**
- * Register a child reaper.
+ * Fork a new process.
+ * @param psm          package state machine data
+ * @return             fork(2) pid
+ */
+static pid_t psmFork(rpmpsm psm)
+       /*@globals fileSystem, internalState @*/
+       /*@modifies psm, fileSystem, internalState @*/
+{
+    pid_t pid;
+
+    if ((pid = fork()) != 0) {
+/*@-modfilesys@*/
+if (_psm_debug)
+fprintf(stderr, "      Fork: %p[%d:%d:%d] = %p child %d\n", psmtbl.psms, 0, psmtbl.npsms, psmtbl.nalloced, psm, pid);
+/*@=modfilesys@*/
+    }
+    return pid;
+}
+
+/**
+ * Register a child reaper, then fork a child.
+ * @param psm          package state machine data
+ * @return             fork(2) pid
  */
-static int psmRegister(rpmpsm psm, pid_t child)
+static pid_t psmRegisterFork(rpmpsm psm)
        /*@globals psmtbl, fileSystem @*/
        /*@modifies psm, psmtbl, fileSystem @*/
 {
@@ -810,17 +832,18 @@ static int psmRegister(rpmpsm psm, pid_t child)
        }
        empty = psmtbl.npsms++;
     }
-    psm->child = child;
     psm->reaped = 0;
     if (psmtbl.psms)   /* XXX can't happen */
        psmtbl.psms[empty] = rpmpsmLink(psm, "psmRegister");
 /*@-modfilesys@*/
 if (_psm_debug)
-fprintf(stderr, "  Register: %p[%d:%d:%d] = %p child %d\n", psmtbl.psms, empty, psmtbl.npsms, psmtbl.nalloced, psm, child);
+fprintf(stderr, "  Register: %p[%d:%d:%d] = %p\n", psmtbl.psms, empty, psmtbl.npsms, psmtbl.nalloced, psm);
 /*@=modfilesys@*/
 
     (void) enableSignal(SIGCHLD);
-    return sigprocmask(SIG_SETMASK, &oldMask, NULL);
+    (void) sigprocmask(SIG_SETMASK, &oldMask, NULL);
+
+    return psmFork(psm);
 }
 
 /**
@@ -867,33 +890,6 @@ fprintf(stderr, "Unregister: %p[%d:%d:%d] = %p child %d\n", psmtbl.psms, i, psmt
 }
 
 /**
- * Register a new child process with the reaper.
- * @param psm          package state machine data
- * @return             
- */
-static pid_t psmFork(rpmpsm psm)
-       /*@globals fileSystem, internalState @*/
-       /*@modifies psm, fileSystem, internalState @*/
-{
-    pid_t child;
-
-    /* Fork and Register parent's signal handler. */
-    if ((child = fork()) != 0) {
-       if (!psm->reaper) {
-           psm->child = child;
-           psm->reaped = 0;
-       } else {
-           (void) psmRegister(psm, child);
-       }
-/*@-modfilesys@*/
-if (_psm_debug)
-fprintf(stderr, "      Fork: %p[%d:%d:%d] = %p child %d\n", psmtbl.psms, 0, psmtbl.npsms, psmtbl.nalloced, psm, child);
-/*@=modfilesys@*/
-    }
-    return child;
-}
-
-/**
  * Return reaped pid safely (i.e. with signals blocked).
  * @param psm          package state machine data
  * @return             
@@ -1117,7 +1113,7 @@ static rpmRC runScript(rpmpsm psm, Header h, const char * sln,
     if (out == NULL) return RPMRC_FAIL;        /* XXX can't happen */
     
     /*@-branchstate@*/
-    if (!psmFork(psm)) {
+    if ((psm->child = psmRegisterFork(psm)) == 0) {
        const char * rootDir;
        int pipes[2];
 
index 9c2ce1b..d0c1592 100644 (file)
@@ -341,9 +341,8 @@ unsigned int headerSizeof(/*@null@*/ Header h, enum hMagic magicp)
  * @param pend         pointer to end of data (or NULL)
  * @return             no. bytes in data, -1 on failure
  */
-/*@mayexit@*/
 static int dataLength(int_32 type, hPTR_t p, int_32 count, int onDisk,
-               hPTR_t pend)
+               /*@null@*/ hPTR_t pend)
        /*@*/
 {
     const unsigned char * s = p;
@@ -1884,6 +1883,8 @@ int headerAppendEntry(Header h, int_32 tag, int_32 type,
        return 0;
 
     length = dataLength(type, p, c, 0, NULL);
+    if (length < 0)
+       return 0;
 
     if (ENTRY_IN_REGION(entry)) {
        char * t = xmalloc(entry->length + length);