* userv - client.c
* client code
*
- * 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
if (alarm(timeout)<0) syscallerror("set up timeout alarm");
}
+
+static void close_unwanted_pipes(void) {
+ int fd;
+
+ for (fd=0; fd<fdsetupsize; fd++) {
+ if (!fdsetup[fd].filename) continue;
+ if (close(fdsetup[fd].pipefd)) fsyscallerror("close pipe fd for %d",fd);
+ if (fdsetup[fd].copyfd>2)
+ if (close(fdsetup[fd].copyfd))
+ if (errno != EBADF)
+ /* EBADF can be induced if cmd line specifies same fd twice */
+ fsyscallerror("close real fd for %d",fd);
+ }
+}
+
static void catdup(const char *which, int from, int to) {
if (dup2(from,to)<0) {
blocksignals(SIG_BLOCK);
reading= fdsetup[fd].mods & fdm_read;
catdup(catnamebuf, fdsetup[fd].copyfd, reading ? 0 : 1);
catdup(catnamebuf, fdsetup[fd].pipefd, reading ? 1 : 0);
+ close_unwanted_pipes();
execl("/bin/cat",catnamebuf,(char*)0);
fprintf(stderr,"userv: %s: cannot exec `cat': %s\n",catnamebuf,strerror(errno));
exit(-1);
}
- if (fdsetup[fd].copyfd>2)
- if (close(fdsetup[fd].copyfd)) fsyscallerror("close real fd for %d",fd);
- if (close(fdsetup[fd].pipefd)) fsyscallerror("close pipe fd for %d",fd);
}
+ close_unwanted_pipes();
}
static void server_sendconfirm(void) {