-/**
- * SIGCHLD cancellation handler.
- */
-static void
-sigchld_cancel (void *arg)
-{
- pid_t child = *(pid_t *) arg;
- pid_t result;
-
- (void) kill(child, SIGKILL);
-
- do {
- result = waitpid(child, NULL, 0);
- } while (result == (pid_t)-1 && errno == EINTR);
-
- DO_LOCK ();
- if (SUB_REF (rpmsigTbl_sigchld) == 0) {
- (void) rpmsqEnable(-SIGQUIT, NULL);
- (void) rpmsqEnable(-SIGINT, NULL);
- }
- DO_UNLOCK ();
-}
-
-/**
- * Execute a command, returning its status.
- */
-int
-rpmsqExecve (const char ** argv)
-{
- int oldtype;
- int status = -1;
- pid_t pid;
- pid_t result;
- sigset_t newMask, oldMask;
-
- DO_LOCK ();
- if (ADD_REF (rpmsigTbl_sigchld) == 0) {
- if (rpmsqEnable(SIGINT, NULL) < 0) {
- SUB_REF (rpmsigTbl_sigchld);
- goto out;
- }
- if (rpmsqEnable(SIGQUIT, NULL) < 0) {
- SUB_REF (rpmsigTbl_sigchld);
- goto out_restore_sigint;
- }
- }
- DO_UNLOCK ();
-
- sigemptyset (&newMask);
- sigaddset (&newMask, SIGCHLD);
- if (sigprocmask (SIG_BLOCK, &newMask, &oldMask) < 0) {
- DO_LOCK ();
- if (SUB_REF (rpmsigTbl_sigchld) == 0)
- goto out_restore_sigquit_and_sigint;
- goto out;
- }
-
- CLEANUP_HANDLER(sigchld_cancel, &pid, &oldtype);
-
- pid = fork ();
- if (pid < (pid_t) 0) { /* fork failed. */
- goto out;
- } else if (pid == (pid_t) 0) { /* Child. */
-
- /* Restore the signals. */
- (void) sigaction (SIGINT, &rpmsigTbl_sigint->oact, NULL);
- (void) sigaction (SIGQUIT, &rpmsigTbl_sigquit->oact, NULL);
- (void) sigprocmask (SIG_SETMASK, &oldMask, NULL);
-
- /* Reset rpmsigTbl lock and refcnt. */
- INIT_LOCK ();
-
- (void) execve (argv[0], (char *const *) argv, environ);
- _exit (127);
- } else { /* Parent. */
- do {
- result = waitpid(pid, &status, 0);
- } while (result == (pid_t)-1 && errno == EINTR);
- if (result != pid)
- status = -1;
- }
-
- CLEANUP_RESET(0, oldtype);
-
- DO_LOCK ();
- if ((SUB_REF (rpmsigTbl_sigchld) == 0 &&
- (rpmsqEnable(-SIGINT, NULL) < 0 || rpmsqEnable (-SIGQUIT, NULL) < 0))
- || sigprocmask (SIG_SETMASK, &oldMask, (sigset_t *) NULL) != 0)
- {
- status = -1;
- }
- goto out;
-
-out_restore_sigquit_and_sigint:
- (void) rpmsqEnable(-SIGQUIT, NULL);
-out_restore_sigint:
- (void) rpmsqEnable(-SIGINT, NULL);
-out:
- DO_UNLOCK ();
- return status;
-}