summaryrefslogtreecommitdiffstats
path: root/usr.sbin/pkg_install/lib
diff options
context:
space:
mode:
authordes <des@FreeBSD.org>2000-10-29 15:39:51 +0000
committerdes <des@FreeBSD.org>2000-10-29 15:39:51 +0000
commitfdc38d445ee2556fe89b3cd95927d79e50816b92 (patch)
tree13818c67670091b656b7480a0674c7de9e5be612 /usr.sbin/pkg_install/lib
parentf82e4ca62c2bea6ce2d8c4f72263cb29a85f00b3 (diff)
downloadFreeBSD-src-fdc38d445ee2556fe89b3cd95927d79e50816b92.zip
FreeBSD-src-fdc38d445ee2556fe89b3cd95927d79e50816b92.tar.gz
Insetad of using fileno(ftp) as stdin for tar, use a pipe and have the
parent pass the data received from the server to the child.
Diffstat (limited to 'usr.sbin/pkg_install/lib')
-rw-r--r--usr.sbin/pkg_install/lib/file.c56
1 files changed, 39 insertions, 17 deletions
diff --git a/usr.sbin/pkg_install/lib/file.c b/usr.sbin/pkg_install/lib/file.c
index eebe4d2..4c4e9c2 100644
--- a/usr.sbin/pkg_install/lib/file.c
+++ b/usr.sbin/pkg_install/lib/file.c
@@ -146,10 +146,13 @@ fileGetURL(char *base, char *spec)
char pword[HOSTNAME_MAX + 40], *uname, *cp, *rp;
char fname[FILENAME_MAX];
char pen[FILENAME_MAX];
+ char buf[8192];
struct passwd *pw;
FILE *ftp;
pid_t tpid;
+ int pfd[2], pstat;
int i, status;
+ size_t r, w;
char *hint;
rp = NULL;
@@ -197,25 +200,44 @@ fileGetURL(char *base, char *spec)
if (isatty(0) || Verbose)
printf("Fetching %s...", fname), fflush(stdout);
pen[0] = '\0';
- if ((rp = make_playpen(pen, 0)) != NULL) {
- tpid = fork();
- if (!tpid) {
- dup2(fileno(ftp), 0);
- i = execl("/usr/bin/tar", "tar", Verbose ? "-xzvf" : "-xzf", "-", 0);
- exit(i);
- }
- else {
- int pstat;
-
- fclose(ftp);
- tpid = waitpid(tpid, &pstat, 0);
- if (Verbose)
- printf("tar command returns %d status\n", WEXITSTATUS(pstat));
- }
- }
- else
+ if ((rp = make_playpen(pen, 0)) == NULL) {
printf("Error: Unable to construct a new playpen for FTP!\n");
+ fclose(ftp);
+ return NULL;
+ }
+ if (pipe(pfd) == -1) {
+ warn("pipe()");
+ cleanup(0);
+ exit(2);
+ }
+ if ((tpid = fork()) == -1) {
+ warn("pipe()");
+ cleanup(0);
+ exit(2);
+ }
+ if (!tpid) {
+ close(pfd[1]);
+ dup2(pfd[0], 0);
+ close(pfd[0]);
+ execl("/usr/bin/tar", "tar", Verbose ? "-xzvf" : "-xzf", "-", 0);
+ _exit(2);
+ }
+ close(pfd[0]);
+ for (;;) {
+ if ((r = fread(buf, 1, sizeof buf, ftp)) < 1)
+ break;
+ if ((w = write(pfd[1], buf, r)) != r)
+ break;
+ }
fclose(ftp);
+ close(pfd[1]);
+ if (r == -1)
+ warn("warning: error reading from server");
+ if (w == -1)
+ warn("warning: error writing to tar");
+ tpid = waitpid(tpid, &pstat, 0);
+ if (Verbose)
+ printf("tar command returns %d status\n", WEXITSTATUS(pstat));
if (rp && (isatty(0) || Verbose))
printf(" Done.\n");
return rp;
OpenPOWER on IntegriCloud