Changeset 1012


Ignore:
Timestamp:
Feb 22, 2017, 1:08:56 AM (8 years ago)
Author:
dmik
Message:

rpm: Partly revert r8 (fork->popen).

This is no longer necessary as fork crash was fixed in NSPR.
See #143 for more details.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • rpm/trunk/build/rpmfc.c

    r636 r1012  
    11#include "system.h"
    2 
    3 #ifdef __EMX__
    4 #include <process.h>
    5 #include <stdlib.h>
    6 #endif
    72
    83#include <errno.h>
     
    2116#include <rpm/rpmfi.h>
    2217#include <rpm/rpmstrpool.h>
     18
     19#ifdef __EMX__
     20#include <sys/socket.h>
     21/* Use socketpair instead of pipe because of select */
     22#define pipe(p) socketpair(AF_UNIX, SOCK_STREAM, 0, p)
     23#endif
    2324
    2425#include "lib/rpmfi_internal.h"         /* rpmfiles stuff for now */
     
    206207    int myerrno = 0;
    207208    int ret = 1; /* assume failure */
    208 #ifdef __EMX__
    209     int i, fd, nbw, nbr;
    210         FILE* in;
    211         char tmpfile[_MAX_PATH];
    212         char buffer[32*1024];
    213 #endif
    214 
    215 #ifndef __EMX__
     209
    216210    if (pipe(toProg) < 0 || pipe(fromProg) < 0) {
    217211        rpmlog(RPMLOG_ERR, _("Couldn't create pipe for %s: %m\n"), argv[0]);
     
    253247    close(fromProg[1]);
    254248
    255 #else
    256 
    257 #if 0
    258         if (dir && chdir(dir)) {
    259             rpmlog(RPMLOG_ERR, _("Couldn't chdir to %s: %s\n"),
    260                     dir, strerror(errno));
    261             _exit(EXIT_FAILURE);
    262         }
    263 #endif
    264 
    265         // write data to file
    266         strcpy( tmpfile, "check-files-XXXXXX");
    267         if (mktemp( tmpfile) == NULL) {
    268                 rpmlog(RPMLOG_ERR, _("Couldn't get temp file: %s\n"),
    269                         strerror(errno));
    270                 return NULL;
    271         }
    272         fd = open( tmpfile, O_CREAT|O_TRUNC|O_BINARY|O_WRONLY);
    273         if (fd == -1) {
    274                 unlink(tmpfile);
    275                 rpmlog(RPMLOG_ERR, _("Couldn't open temp file: %s\n"),
    276                         strerror(errno));
    277                 return NULL;
    278         }
    279         nbw = write( fd, writePtr,writeBytesLeft);
    280         if (nbw != writeBytesLeft) {
    281                 close(fd);
    282                 unlink(tmpfile);
    283                 rpmlog(RPMLOG_ERR, _("Couldn't write temp file: %s\n"),
    284                         strerror(errno));
    285                 return NULL;
    286         }
    287         close(fd);
    288        
    289         // create command line, popen does
    290         // not directly execute shell scripts :-(
    291         // TODO rewrite check-files.sh in rexx
    292         strcpy( buffer, "sh -c \"");
    293         strcat( buffer, argv[0]);
    294         // popen requires backslash!
    295         //for( i=0; i<strlen(buffer); i++)
    296         //      if (buffer[i] == '/')
    297         //              buffer[i] = '\\';
    298 
    299         i = 1;
    300         while( argv[i] != NULL) {
    301                 strcat( buffer, " ");
    302                 strcat( buffer, argv[i++]);
    303         }
    304         // add temp file
    305         strcat( buffer, " ");
    306         strcat( buffer, tmpfile);
    307         strcat( buffer, "\"");
    308         if (0)
    309             fprintf( stderr,"command line: '%s'\n", buffer);
    310 
    311         // execute child and read input pipe
    312         in = popen( buffer, "r");
    313         if (in == NULL) {
    314                 unlink(tmpfile);
    315                 rpmlog(RPMLOG_ERR, _("Couldn't popen: %s\n"),
    316                         strerror(errno));
    317                 return NULL;
    318         }
    319        
    320249        readBuff = newStringBuf();
    321 
    322         /* Read any data from prog */
    323         {   char buf[BUFSIZ+1];
    324             while (!feof(in)) {
    325                         nbr = fread(buf, 1, sizeof(buf)-1, in);
    326                         buf[nbr] = '\0';
    327                         if (0)
    328                             fprintf( stderr,"read '%s'\n",buf);
    329                         appendStringBuf(readBuff, buf);
    330             }
    331         }
    332         fclose(in);
    333 
    334         // delete temporary
    335         unlink(tmpfile);
    336 
    337 #endif // __EMX__
    338 
    339 #ifndef __EMX__
    340     readBuff = newStringBuf();
    341250
    342251    while (1) {
     
    421330        goto exit;
    422331    }
    423 #endif // __EMX__
    424332
    425333    ret = 0;
Note: See TracChangeset for help on using the changeset viewer.