X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=userv.git;a=blobdiff_plain;f=servexec.c;h=aa35fc7550272dcc9286160673791a829909b64f;hp=a71b64f1e78bac9663f3c4f26c54ab357709b657;hb=0153e75a57925ff29262d98ba94da3ad5137bd0c;hpb=9c66781b8a9dd60bb3e23f9813700897e3bf8200 diff --git a/servexec.c b/servexec.c index a71b64f..aa35fc7 100644 --- a/servexec.c +++ b/servexec.c @@ -224,7 +224,7 @@ void execservice(const int synchsocket[], int clientfd) { "-", 0 }; - int fd, realfd, holdfd, newfd, r, envvarbufsize=0, targ, nargs, i, l; + int fd, realfd, holdfd, newfd, r, envvarbufsize=0, targ, nargs, i, l, fdflags; char *envvarbuf=0; const char **args, *const *cpp; char *const *pp; @@ -250,7 +250,16 @@ void execservice(const int synchsocket[], int clientfd) { if (close(clientfd)) serv_syscallfail("close client socket fd"); - /* Now we have to make all the fd's work. It's rather a complicated + /* First we need to close the holding writing ends of the pipes + * inherited from our parent: */ + for (fd=0; fd= 0) fdarray[fdarray[fd].realfd].holdfd= fd; @@ -286,7 +290,8 @@ void execservice(const int synchsocket[], int clientfd) { } if (dup2(fdarray[fd].realfd,fd)<0) serv_syscallfail("dup2 set up fd"); if (close(fdarray[fd].realfd)) serv_syscallfail("close old fd"); - if (fcntl(fd,F_SETFD,0)<0) serv_syscallfail("set no-close-on-exec on fd"); + fdflags= fcntl(fd,F_GETFD); if (fdflags<0) serv_syscallfail("get fd flags"); + if (fcntl(fd,F_SETFD,fdflags&~FD_CLOEXEC)==-1) serv_syscallfail("set no-close-on-exec on fd"); fdarray[fd].realfd= fd; }