patch-rpmio_rpmsq_c 3.7 KB

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