Main Page | Modules | Data Structures | File List | Data Fields | Globals | Related Pages

rpmio/rpmsq.c

Go to the documentation of this file.
00001 
00005 #include "system.h"
00006 
00007 #if defined(__LCLINT__)
00008 #define _BITS_SIGTHREAD_H       /* XXX avoid __sigset_t heartburn. */
00009 
00010 /*@-incondefs -protoparammatch@*/
00011 /*@-exportheader@*/
00012 /*@constant int SA_SIGINFO@*/
00013 extern int sighold(int sig)
00014         /*@globals errno, systemState @*/;
00015 extern int sigignore(int sig)
00016         /*@globals errno, systemState @*/;
00017 extern int sigpause(int sig)
00018         /*@globals errno, systemState @*/;
00019 extern int sigrelse(int sig)
00020         /*@globals errno, systemState @*/;
00021 extern void (*sigset(int sig, void (*disp)(int)))(int)
00022         /*@globals errno, systemState @*/;
00023 
00024 struct qelem;
00025 extern  void insque(struct qelem * __elem, struct qelem * __prev)
00026         /*@modifies  __elem, __prev @*/;
00027 extern  void remque(struct qelem * __elem)
00028         /*@modifies  __elem @*/;
00029 
00030 extern pthread_t pthread_self(void)
00031         /*@*/;
00032 extern int pthread_equal(pthread_t t1, pthread_t t2)
00033         /*@*/;
00034 
00035 extern int pthread_create(/*@out@*/ pthread_t *restrict thread,
00036                 const pthread_attr_t *restrict attr,
00037                 void *(*start_routine)(void*), void *restrict arg)
00038         /*@modifies *thread @*/;
00039 extern int pthread_join(pthread_t thread, /*@out@*/ void **value_ptr)
00040         /*@modifies *value_ptr @*/;
00041 
00042 extern int pthread_setcancelstate(int state, /*@out@*/ int *oldstate)
00043         /*@globals internalState @*/
00044         /*@modifies *oldstate, internalState @*/;
00045 extern int pthread_setcanceltype(int type, /*@out@*/ int *oldtype)
00046         /*@globals internalState @*/
00047         /*@modifies *oldtype, internalState @*/;
00048 extern void pthread_testcancel(void)
00049         /*@globals internalState @*/
00050         /*@modifies internalState @*/;
00051 extern void pthread_cleanup_pop(int execute)
00052         /*@globals internalState @*/
00053         /*@modifies internalState @*/;
00054 extern void pthread_cleanup_push(void (*routine)(void*), void *arg)
00055         /*@globals internalState @*/
00056         /*@modifies internalState @*/;
00057 extern void _pthread_cleanup_pop(/*@out@*/ struct _pthread_cleanup_buffer *__buffer, int execute)
00058         /*@globals internalState @*/
00059         /*@modifies internalState @*/;
00060 extern void _pthread_cleanup_push(/*@out@*/ struct _pthread_cleanup_buffer *__buffer, void (*routine)(void*), /*@out@*/ void *arg)
00061         /*@globals internalState @*/
00062         /*@modifies internalState @*/;
00063 
00064 extern int pthread_mutexattr_destroy(pthread_mutexattr_t *attr)
00065         /*@globals errno, internalState @*/
00066         /*@modifies *attr, errno, internalState @*/;
00067 extern int pthread_mutexattr_init(/*@out@*/ pthread_mutexattr_t *attr)
00068         /*@globals errno, internalState @*/
00069         /*@modifies *attr, errno, internalState @*/;
00070 
00071 int pthread_mutexattr_gettype(const pthread_mutexattr_t *restrict attr,
00072                 /*@out@*/ int *restrict type)
00073         /*@modifies *type @*/;
00074 int pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type)
00075         /*@globals errno, internalState @*/
00076         /*@modifies *attr, errno, internalState @*/;
00077 
00078 extern int pthread_mutex_destroy(pthread_mutex_t *mutex)
00079         /*@modifies *mutex @*/;
00080 extern int pthread_mutex_init(/*@out@*/ pthread_mutex_t *restrict mutex,
00081                 /*@null@*/ const pthread_mutexattr_t *restrict attr)
00082         /*@globals errno, internalState @*/
00083         /*@modifies *mutex, errno, internalState @*/;
00084 
00085 extern int pthread_mutex_lock(pthread_mutex_t *mutex)
00086         /*@globals errno @*/
00087         /*@modifies *mutex, errno @*/;
00088 extern int pthread_mutex_trylock(pthread_mutex_t *mutex)
00089         /*@globals errno @*/
00090         /*@modifies *mutex, errno @*/;
00091 extern int pthread_mutex_unlock(pthread_mutex_t *mutex)
00092         /*@globals errno @*/
00093         /*@modifies *mutex, errno @*/;
00094 
00095 extern int pthread_cond_destroy(pthread_cond_t *cond)
00096         /*@modifies *cond @*/;
00097 extern int pthread_cond_init(/*@out@*/ pthread_cond_t *restrict cond,
00098                 const pthread_condattr_t *restrict attr)
00099         /*@globals errno, internalState @*/
00100         /*@modifies *cond, errno, internalState @*/;
00101 
00102 extern int pthread_cond_timedwait(pthread_cond_t *restrict cond,
00103                 pthread_mutex_t *restrict mutex,
00104                 const struct timespec *restrict abstime)
00105         /*@modifies *cond, *mutex @*/;
00106 extern int pthread_cond_wait(pthread_cond_t *restrict cond,
00107                 pthread_mutex_t *restrict mutex)
00108         /*@modifies *cond, *mutex @*/;
00109 extern int pthread_cond_broadcast(pthread_cond_t *cond)
00110         /*@globals errno, internalState @*/
00111         /*@modifies *cond, errno, internalState @*/;
00112 extern int pthread_cond_signal(pthread_cond_t *cond)
00113         /*@globals errno, internalState @*/
00114         /*@modifies *cond, errno, internalState @*/;
00115 
00116 /*@=exportheader@*/
00117 /*@=incondefs =protoparammatch@*/
00118 #endif
00119 
00120 #include <signal.h>
00121 #include <sys/signal.h>
00122 #include <sys/wait.h>
00123 #include <search.h>
00124 
00125 #if defined(HAVE_PTHREAD_H)
00126 
00127 #include <pthread.h>
00128 
00129 /*@unchecked@*/
00130 /*@-type@*/
00131 static pthread_mutex_t rpmsigTbl_lock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
00132 /*@=type@*/
00133 
00134 #define DO_LOCK()       pthread_mutex_lock(&rpmsigTbl_lock);
00135 #define DO_UNLOCK()     pthread_mutex_unlock(&rpmsigTbl_lock);
00136 #define INIT_LOCK()     \
00137     {   pthread_mutexattr_t attr; \
00138         (void) pthread_mutexattr_init(&attr); \
00139         (void) pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); \
00140         (void) pthread_mutex_init (&rpmsigTbl_lock, &attr); \
00141         (void) pthread_mutexattr_destroy(&attr); \
00142         rpmsigTbl_sigchld->active = 0; \
00143     }
00144 #define ADD_REF(__tbl)  (__tbl)->active++
00145 #define SUB_REF(__tbl)  --(__tbl)->active
00146 #define CLEANUP_HANDLER(__handler, __arg, __oldtypeptr) \
00147     (void) pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, (__oldtypeptr));\
00148         pthread_cleanup_push((__handler), (__arg));
00149 #define CLEANUP_RESET(__execute, __oldtype) \
00150     (void) pthread_cleanup_pop(__execute); \
00151     (void) pthread_setcanceltype ((__oldtype), &(__oldtype));
00152 
00153 #define SAME_THREAD(_a, _b)     pthread_equal(((pthread_t)_a), ((pthread_t)_b))
00154 
00155 #define ME()    ((void *)pthread_self())
00156 
00157 #else
00158 
00159 #define DO_LOCK()
00160 #define DO_UNLOCK()
00161 #define INIT_LOCK()
00162 #define ADD_REF(__tbl)  /*@-noeffect@*/ (0) /*@=noeffect@*/
00163 #define SUB_REF(__tbl)  /*@-noeffect@*/ (0) /*@=noeffect@*/
00164 #define CLEANUP_HANDLER(__handler, __arg, __oldtypeptr)
00165 #define CLEANUP_RESET(__execute, __oldtype)
00166 
00167 #define SAME_THREAD(_a, _b)     (42)
00168 
00169 #define ME()    (((void *)getpid()))
00170 
00171 #endif  /* HAVE_PTHREAD_H */
00172 
00173 #include <rpmsq.h>
00174 
00175 #include "debug.h"
00176 
00177 #define _RPMSQ_DEBUG    0
00178 /*@unchecked@*/
00179 int _rpmsq_debug = _RPMSQ_DEBUG;
00180 
00181 /*@unchecked@*/
00182 static struct rpmsqElem rpmsqRock;
00183 
00184 /*@-compmempass@*/
00185 /*@unchecked@*/
00186 rpmsq rpmsqQueue = &rpmsqRock;
00187 /*@=compmempass@*/
00188 
00189 int rpmsqInsert(void * elem, void * prev)
00190 {
00191     rpmsq sq = (rpmsq) elem;
00192     int ret = -1;
00193 
00194     if (sq != NULL) {
00195 #ifdef _RPMSQ_DEBUG
00196 if (_rpmsq_debug)
00197 fprintf(stderr, "    Insert(%p): %p\n", ME(), sq);
00198 #endif
00199         ret = sighold(SIGCHLD);
00200         if (ret == 0) {
00201             sq->child = 0;
00202             sq->reaped = 0;
00203             sq->status = 0;
00204             sq->reaper = 1;
00205 /*@-bounds@*/
00206             sq->pipes[0] = sq->pipes[1] = -1;
00207 /*@=bounds@*/
00208 
00209             sq->id = ME();
00210             ret = pthread_mutex_init(&sq->mutex, NULL);
00211             ret = pthread_cond_init(&sq->cond, NULL);
00212             insque(elem, (prev != NULL ? prev : rpmsqQueue));
00213             ret = sigrelse(SIGCHLD);
00214         }
00215     }
00216     return ret;
00217 }
00218 
00219 int rpmsqRemove(void * elem)
00220 {
00221     rpmsq sq = (rpmsq) elem;
00222     int ret = -1;
00223 
00224     if (elem != NULL) {
00225 
00226 #ifdef _RPMSQ_DEBUG
00227 if (_rpmsq_debug)
00228 fprintf(stderr, "    Remove(%p): %p\n", ME(), sq);
00229 #endif
00230         ret = sighold (SIGCHLD);
00231         if (ret == 0) {
00232             remque(elem);
00233             ret = pthread_cond_destroy(&sq->cond);
00234             ret = pthread_mutex_destroy(&sq->mutex);
00235             sq->id = NULL;
00236 /*@-bounds@*/
00237             if (sq->pipes[1])   ret = close(sq->pipes[1]);
00238             if (sq->pipes[0])   ret = close(sq->pipes[0]);
00239             sq->pipes[0] = sq->pipes[1] = -1;
00240 /*@=bounds@*/
00241 #ifdef  NOTYET  /* rpmpsmWait debugging message needs */
00242             sq->reaper = 1;
00243             sq->status = 0;
00244             sq->reaped = 0;
00245             sq->child = 0;
00246 #endif
00247             ret = sigrelse(SIGCHLD);
00248         }
00249     }
00250     return ret;
00251 }
00252 
00253 /*@unchecked@*/
00254 sigset_t rpmsqCaught;
00255 
00256 /*@unchecked@*/
00257 /*@-fullinitblock@*/
00258 static struct rpmsig_s {
00259     int signum;
00260     void (*handler) (int signum, void * info, void * context);
00261     int active;
00262     struct sigaction oact;
00263 } rpmsigTbl[] = {
00264     { SIGINT,   rpmsqAction },
00265 #define rpmsigTbl_sigint        (&rpmsigTbl[0])
00266     { SIGQUIT,  rpmsqAction },
00267 #define rpmsigTbl_sigquit       (&rpmsigTbl[1])
00268     { SIGCHLD,  rpmsqAction },
00269 #define rpmsigTbl_sigchld       (&rpmsigTbl[2])
00270     { SIGHUP,   rpmsqAction },
00271 #define rpmsigTbl_sighup        (&rpmsigTbl[3])
00272     { SIGTERM,  rpmsqAction },
00273 #define rpmsigTbl_sigterm       (&rpmsigTbl[4])
00274     { SIGPIPE,  rpmsqAction },
00275 #define rpmsigTbl_sigpipe       (&rpmsigTbl[5])
00276     { -1,       NULL },
00277 };
00278 /*@=fullinitblock@*/
00279 
00280 void rpmsqAction(int signum,
00281                 /*@unused@*/ void * info, /*@unused@*/ void * context)
00282 {
00283     int save = errno;
00284     rpmsig tbl;
00285 
00286     for (tbl = rpmsigTbl; tbl->signum >= 0; tbl++) {
00287         if (tbl->signum != signum)
00288             continue;
00289 
00290         (void) sigaddset(&rpmsqCaught, signum);
00291 
00292         switch (signum) {
00293         case SIGCHLD:
00294             while (1) {
00295                 rpmsq sq;
00296                 int status = 0;
00297                 pid_t reaped = waitpid(0, &status, WNOHANG);
00298 
00299                 /* XXX errno set to ECHILD/EINVAL/EINTR. */
00300                 if (reaped <= 0)
00301                     /*@innerbreak@*/ break;
00302 
00303                 /* XXX insque(3)/remque(3) are dequeue, not ring. */
00304                 for (sq = rpmsqQueue->q_forw;
00305                      sq != NULL && sq != rpmsqQueue;
00306                      sq = sq->q_forw)
00307                 {
00308                     if (sq->child != reaped)
00309                         /*@innercontinue@*/ continue;
00310                     sq->reaped = reaped;
00311                     sq->status = status;
00312                     (void) pthread_cond_signal(&sq->cond);
00313                     /*@innerbreak@*/ break;
00314                 }
00315             }
00316             /*@switchbreak@*/ break;
00317         default:
00318             /*@switchbreak@*/ break;
00319         }
00320         break;
00321     }
00322     errno = save;
00323 }
00324 
00325 int rpmsqEnable(int signum, /*@null@*/ rpmsqAction_t handler)
00326         /*@globals rpmsigTbl @*/
00327         /*@modifies rpmsigTbl @*/
00328 {
00329     int tblsignum = (signum >= 0 ? signum : -signum);
00330     struct sigaction sa;
00331     rpmsig tbl;
00332     int ret = -1;
00333 
00334     (void) DO_LOCK ();
00335     if (rpmsqQueue->id == NULL)
00336         rpmsqQueue->id = ME();
00337     for (tbl = rpmsigTbl; tbl->signum >= 0; tbl++) {
00338         if (tblsignum != tbl->signum)
00339             continue;
00340 
00341         if (signum >= 0) {                      /* Enable. */
00342             if (ADD_REF(tbl) <= 0) {
00343                 (void) sigdelset(&rpmsqCaught, tbl->signum);
00344                 (void) sigemptyset (&sa.sa_mask);
00345 /*@-compdef -type @*/
00346                 sa.sa_flags = SA_SIGINFO;
00347                 sa.sa_sigaction = (handler != NULL ? handler : tbl->handler);
00348                 if (sigaction(tbl->signum, &sa, &tbl->oact) < 0) {
00349                     SUB_REF(tbl);
00350                     break;
00351                 }
00352 /*@=compdef =type @*/
00353                 tbl->active = 1;                /* XXX just in case */
00354                 if (handler != NULL)
00355                     tbl->handler = handler;
00356             }
00357         } else {                                /* Disable. */
00358             if (SUB_REF(tbl) <= 0) {
00359                 if (sigaction(tbl->signum, &tbl->oact, NULL) < 0)
00360                     break;
00361                 tbl->active = 0;                /* XXX just in case */
00362                 tbl->handler = (handler != NULL ? handler : rpmsqAction);
00363             }
00364         }
00365         ret = tbl->active;
00366         break;
00367     }
00368     (void) DO_UNLOCK ();
00369     return ret;
00370 }
00371 
00372 pid_t rpmsqFork(rpmsq sq)
00373 {
00374     pid_t pid;
00375     int xx;
00376 
00377     if (sq->reaper) {
00378         xx = rpmsqInsert(sq, NULL);
00379 #ifdef _RPMSQ_DEBUG
00380 if (_rpmsq_debug)
00381 fprintf(stderr, "    Enable(%p): %p\n", ME(), sq);
00382 #endif
00383         xx = rpmsqEnable(SIGCHLD, NULL);
00384     }
00385 
00386     xx = pipe(sq->pipes);
00387 
00388     xx = sighold(SIGCHLD);
00389 
00390     pid = fork();
00391     if (pid < (pid_t) 0) {              /* fork failed.  */
00392 /*@-bounds@*/
00393         xx = close(sq->pipes[0]);
00394         xx = close(sq->pipes[1]);
00395         sq->pipes[0] = sq->pipes[1] = -1;
00396 /*@=bounds@*/
00397         goto out;
00398     } else if (pid == (pid_t) 0) {      /* Child. */
00399         int yy;
00400 
00401         /* Block to permit parent time to wait. */
00402 /*@-bounds@*/
00403         xx = close(sq->pipes[1]);
00404         xx = read(sq->pipes[0], &yy, sizeof(yy));
00405         xx = close(sq->pipes[0]);
00406         sq->pipes[0] = sq->pipes[1] = -1;
00407 /*@=bounds@*/
00408 
00409 #ifdef _RPMSQ_DEBUG
00410 if (_rpmsq_debug)
00411 fprintf(stderr, "     Child(%p): %p child %d\n", ME(), sq, getpid());
00412 #endif
00413 
00414     } else {                            /* Parent. */
00415 
00416         sq->child = pid;
00417 
00418 #ifdef _RPMSQ_DEBUG
00419 if (_rpmsq_debug)
00420 fprintf(stderr, "    Parent(%p): %p child %d\n", ME(), sq, sq->child);
00421 #endif
00422 
00423     }
00424 
00425 out:
00426     xx = sigrelse(SIGCHLD);
00427     return sq->child;
00428 }
00429 
00436 static int rpmsqWaitUnregister(rpmsq sq)
00437         /*@globals fileSystem, internalState @*/
00438         /*@modifies sq, fileSystem, internalState @*/
00439 {
00440     int nothreads = 0;
00441     int ret = 0;
00442     int xx;
00443 
00444     /* Protect sq->reaped from handler changes. */
00445     ret = sighold(SIGCHLD);
00446 
00447     /* Initialize the cond var mutex. */
00448     if (!nothreads)
00449         ret = pthread_mutex_lock(&sq->mutex);
00450 
00451     /* Start the child, linux often runs child before parent. */
00452 /*@-bounds@*/
00453     if (sq->pipes[0] >= 0)
00454         xx = close(sq->pipes[0]);
00455     if (sq->pipes[1] >= 0)
00456         xx = close(sq->pipes[1]);
00457     sq->pipes[0] = sq->pipes[1] = -1;
00458 /*@=bounds@*/
00459 
00460     /* Put a stopwatch on the time spent waiting to measure performance gain. */
00461     (void) rpmswEnter(&sq->op, -1);
00462 
00463     /* Wait for handler to receive SIGCHLD. */
00464     /*@-infloops@*/
00465     while (ret == 0 && sq->reaped != sq->child) {
00466         if (nothreads)
00467             /* Note that sigpause re-enables SIGCHLD. */
00468             ret = sigpause(SIGCHLD);
00469         else {
00470             xx = sigrelse(SIGCHLD);
00471             ret = pthread_cond_wait(&sq->cond, &sq->mutex);
00472             xx = sighold(SIGCHLD);
00473         }
00474     }
00475     /*@=infloops@*/
00476 
00477     /* Accumulate stopwatch time spent waiting, potential performance gain. */
00478     sq->ms_scriptlets += rpmswExit(&sq->op, -1)/1000;
00479 
00480     /* Tear down cond var mutex, our child has been reaped. */
00481     if (!nothreads)
00482         xx = pthread_mutex_unlock(&sq->mutex);
00483     xx = sigrelse(SIGCHLD);
00484 
00485 #ifdef _RPMSQ_DEBUG
00486 if (_rpmsq_debug)
00487 fprintf(stderr, "      Wake(%p): %p child %d reaper %d ret %d\n", ME(), sq, sq->child, sq->reaper, ret);
00488 #endif
00489 
00490     /* Remove processed SIGCHLD item from queue. */
00491     xx = rpmsqRemove(sq);
00492 
00493     /* Disable SIGCHLD handler on refcount == 0. */
00494     xx = rpmsqEnable(-SIGCHLD, NULL);
00495 #ifdef _RPMSQ_DEBUG
00496 if (_rpmsq_debug)
00497 fprintf(stderr, "   Disable(%p): %p\n", ME(), sq);
00498 #endif
00499 
00500     return ret;
00501 }
00502 
00503 pid_t rpmsqWait(rpmsq sq)
00504 {
00505 
00506 #ifdef _RPMSQ_DEBUG
00507 if (_rpmsq_debug)
00508 fprintf(stderr, "      Wait(%p): %p child %d reaper %d\n", ME(), sq, sq->child, sq->reaper);
00509 #endif
00510 
00511     if (sq->reaper) {
00512         (void) rpmsqWaitUnregister(sq);
00513     } else {
00514         pid_t reaped;
00515         int status;
00516         do {
00517             reaped = waitpid(sq->child, &status, 0);
00518         } while (reaped >= 0 && reaped != sq->child);
00519         sq->reaped = reaped;
00520         sq->status = status;
00521 #ifdef _RPMSQ_DEBUG
00522 if (_rpmsq_debug)
00523 fprintf(stderr, "   Waitpid(%p): %p child %d reaped %d\n", ME(), sq, sq->child, sq->reaped);
00524 #endif
00525     }
00526 
00527 #ifdef _RPMSQ_DEBUG
00528 if (_rpmsq_debug)
00529 fprintf(stderr, "      Fini(%p): %p child %d status 0x%x\n", ME(), sq, sq->child, sq->status);
00530 #endif
00531 
00532     return sq->reaped;
00533 }
00534 
00535 void * rpmsqThread(void * (*start) (void * arg), void * arg)
00536 {
00537     pthread_t pth;
00538     int ret;
00539 
00540     ret = pthread_create(&pth, NULL, start, arg);
00541     return (ret == 0 ? (void *)pth : NULL);
00542 }
00543 
00544 int rpmsqJoin(void * thread)
00545 {
00546     pthread_t pth = (pthread_t) thread;
00547     if (thread == NULL)
00548         return EINVAL;
00549     return pthread_join(pth, NULL);
00550 }
00551 
00552 int rpmsqThreadEqual(void * thread)
00553 {
00554     pthread_t t1 = (pthread_t) thread;
00555     pthread_t t2 = pthread_self();
00556     return pthread_equal(t1, t2);
00557 }
00558 
00562 static void
00563 sigchld_cancel (void *arg)
00564         /*@globals rpmsigTbl, fileSystem, internalState @*/
00565         /*@modifies rpmsigTbl, fileSystem, internalState @*/
00566 {
00567     pid_t child = *(pid_t *) arg;
00568     pid_t result;
00569 
00570     (void) kill(child, SIGKILL);
00571 
00572     do {
00573         result = waitpid(child, NULL, 0);
00574     } while (result == (pid_t)-1 && errno == EINTR);
00575 
00576     (void) DO_LOCK ();
00577     if (SUB_REF (rpmsigTbl_sigchld) == 0) {
00578         (void) rpmsqEnable(-SIGQUIT, NULL);
00579         (void) rpmsqEnable(-SIGINT, NULL);
00580     }
00581     (void) DO_UNLOCK ();
00582 }
00583 
00587 int
00588 rpmsqExecve (const char ** argv)
00589         /*@globals rpmsigTbl @*/
00590         /*@modifies rpmsigTbl @*/
00591 {
00592     int oldtype;
00593     int status = -1;
00594     pid_t pid = 0;
00595     pid_t result;
00596     sigset_t newMask, oldMask;
00597     rpmsq sq = memset(alloca(sizeof(*sq)), 0, sizeof(*sq));
00598 
00599     (void) DO_LOCK ();
00600     if (ADD_REF (rpmsigTbl_sigchld) == 0) {
00601         if (rpmsqEnable(SIGINT, NULL) < 0) {
00602             SUB_REF (rpmsigTbl_sigchld);
00603             goto out;
00604         }
00605         if (rpmsqEnable(SIGQUIT, NULL) < 0) {
00606             SUB_REF (rpmsigTbl_sigchld);
00607             goto out_restore_sigint;
00608         }
00609     }
00610     (void) DO_UNLOCK ();
00611 
00612     (void) sigemptyset (&newMask);
00613     (void) sigaddset (&newMask, SIGCHLD);
00614     if (sigprocmask (SIG_BLOCK, &newMask, &oldMask) < 0) {
00615         (void) DO_LOCK ();
00616         if (SUB_REF (rpmsigTbl_sigchld) == 0)
00617             goto out_restore_sigquit_and_sigint;
00618         goto out;
00619     }
00620 
00621     CLEANUP_HANDLER(sigchld_cancel, &pid, &oldtype);
00622 
00623     pid = fork ();
00624     if (pid < (pid_t) 0) {              /* fork failed.  */
00625         goto out;
00626     } else if (pid == (pid_t) 0) {      /* Child. */
00627 
00628         /* Restore the signals.  */
00629         (void) sigaction (SIGINT, &rpmsigTbl_sigint->oact, NULL);
00630         (void) sigaction (SIGQUIT, &rpmsigTbl_sigquit->oact, NULL);
00631         (void) sigprocmask (SIG_SETMASK, &oldMask, NULL);
00632 
00633         /* Reset rpmsigTbl lock and refcnt. */
00634         INIT_LOCK ();
00635 
00636 #if defined(__GLIBC__)
00637 
00641         {
00642            char* bypassVar = (char*) malloc(1024*sizeof(char));
00643            if (bypassVar != NULL)
00644            {
00645               snprintf(bypassVar,1024*sizeof(char), "__PASSTHROUGH_LD_ASSUME_KERNEL_%d", getppid());
00646               bypassVar[1023] = '\0';
00647               if (getenv(bypassVar) != NULL)
00648               {
00649                  char* bypassVal = (char*) malloc(1024*sizeof(char));
00650                  if (bypassVal != NULL)
00651                  {
00652                     snprintf(bypassVal, 1024*sizeof(char), "%s", getenv(bypassVar));
00653                     unsetenv(bypassVar);
00654                     snprintf(bypassVar, 1024*sizeof(char), "LD_ASSUME_KERNEL=%s", bypassVal);
00655                     bypassVar[1023] = '\0';
00656                     putenv(bypassVar);
00657                     free(bypassVal);
00658                  }
00659                  else
00660                  {
00661                     free(bypassVar);
00662                  }
00663               }
00664            }
00665         }
00666 #endif
00667 
00668         (void) execve (argv[0], (char *const *) argv, environ);
00669         _exit (127);
00670     } else {                            /* Parent. */
00671         do {
00672             result = waitpid(pid, &status, 0);
00673         } while (result == (pid_t)-1 && errno == EINTR);
00674         if (result != pid)
00675             status = -1;
00676     }
00677 
00678     CLEANUP_RESET(0, oldtype);
00679 
00680     (void) DO_LOCK ();
00681     if ((SUB_REF (rpmsigTbl_sigchld) == 0 &&
00682         (rpmsqEnable(-SIGINT, NULL) < 0 || rpmsqEnable (-SIGQUIT, NULL) < 0))
00683       || sigprocmask (SIG_SETMASK, &oldMask, NULL) != 0)
00684     {
00685         status = -1;
00686     }
00687     goto out;
00688 
00689 out_restore_sigquit_and_sigint:
00690     (void) rpmsqEnable(-SIGQUIT, NULL);
00691 out_restore_sigint:
00692     (void) rpmsqEnable(-SIGINT, NULL);
00693 out:
00694     (void) DO_UNLOCK ();
00695     return status;
00696 }

Generated on Thu May 19 18:31:19 2005 for rpm by doxygen 1.3.5