Changeset 634


Ignore:
Timestamp:
Jan 5, 2016, 10:56:07 PM (10 years ago)
Author:
Yuri Dario
Message:

rpm: replace fork() with popen() when redirecting output. fixes ticket#143.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • rpm/trunk/cliutils.c

    r595 r634  
    1515
    1616static pid_t pipeChild = 0;
     17#ifdef __KLIBC__
     18static FILE* pipeFD = NULL;
     19#endif
    1720
    1821RPM_GNUC_NORETURN
     
    5053    int p[2];
    5154
     55#ifdef __KLIBC__
     56
     57    char cmdline[16*1024];
     58    sprintf( cmdline, "sh -c %s", rpmcliPipeOutput);
     59    // start child and redirect its input to us
     60    pipeFD = popen( cmdline, "w");
     61    // now redirect stdout to input handle
     62    dup2( fileno(pipeFD), STDOUT_FILENO);
     63
     64#else
     65
    5266    if (pipe(p) < 0) {
    5367        fprintf(stderr, _("creating a pipe for --pipe failed: %m\n"));
     
    6882    (void) dup2(p[1], STDOUT_FILENO);
    6983    (void) close(p[1]);
     84#endif
     85
    7086    return 0;
    7187}
     
    7490{
    7591    int rc = 0;
     92
     93#ifdef __KLIBC__
     94
     95    // close stdout to allow child to end
     96    (void) fclose(stdout);
     97    // wait child end and query exit code
     98    int status = pclose(pipeFD);
     99    pipeFD = NULL;
     100    if (!WIFEXITED(status) || WEXITSTATUS(status))
     101        rc = 1;
     102
     103#else
    76104    if (pipeChild) {
    77105        int status;
     
    86114            rc = 1;
    87115    }
     116#endif
     117
    88118    return rc;
    89119}
Note: See TracChangeset for help on using the changeset viewer.