summaryrefslogtreecommitdiff
path: root/package/rpm/patches/patch-rpmio_rpmsq_c
blob: 779101b6238536f6cbb06e9dd22688a15d8af142 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
--- rpm-4.7.0.orig/rpmio/rpmsq.c	2009-03-03 07:51:52.000000000 +0100
+++ rpm-4.7.0/rpmio/rpmsq.c	2009-06-25 20:15:31.954966249 +0200
@@ -83,6 +83,7 @@ static rpmsq rpmsqQueue = &rpmsqRock;
  */
 static int rpmsqInsert(void * elem, void * prev)
 {
+    sigset_t new_set, old_set;
     rpmsq sq = (rpmsq) elem;
     int ret = -1;
 
@@ -91,7 +92,9 @@ static int rpmsqInsert(void * elem, void
 if (_rpmsq_debug)
 fprintf(stderr, "    Insert(%p): %p\n", ME(), sq);
 #endif
-	ret = sighold(SIGCHLD);
+	sigemptyset(&new_set);
+	sigaddset(&new_set, SIGCHLD);
+	ret = sigprocmask(SIG_BLOCK, &new_set, &old_set);
 	if (ret == 0) {
 	    sq->child = 0;
 	    sq->reaped = 0;
@@ -102,7 +105,7 @@ fprintf(stderr, "    Insert(%p): %p\n", 
 	    sq->id = ME();
 	    ret = pthread_mutex_init(&sq->mutex, NULL);
 	    insque(elem, (prev != NULL ? prev : rpmsqQueue));
-	    ret = sigrelse(SIGCHLD);
+	    ret = sigprocmask(SIG_SETMASK, &old_set, NULL);
 	}
     }
     return ret;
@@ -115,6 +118,7 @@ fprintf(stderr, "    Insert(%p): %p\n", 
  */
 static int rpmsqRemove(void * elem)
 {
+    sigset_t new_set, old_set;
     rpmsq sq = (rpmsq) elem;
     int ret = -1;
 
@@ -124,7 +128,9 @@ static int rpmsqRemove(void * elem)
 if (_rpmsq_debug)
 fprintf(stderr, "    Remove(%p): %p\n", ME(), sq);
 #endif
-	ret = sighold (SIGCHLD);
+	sigemptyset(&new_set);
+	sigaddset(&new_set, SIGCHLD);
+	ret = sigprocmask(SIG_BLOCK, &new_set, &old_set);
 	if (ret == 0) {
 	    remque(elem);
 	   
@@ -142,7 +148,7 @@ fprintf(stderr, "    Remove(%p): %p\n", 
 	    sq->reaped = 0;
 	    sq->child = 0;
 #endif
-	    ret = sigrelse(SIGCHLD);
+	    ret = sigprocmask(SIG_SETMASK, &old_set, NULL);
 	}
     }
     return ret;
@@ -289,6 +295,7 @@ int rpmsqEnable(int signum, rpmsqAction_
 
 pid_t rpmsqFork(rpmsq sq)
 {
+    sigset_t new_set, old_set;
     pid_t pid;
     int xx;
     int nothreads = 0;   /* XXX: Shouldn't this be a global? */
@@ -304,7 +311,9 @@ fprintf(stderr, "    Enable(%p): %p\n", 
 
     xx = pipe(sq->pipes);
 
-    xx = sighold(SIGCHLD);
+    sigemptyset(&new_set);
+    sigaddset(&new_set, SIGCHLD);
+    xx = sigprocmask(SIG_BLOCK, &new_set, &old_set);
 
     /* 
      * Initialize the cond var mutex.   We have to aquire the lock we 
@@ -355,7 +364,7 @@ fprintf(stderr, "    Parent(%p): %p chil
     }
 
 out:
-    xx = sigrelse(SIGCHLD);
+    xx = sigprocmask(SIG_SETMASK, &old_set, NULL);
     return sq->child;
 }
 
@@ -367,12 +376,15 @@ out:
  */
 static int rpmsqWaitUnregister(rpmsq sq)
 {
+    sigset_t new_set, old_set;
     int nothreads = 0;
     int ret = 0;
     int xx;
 
     /* Protect sq->reaped from handler changes. */
-    ret = sighold(SIGCHLD);
+    sigemptyset(&new_set);
+    sigaddset(&new_set, SIGCHLD);
+    ret = sigprocmask(SIG_BLOCK, &new_set, &old_set);
 
     /* Start the child, linux often runs child before parent. */
     if (sq->pipes[0] >= 0)
@@ -388,9 +400,9 @@ static int rpmsqWaitUnregister(rpmsq sq)
     while (ret == 0 && sq->reaped != sq->child) {
 	if (nothreads)
 	    /* Note that sigpause re-enables SIGCHLD. */
-	    ret = sigpause(SIGCHLD);
+	    ret = sigsuspend(&new_set);
 	else {
-	    xx = sigrelse(SIGCHLD);
+    	    xx = sigprocmask(SIG_SETMASK, &old_set, NULL);
 	    
 	    /* 
 	     * We start before the fork with this mutex locked;
@@ -398,14 +410,14 @@ static int rpmsqWaitUnregister(rpmsq sq)
 	     * So if we get the lock the child has been reaped.
 	     */
 	    ret = pthread_mutex_lock(&sq->mutex);
-	    xx = sighold(SIGCHLD);
+	    xx = sigprocmask(SIG_BLOCK, &new_set, &old_set);
 	}
     }
 
     /* Accumulate stopwatch time spent waiting, potential performance gain. */
     sq->ms_scriptlets += rpmswExit(&sq->op, -1)/1000;
 
-    xx = sigrelse(SIGCHLD);
+    xx = sigprocmask(SIG_SETMASK, &old_set, NULL);
 
 #ifdef _RPMSQ_DEBUG
 if (_rpmsq_debug)