diff options
author | Nicolas Planel <nplanel@mandriva.com> | 2003-10-29 16:07:11 +0000 |
---|---|---|
committer | Nicolas Planel <nplanel@mandriva.com> | 2003-10-29 16:07:11 +0000 |
commit | de47eb59bb829423b1d0f47ba13099073999b3cb (patch) | |
tree | 827f35c4666e15ec66edae7c1fa05d963324602b /mdk-stage1/dietlibc/libugly/popen.c | |
parent | 1fece42e9c460ca017fc4facad380f05163d8977 (diff) | |
download | drakx-backup-do-not-use-de47eb59bb829423b1d0f47ba13099073999b3cb.tar drakx-backup-do-not-use-de47eb59bb829423b1d0f47ba13099073999b3cb.tar.gz drakx-backup-do-not-use-de47eb59bb829423b1d0f47ba13099073999b3cb.tar.bz2 drakx-backup-do-not-use-de47eb59bb829423b1d0f47ba13099073999b3cb.tar.xz drakx-backup-do-not-use-de47eb59bb829423b1d0f47ba13099073999b3cb.zip |
Corporate Server 2.1.1 releasetopic/Corpo_2_1
Diffstat (limited to 'mdk-stage1/dietlibc/libugly/popen.c')
-rw-r--r-- | mdk-stage1/dietlibc/libugly/popen.c | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/mdk-stage1/dietlibc/libugly/popen.c b/mdk-stage1/dietlibc/libugly/popen.c index e0e441495..aa9a2cde0 100644 --- a/mdk-stage1/dietlibc/libugly/popen.c +++ b/mdk-stage1/dietlibc/libugly/popen.c @@ -1,32 +1,38 @@ #include "dietstdio.h" #include <unistd.h> +#include <fcntl.h> +#include "binshstr.h" extern char **environ; FILE *popen(const char *command, const char *type) { int pfd[2]; int fd0; + FILE* f; pid_t pid; + if (pipe(pfd)<0) return 0; fd0=(*type=='r'); - if ((pid=vfork())<0) { + if (!(f=fdopen(pfd[!fd0],type))) { + close(pfd[0]); /* malloc failed */ + close(pfd[1]); + return 0; + } + if ((pid=fork())<0) { close(pfd[0]); close(pfd[1]); return 0; } if (!pid) { /* child */ - char *argv[]={"sh","-c",0,0}; + const char *argv[]={__sh,"-c",0,0}; close(pfd[!fd0]); close(fd0); dup2(pfd[fd0],fd0); close(pfd[fd0]); - argv[2]=(char*)command; - execve("/bin/sh",argv,environ); - _exit(255); + argv[2]=command; + execve(__binsh,(char*const*)argv,environ); + _exit(127); } close(pfd[fd0]); - { - register FILE* f; - if ((f=fdopen(pfd[!fd0],type))) - f->popen_kludge=pid; - return f; - } + fcntl (pfd[!fd0], F_SETFD, FD_CLOEXEC); + f->popen_kludge=pid; + return f; } |