Changeset 319


Ignore:
Timestamp:
Mar 15, 2011, 8:57:49 PM (14 years ago)
Author:
katerina
Message:

Fix for ticket #239: Mutex in child after fork()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/sh_entropy.c

    r252 r319  
    520520  char   arg1[80];
    521521
     522#if defined(HAVE_PTHREAD) && defined (_POSIX_THREAD_SAFE_FUNCTIONS) && defined(HAVE_GETPWNAM_R)
     523  struct passwd    pwd;
     524  char           * buffer;
     525  struct passwd *  tempres;
     526#else
     527  struct passwd * tempres;
     528#endif
     529
    522530  SL_ENTER(_("sh_popen"));
     531
     532#if defined(HAVE_PTHREAD) && defined (_POSIX_THREAD_SAFE_FUNCTIONS) && defined(HAVE_GETPWNAM_R)
     533  buffer = SH_ALLOC(SH_PWBUF_SIZE);
     534  sh_getpwnam_r(DEFAULT_IDENT, &pwd, buffer, SH_PWBUF_SIZE, &tempres);
     535#else
     536  tempres = sh_getpwnam(DEFAULT_IDENT);
     537#endif
    523538
    524539  strncpy (arg0, _("/bin/sh"), sizeof(arg0));
     
    596611      if (0 == geteuid())
    597612        {
    598 #if defined(HAVE_PTHREAD) && defined (_POSIX_THREAD_SAFE_FUNCTIONS) && defined(HAVE_GETPWNAM_R)
    599           struct passwd    pwd;
    600           char           * buffer = SH_ALLOC(SH_PWBUF_SIZE);
    601           struct passwd *  tempres;
    602           sh_getpwnam_r(DEFAULT_IDENT, &pwd, buffer, SH_PWBUF_SIZE, &tempres);
    603 #else
    604           struct passwd * tempres = sh_getpwnam(DEFAULT_IDENT);
    605 #endif
    606613 
    607614          if (NULL != tempres) {
     
    619626            i = -1;
    620627          }
    621 #if defined(HAVE_PTHREAD) && defined (_POSIX_THREAD_SAFE_FUNCTIONS) && defined(HAVE_GETPWNAM_R)
    622           SH_FREE(buffer);
    623 #endif
    624628        }
    625629     
     
    644648    }
    645649
    646     /* parent
    647      */
    648     if (envp[0] != NULL)
    649       free(envp[0]);
    650 
    651     sl_close_fd (FIL__, __LINE__, pipedes[STDOUT_FILENO]);
    652     retry_fcntl (FIL__, __LINE__, pipedes[STDIN_FILENO], F_SETFD, FD_CLOEXEC);
    653 
    654     outf = fdopen (pipedes[STDIN_FILENO], "r");
    655 
    656     if (outf == NULL)
    657       {
    658         aud_kill (FIL__, __LINE__, source->pid, SIGKILL);
    659         sl_close_fd (FIL__, __LINE__, pipedes[STDOUT_FILENO]);
    660         waitpid (source->pid, NULL, 0);
    661         source->pid = 0;
    662         SL_RETURN(NULL, _("sh_popen"));
    663       }
    664 
    665     SL_RETURN(outf, _("sh_popen"));
     650  /* parent
     651   */
     652#if defined(HAVE_PTHREAD) && defined (_POSIX_THREAD_SAFE_FUNCTIONS) && defined(HAVE_GETPWNAM_R)
     653  SH_FREE(buffer);
     654#endif
     655
     656  if (envp[0] != NULL)
     657    free(envp[0]);
     658 
     659  sl_close_fd (FIL__, __LINE__, pipedes[STDOUT_FILENO]);
     660  retry_fcntl (FIL__, __LINE__, pipedes[STDIN_FILENO], F_SETFD, FD_CLOEXEC);
     661 
     662  outf = fdopen (pipedes[STDIN_FILENO], "r");
     663 
     664  if (outf == NULL)
     665    {
     666      aud_kill (FIL__, __LINE__, source->pid, SIGKILL);
     667      sl_close_fd (FIL__, __LINE__, pipedes[STDOUT_FILENO]);
     668      waitpid (source->pid, NULL, 0);
     669      source->pid = 0;
     670      SL_RETURN(NULL, _("sh_popen"));
     671    }
     672 
     673  SL_RETURN(outf, _("sh_popen"));
    666674}
    667675
Note: See TracChangeset for help on using the changeset viewer.