- macosx: change to --prefix=/usr rather than /opt/local.
[platform/upstream/rpm.git] / rpmio / rpmsq.c
index 4285f1a..c49e9cd 100644 (file)
@@ -126,10 +126,15 @@ extern int pthread_cond_signal(pthread_cond_t *cond)
 
 #include <pthread.h>
 
+#ifndef PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
+/*@unchecked@*/
+static pthread_mutex_t rpmsigTbl_lock = PTHREAD_MUTEX_INITIALIZER;
+#else
 /*@unchecked@*/
 /*@-type@*/
 static pthread_mutex_t rpmsigTbl_lock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
 /*@=type@*/
+#endif
 
 #define        DO_LOCK()       pthread_mutex_lock(&rpmsigTbl_lock);
 #define        DO_UNLOCK()     pthread_mutex_unlock(&rpmsigTbl_lock);
@@ -147,7 +152,7 @@ static pthread_mutex_t rpmsigTbl_lock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
     (void) pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, (__oldtypeptr));\
        pthread_cleanup_push((__handler), (__arg));
 #define        CLEANUP_RESET(__execute, __oldtype) \
-    (void) pthread_cleanup_pop(__execute); \
+    pthread_cleanup_pop(__execute); \
     (void) pthread_setcanceltype ((__oldtype), &(__oldtype));
 
 #define        SAME_THREAD(_a, _b)     pthread_equal(((pthread_t)_a), ((pthread_t)_b))
@@ -201,7 +206,7 @@ fprintf(stderr, "    Insert(%p): %p\n", ME(), sq);
            sq->child = 0;
            sq->reaped = 0;
            sq->status = 0;
-           sq->reaper = 1;
+           sq->reaper = 0;
 /*@-bounds@*/
            sq->pipes[0] = sq->pipes[1] = -1;
 /*@=bounds@*/
@@ -341,15 +346,23 @@ int rpmsqEnable(int signum, /*@null@*/ rpmsqAction_t handler)
        if (signum >= 0) {                      /* Enable. */
            if (ADD_REF(tbl) <= 0) {
                (void) sigdelset(&rpmsqCaught, tbl->signum);
+
+               /* XXX Don't set a signal handler if already SIG_IGN */
+               (void) sigaction(tbl->signum, NULL, &tbl->oact);
+               if (tbl->oact.sa_handler == SIG_IGN)
+                   continue;
+
                (void) sigemptyset (&sa.sa_mask);
-/*@-compdef -type @*/
                sa.sa_flags = SA_SIGINFO;
+#if defined(__LCLINT__)        /* XXX glibc has union to track handler prototype. */
+               sa.sa_handler = (handler != NULL ? handler : tbl->handler);
+#else
                sa.sa_sigaction = (handler != NULL ? handler : tbl->handler);
+#endif
                if (sigaction(tbl->signum, &sa, &tbl->oact) < 0) {
                    SUB_REF(tbl);
                    break;
                }
-/*@=compdef =type @*/
                tbl->active = 1;                /* XXX just in case */
                if (handler != NULL)
                    tbl->handler = handler;
@@ -596,6 +609,10 @@ rpmsqExecve (const char ** argv)
     sigset_t newMask, oldMask;
     rpmsq sq = memset(alloca(sizeof(*sq)), 0, sizeof(*sq));
 
+#ifndef PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
+       INIT_LOCK ();
+#endif
+
     (void) DO_LOCK ();
     if (ADD_REF (rpmsigTbl_sigchld) == 0) {
        if (rpmsqEnable(SIGINT, NULL) < 0) {