X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=userv.git;a=blobdiff_plain;f=servexec.c;h=7b1bcc015be6ca93d8868857f769539b72d5d63f;hp=a71b64f1e78bac9663f3c4f26c54ab357709b657;hb=4923f5a1c9b32a801a66a4ac458b401207b7d7ac;hpb=9c66781b8a9dd60bb3e23f9813700897e3bf8200 diff --git a/servexec.c b/servexec.c index a71b64f..7b1bcc0 100644 --- a/servexec.c +++ b/servexec.c @@ -2,7 +2,7 @@ * userv - execserv.c * daemon code which executes actual service (ie child process) * - * Copyright (C)1996-1997,1999 Ian Jackson + * Copyright (C)1996-1997,1999-2001,2003 Ian Jackson * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by @@ -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; }