rpm  4.5
rpmsq.c
Go to the documentation of this file.
1 
5 #include "system.h"
6 
7 #if defined(__LCLINT__)
8 #define _BITS_SIGTHREAD_H /* XXX avoid __sigset_t heartburn. */
9 
10 /*@-incondefs -protoparammatch@*/
11 /*@-exportheader@*/
12 /*@constant int SA_SIGINFO@*/
13 extern int sighold(int sig)
14  /*@globals errno, systemState @*/;
15 extern int sigignore(int sig)
16  /*@globals errno, systemState @*/;
17 extern int sigpause(int sig)
18  /*@globals errno, systemState @*/;
19 extern int sigrelse(int sig)
20  /*@globals errno, systemState @*/;
21 extern void (*sigset(int sig, void (*disp)(int)))(int)
22  /*@globals errno, systemState @*/;
23 
24 struct qelem;
25 extern void insque(struct qelem * __elem, struct qelem * __prev)
26  /*@modifies __elem, __prev @*/;
27 extern void remque(struct qelem * __elem)
28  /*@modifies __elem @*/;
29 
30 extern pthread_t pthread_self(void)
31  /*@*/;
32 extern int pthread_equal(pthread_t t1, pthread_t t2)
33  /*@*/;
34 
35 extern int pthread_create(/*@out@*/ pthread_t *restrict thread,
36  const pthread_attr_t *restrict attr,
37  void *(*start_routine)(void*), void *restrict arg)
38  /*@modifies *thread @*/;
39 extern int pthread_join(pthread_t thread, /*@out@*/ void **value_ptr)
40  /*@modifies *value_ptr @*/;
41 
42 extern int pthread_setcancelstate(int state, /*@out@*/ int *oldstate)
43  /*@globals internalState @*/
44  /*@modifies *oldstate, internalState @*/;
45 extern int pthread_setcanceltype(int type, /*@out@*/ int *oldtype)
46  /*@globals internalState @*/
47  /*@modifies *oldtype, internalState @*/;
48 extern void pthread_testcancel(void)
49  /*@globals internalState @*/
50  /*@modifies internalState @*/;
51 extern void pthread_cleanup_pop(int execute)
52  /*@globals internalState @*/
53  /*@modifies internalState @*/;
54 extern void pthread_cleanup_push(void (*routine)(void*), void *arg)
55  /*@globals internalState @*/
56  /*@modifies internalState @*/;
57 extern void _pthread_cleanup_pop(/*@out@*/ struct _pthread_cleanup_buffer *__buffer, int execute)
58  /*@globals internalState @*/
59  /*@modifies internalState @*/;
60 extern void _pthread_cleanup_push(/*@out@*/ struct _pthread_cleanup_buffer *__buffer, void (*routine)(void*), /*@out@*/ void *arg)
61  /*@globals internalState @*/
62  /*@modifies internalState @*/;
63 
64 extern int pthread_mutexattr_destroy(pthread_mutexattr_t *attr)
65  /*@globals errno, internalState @*/
66  /*@modifies *attr, errno, internalState @*/;
67 extern int pthread_mutexattr_init(/*@out@*/ pthread_mutexattr_t *attr)
68  /*@globals errno, internalState @*/
69  /*@modifies *attr, errno, internalState @*/;
70 
71 int pthread_mutexattr_gettype(const pthread_mutexattr_t *restrict attr,
72  /*@out@*/ int *restrict type)
73  /*@modifies *type @*/;
74 int pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type)
75  /*@globals errno, internalState @*/
76  /*@modifies *attr, errno, internalState @*/;
77 
78 extern int pthread_mutex_destroy(pthread_mutex_t *mutex)
79  /*@modifies *mutex @*/;
80 extern int pthread_mutex_init(/*@out@*/ pthread_mutex_t *restrict mutex,
81  /*@null@*/ const pthread_mutexattr_t *restrict attr)
82  /*@globals errno, internalState @*/
83  /*@modifies *mutex, errno, internalState @*/;
84 
85 extern int pthread_mutex_lock(pthread_mutex_t *mutex)
86  /*@globals errno @*/
87  /*@modifies *mutex, errno @*/;
88 extern int pthread_mutex_trylock(pthread_mutex_t *mutex)
89  /*@globals errno @*/
90  /*@modifies *mutex, errno @*/;
91 extern int pthread_mutex_unlock(pthread_mutex_t *mutex)
92  /*@globals errno @*/
93  /*@modifies *mutex, errno @*/;
94 
95 extern int pthread_cond_destroy(pthread_cond_t *cond)
96  /*@modifies *cond @*/;
97 extern int pthread_cond_init(/*@out@*/ pthread_cond_t *restrict cond,
98  const pthread_condattr_t *restrict attr)
99  /*@globals errno, internalState @*/
100  /*@modifies *cond, errno, internalState @*/;
101 
102 extern int pthread_cond_timedwait(pthread_cond_t *restrict cond,
103  pthread_mutex_t *restrict mutex,
104  const struct timespec *restrict abstime)
105  /*@modifies *cond, *mutex @*/;
106 extern int pthread_cond_wait(pthread_cond_t *restrict cond,
107  pthread_mutex_t *restrict mutex)
108  /*@modifies *cond, *mutex @*/;
109 extern int pthread_cond_broadcast(pthread_cond_t *cond)
110  /*@globals errno, internalState @*/
111  /*@modifies *cond, errno, internalState @*/;
112 extern int pthread_cond_signal(pthread_cond_t *cond)
113  /*@globals errno, internalState @*/
114  /*@modifies *cond, errno, internalState @*/;
115 
116 /*@=exportheader@*/
117 /*@=incondefs =protoparammatch@*/
118 #endif
119 
120 #include <signal.h>
121 #include <sys/signal.h>
122 #include <sys/wait.h>
123 #include <search.h>
124 
125 #if defined(HAVE_PTHREAD_H)
126 
127 #include <pthread.h>
128 
129 /* XXX suggested in bugzilla #159024 */
130 #if PTHREAD_MUTEX_DEFAULT != PTHREAD_MUTEX_NORMAL
131  #error RPM expects PTHREAD_MUTEX_DEFAULT == PTHREAD_MUTEX_NORMAL
132 #endif
133 
134 #ifndef PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
135 /*@unchecked@*/
136 static pthread_mutex_t rpmsigTbl_lock = PTHREAD_MUTEX_INITIALIZER;
137 #else
138 /*@unchecked@*/
139 /*@-type@*/
140 static pthread_mutex_t rpmsigTbl_lock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
141 /*@=type@*/
142 #endif
143 
144 #define DO_LOCK() pthread_mutex_lock(&rpmsigTbl_lock);
145 #define DO_UNLOCK() pthread_mutex_unlock(&rpmsigTbl_lock);
146 #define INIT_LOCK() \
147  { pthread_mutexattr_t attr; \
148  (void) pthread_mutexattr_init(&attr); \
149  (void) pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); \
150  (void) pthread_mutex_init (&rpmsigTbl_lock, &attr); \
151  (void) pthread_mutexattr_destroy(&attr); \
152  rpmsigTbl_sigchld->active = 0; \
153  }
154 #define ADD_REF(__tbl) (__tbl)->active++
155 #define SUB_REF(__tbl) --(__tbl)->active
156 #define CLEANUP_HANDLER(__handler, __arg, __oldtypeptr) \
157  (void) pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, (__oldtypeptr));\
158  pthread_cleanup_push((__handler), (__arg));
159 #define CLEANUP_RESET(__execute, __oldtype) \
160  pthread_cleanup_pop(__execute); \
161  (void) pthread_setcanceltype ((__oldtype), &(__oldtype));
162 
163 #define SAME_THREAD(_a, _b) pthread_equal(((pthread_t)_a), ((pthread_t)_b))
164 
165 #define ME() ((void *)pthread_self())
166 
167 #else
168 
169 #define DO_LOCK()
170 #define DO_UNLOCK()
171 #define INIT_LOCK()
172 #define ADD_REF(__tbl) /*@-noeffect@*/ (0) /*@=noeffect@*/
173 #define SUB_REF(__tbl) /*@-noeffect@*/ (0) /*@=noeffect@*/
174 #define CLEANUP_HANDLER(__handler, __arg, __oldtypeptr)
175 #define CLEANUP_RESET(__execute, __oldtype)
176 
177 #define SAME_THREAD(_a, _b) (42)
178 
179 #define ME() (((void *)getpid()))
180 
181 #endif /* HAVE_PTHREAD_H */
182 
183 #include <rpmsq.h>
184 
185 #include "debug.h"
186 
187 #define _RPMSQ_DEBUG 0
188 /*@unchecked@*/
190 
191 /*@unchecked@*/
192 static struct rpmsqElem rpmsqRock;
193 
194 /*@-compmempass@*/
195 /*@unchecked@*/
197 /*@=compmempass@*/
198 
199 int rpmsqInsert(void * elem, void * prev)
200 {
201  rpmsq sq = (rpmsq) elem;
202  int ret = -1;
203 
204  if (sq != NULL) {
205 #ifdef _RPMSQ_DEBUG
206 if (_rpmsq_debug)
207 fprintf(stderr, " Insert(%p): %p\n", ME(), sq);
208 #endif
209  ret = sighold(SIGCHLD);
210  if (ret == 0) {
211  sq->child = 0;
212  sq->reaped = 0;
213  sq->status = 0;
214  /* ==> Set to 1 to catch SIGCHLD, set to 0 to use waitpid(2). */
215  sq->reaper = 1;
216 /*@-bounds@*/
217  sq->pipes[0] = sq->pipes[1] = -1;
218 /*@=bounds@*/
219 
220  sq->id = ME();
221  insque(elem, (prev != NULL ? prev : rpmsqQueue));
222  ret = sigrelse(SIGCHLD);
223  }
224  }
225  return ret;
226 }
227 
228 int rpmsqRemove(void * elem)
229 {
230  rpmsq sq = (rpmsq) elem;
231  int ret = -1;
232 
233  if (elem != NULL) {
234 
235 #ifdef _RPMSQ_DEBUG
236 if (_rpmsq_debug)
237 fprintf(stderr, " Remove(%p): %p\n", ME(), sq);
238 #endif
239  ret = sighold (SIGCHLD);
240  if (ret == 0) {
241  remque(elem);
242  sq->id = NULL;
243 /*@-bounds@*/
244  if (sq->pipes[1] > 0) ret = close(sq->pipes[1]);
245  if (sq->pipes[0] > 0) ret = close(sq->pipes[0]);
246  sq->pipes[0] = sq->pipes[1] = -1;
247 /*@=bounds@*/
248 #ifdef NOTYET /* rpmpsmWait debugging message needs */
249  sq->status = 0;
250  sq->reaped = 0;
251  sq->child = 0;
252 #endif
253  ret = sigrelse(SIGCHLD);
254  }
255  }
256  return ret;
257 }
258 
259 /*@unchecked@*/
260 sigset_t rpmsqCaught;
261 
262 /*@unchecked@*/
263 /*@-fullinitblock@*/
264 static struct rpmsig_s {
265  int signum;
266  void (*handler) (int signum, void * info, void * context);
267  int active;
268  struct sigaction oact;
269 } rpmsigTbl[] = {
270  { SIGINT, rpmsqAction },
271 #define rpmsigTbl_sigint (&rpmsigTbl[0])
272  { SIGQUIT, rpmsqAction },
273 #define rpmsigTbl_sigquit (&rpmsigTbl[1])
274  { SIGCHLD, rpmsqAction },
275 #define rpmsigTbl_sigchld (&rpmsigTbl[2])
276  { SIGHUP, rpmsqAction },
277 #define rpmsigTbl_sighup (&rpmsigTbl[3])
278  { SIGTERM, rpmsqAction },
279 #define rpmsigTbl_sigterm (&rpmsigTbl[4])
280  { SIGPIPE, rpmsqAction },
281 #define rpmsigTbl_sigpipe (&rpmsigTbl[5])
282  { -1, NULL },
283 };
284 /*@=fullinitblock@*/
285 
286 void rpmsqAction(int signum,
287  /*@unused@*/ void * info, /*@unused@*/ void * context)
288 {
289  int save = errno;
290  rpmsig tbl;
291 
292  for (tbl = rpmsigTbl; tbl->signum >= 0; tbl++) {
293  if (tbl->signum != signum)
294  continue;
295 
296  (void) sigaddset(&rpmsqCaught, signum);
297 
298  switch (signum) {
299  case SIGCHLD:
300  while (1) {
301  rpmsq sq;
302  int status = 0;
303  pid_t reaped = waitpid(0, &status, WNOHANG);
304 
305  /* XXX errno set to ECHILD/EINVAL/EINTR. */
306  if (reaped <= 0)
307  /*@innerbreak@*/ break;
308 
309  /* XXX insque(3)/remque(3) are dequeue, not ring. */
310  for (sq = rpmsqQueue->q_forw;
311  sq != NULL && sq != rpmsqQueue;
312  sq = sq->q_forw)
313  {
314  int ret;
315 
316  if (sq->child != reaped)
317  /*@innercontinue@*/ continue;
318  sq->reaped = reaped;
319  sq->status = status;
320 
321  ret = close(sq->pipes[1]); sq->pipes[1] = -1;
322 
323  /*@innerbreak@*/ break;
324  }
325  }
326  /*@switchbreak@*/ break;
327  default:
328  /*@switchbreak@*/ break;
329  }
330  break;
331  }
332  errno = save;
333 }
334 
335 int rpmsqEnable(int signum, /*@null@*/ rpmsqAction_t handler)
336  /*@globals rpmsigTbl @*/
337  /*@modifies rpmsigTbl @*/
338 {
339  int tblsignum = (signum >= 0 ? signum : -signum);
340  struct sigaction sa;
341  rpmsig tbl;
342  int ret = -1;
343 
344  (void) DO_LOCK ();
345  if (rpmsqQueue->id == NULL)
346  rpmsqQueue->id = ME();
347  for (tbl = rpmsigTbl; tbl->signum >= 0; tbl++) {
348  if (tblsignum != tbl->signum)
349  continue;
350 
351  if (signum >= 0) { /* Enable. */
352  if (ADD_REF(tbl) <= 0) {
353  (void) sigdelset(&rpmsqCaught, tbl->signum);
354 
355  /* XXX Don't set a signal handler if already SIG_IGN */
356  (void) sigaction(tbl->signum, NULL, &tbl->oact);
357  if (tbl->oact.sa_handler == SIG_IGN)
358  continue;
359 
360  (void) sigemptyset (&sa.sa_mask);
361  sa.sa_flags = SA_SIGINFO;
362 #if defined(__LCLINT__) /* XXX glibc has union to track handler prototype. */
363  sa.sa_handler = (handler != NULL ? handler : tbl->handler);
364 #else
365  sa.sa_sigaction = (handler != NULL ? handler : tbl->handler);
366 #endif
367  if (sigaction(tbl->signum, &sa, &tbl->oact) < 0) {
368  SUB_REF(tbl);
369  break;
370  }
371  tbl->active = 1; /* XXX just in case */
372  if (handler != NULL)
373  tbl->handler = handler;
374  }
375  } else { /* Disable. */
376  if (SUB_REF(tbl) <= 0) {
377  if (sigaction(tbl->signum, &tbl->oact, NULL) < 0)
378  break;
379  tbl->active = 0; /* XXX just in case */
380  tbl->handler = (handler != NULL ? handler : rpmsqAction);
381  }
382  }
383  ret = tbl->active;
384  break;
385  }
386  (void) DO_UNLOCK ();
387  return ret;
388 }
389 
390 pid_t rpmsqFork(rpmsq sq)
391 {
392  pid_t pid;
393  int xx;
394 
395  if (sq->reaper) {
396  xx = rpmsqInsert(sq, NULL);
397 #ifdef _RPMSQ_DEBUG
398 if (_rpmsq_debug)
399 fprintf(stderr, " Enable(%p): %p\n", ME(), sq);
400 #endif
401  xx = rpmsqEnable(SIGCHLD, NULL);
402  }
403 
404  xx = pipe(sq->pipes);
405 
406  xx = sighold(SIGCHLD);
407 
408  pid = fork();
409  if (pid < (pid_t) 0) { /* fork failed. */
410 /*@-bounds@*/
411  xx = close(sq->pipes[0]);
412  xx = close(sq->pipes[1]);
413  sq->pipes[0] = sq->pipes[1] = -1;
414 /*@=bounds@*/
415  goto out;
416  } else if (pid == (pid_t) 0) { /* Child. */
417  int yy;
418 
419  /* Block to permit parent time to wait. */
420 /*@-bounds@*/
421  xx = close(sq->pipes[1]);
422  if (sq->reaper)
423  xx = read(sq->pipes[0], &yy, sizeof(yy));
424  xx = close(sq->pipes[0]);
425  sq->pipes[0] = sq->pipes[1] = -1;
426 /*@=bounds@*/
427 
428 #ifdef _RPMSQ_DEBUG
429 if (_rpmsq_debug)
430 fprintf(stderr, " Child(%p): %p child %d\n", ME(), sq, getpid());
431 #endif
432 
433  } else { /* Parent. */
434 
435  sq->child = pid;
436 
437 #ifdef _RPMSQ_DEBUG
438 if (_rpmsq_debug)
439 fprintf(stderr, " Parent(%p): %p child %d\n", ME(), sq, sq->child);
440 #endif
441 
442  }
443 
444 out:
445  xx = sigrelse(SIGCHLD);
446  return sq->child;
447 }
448 
456  /*@globals fileSystem, internalState @*/
457  /*@modifies sq, fileSystem, internalState @*/
458 {
459  int nothreads = 0;
460  int ret = 0;
461  int xx;
462 
463 assert(sq->reaper);
464  /* Protect sq->reaped from handler changes. */
465  ret = sighold(SIGCHLD);
466 
467  /* Start the child, linux often runs child before parent. */
468 /*@-bounds@*/
469  if (sq->pipes[0] >= 0)
470  xx = close(sq->pipes[0]);
471  if (sq->pipes[1] >= 0)
472  xx = close(sq->pipes[1]);
473 /*@=bounds@*/
474 
475  /* Re-initialize the pipe to receive SIGCHLD receipt confirmation. */
476  xx = pipe(sq->pipes);
477 
478  /* Put a stopwatch on the time spent waiting to measure performance gain. */
479  (void) rpmswEnter(&sq->op, -1);
480 
481  /* Wait for handler to receive SIGCHLD. */
482  /*@-infloops@*/
483  while (ret == 0 && sq->reaped != sq->child) {
484  if (nothreads)
485  /* Note that sigpause re-enables SIGCHLD. */
486  ret = sigpause(SIGCHLD);
487  else {
488  xx = sigrelse(SIGCHLD);
489 
490  /* Signal handler does close(sq->pipes[1]) triggering 0b EOF read */
491  if (read(sq->pipes[0], &xx, sizeof(xx)) == 0) {
492  xx = close(sq->pipes[0]); sq->pipes[0] = -1;
493  ret = 1;
494  }
495 
496  xx = sighold(SIGCHLD);
497  }
498  }
499  /*@=infloops@*/
500 
501  /* Accumulate stopwatch time spent waiting, potential performance gain. */
502  sq->ms_scriptlets += rpmswExit(&sq->op, -1)/1000;
503 
504  xx = sigrelse(SIGCHLD);
505 
506 #ifdef _RPMSQ_DEBUG
507 if (_rpmsq_debug)
508 fprintf(stderr, " Wake(%p): %p child %d reaper %d ret %d\n", ME(), sq, sq->child, sq->reaper, ret);
509 #endif
510 
511  /* Remove processed SIGCHLD item from queue. */
512  xx = rpmsqRemove(sq);
513 
514  /* Disable SIGCHLD handler on refcount == 0. */
515  xx = rpmsqEnable(-SIGCHLD, NULL);
516 #ifdef _RPMSQ_DEBUG
517 if (_rpmsq_debug)
518 fprintf(stderr, " Disable(%p): %p\n", ME(), sq);
519 #endif
520 
521  return ret;
522 }
523 
524 pid_t rpmsqWait(rpmsq sq)
525 {
526 
527 #ifdef _RPMSQ_DEBUG
528 if (_rpmsq_debug)
529 fprintf(stderr, " Wait(%p): %p child %d reaper %d\n", ME(), sq, sq->child, sq->reaper);
530 #endif
531 
532  if (sq->reaper) {
533  (void) rpmsqWaitUnregister(sq);
534  } else {
535  pid_t reaped;
536  int status;
537  do {
538  reaped = waitpid(sq->child, &status, 0);
539  } while (reaped >= 0 && reaped != sq->child);
540  sq->reaped = reaped;
541  sq->status = status;
542 #ifdef _RPMSQ_DEBUG
543 if (_rpmsq_debug)
544 fprintf(stderr, " Waitpid(%p): %p child %d reaped %d\n", ME(), sq, sq->child, sq->reaped);
545 #endif
546  }
547 
548 #ifdef _RPMSQ_DEBUG
549 if (_rpmsq_debug)
550 fprintf(stderr, " Fini(%p): %p child %d status 0x%x\n", ME(), sq, sq->child, sq->status);
551 #endif
552 
553  return sq->reaped;
554 }
555 
556 void * rpmsqThread(void * (*start) (void * arg), void * arg)
557 {
558  pthread_t pth;
559  int ret;
560 
561  ret = pthread_create(&pth, NULL, start, arg);
562  return (ret == 0 ? (void *)pth : NULL);
563 }
564 
565 int rpmsqJoin(void * thread)
566 {
567  pthread_t pth = (pthread_t) thread;
568  if (thread == NULL)
569  return EINVAL;
570  return pthread_join(pth, NULL);
571 }
572 
573 int rpmsqThreadEqual(void * thread)
574 {
575  pthread_t t1 = (pthread_t) thread;
576  pthread_t t2 = pthread_self();
577  return pthread_equal(t1, t2);
578 }
579 
583 static void
584 sigchld_cancel (void *arg)
585  /*@globals rpmsigTbl, fileSystem, internalState @*/
586  /*@modifies rpmsigTbl, fileSystem, internalState @*/
587 {
588  pid_t child = *(pid_t *) arg;
589  pid_t result;
590 
591  (void) kill(child, SIGKILL);
592 
593  do {
594  result = waitpid(child, NULL, 0);
595  } while (result == (pid_t)-1 && errno == EINTR);
596 
597  (void) DO_LOCK ();
598  if (SUB_REF (rpmsigTbl_sigchld) == 0) {
599  (void) rpmsqEnable(-SIGQUIT, NULL);
600  (void) rpmsqEnable(-SIGINT, NULL);
601  }
602  (void) DO_UNLOCK ();
603 }
604 
608 int
609 rpmsqExecve (const char ** argv)
610  /*@globals rpmsigTbl @*/
611  /*@modifies rpmsigTbl @*/
612 {
613  int oldtype;
614  int status = -1;
615  pid_t pid = 0;
616  pid_t result;
617  sigset_t newMask, oldMask;
618  rpmsq sq = memset(alloca(sizeof(*sq)), 0, sizeof(*sq));
619 
620 #ifndef PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
621  INIT_LOCK ();
622 #endif
623 
624  (void) DO_LOCK ();
625  if (ADD_REF (rpmsigTbl_sigchld) == 0) {
626  if (rpmsqEnable(SIGINT, NULL) < 0) {
628  goto out;
629  }
630  if (rpmsqEnable(SIGQUIT, NULL) < 0) {
632  goto out_restore_sigint;
633  }
634  }
635  (void) DO_UNLOCK ();
636 
637  (void) sigemptyset (&newMask);
638  (void) sigaddset (&newMask, SIGCHLD);
639  if (sigprocmask (SIG_BLOCK, &newMask, &oldMask) < 0) {
640  (void) DO_LOCK ();
641  if (SUB_REF (rpmsigTbl_sigchld) == 0)
642  goto out_restore_sigquit_and_sigint;
643  goto out;
644  }
645 
646  CLEANUP_HANDLER(sigchld_cancel, &pid, &oldtype);
647 
648  pid = fork ();
649  if (pid < (pid_t) 0) { /* fork failed. */
650  goto out;
651  } else if (pid == (pid_t) 0) { /* Child. */
652 
653  /* Restore the signals. */
654  (void) sigaction (SIGINT, &rpmsigTbl_sigint->oact, NULL);
655  (void) sigaction (SIGQUIT, &rpmsigTbl_sigquit->oact, NULL);
656  (void) sigprocmask (SIG_SETMASK, &oldMask, NULL);
657 
658  /* Reset rpmsigTbl lock and refcnt. */
659  INIT_LOCK ();
660 
661  (void) execve (argv[0], (char *const *) argv, environ);
662  _exit (127);
663  } else { /* Parent. */
664  do {
665  result = waitpid(pid, &status, 0);
666  } while (result == (pid_t)-1 && errno == EINTR);
667  if (result != pid)
668  status = -1;
669  }
670 
671  CLEANUP_RESET(0, oldtype);
672 
673  (void) DO_LOCK ();
674  if ((SUB_REF (rpmsigTbl_sigchld) == 0 &&
675  (rpmsqEnable(-SIGINT, NULL) < 0 || rpmsqEnable (-SIGQUIT, NULL) < 0))
676  || sigprocmask (SIG_SETMASK, &oldMask, NULL) != 0)
677  {
678  status = -1;
679  }
680  goto out;
681 
682 out_restore_sigquit_and_sigint:
683  (void) rpmsqEnable(-SIGQUIT, NULL);
684 out_restore_sigint:
685  (void) rpmsqEnable(-SIGINT, NULL);
686 out:
687  (void) DO_UNLOCK ();
688  return status;
689 }