From 3e966fa3497988f2e7a49f8c23d1de688f6343d4 Mon Sep 17 00:00:00 2001 From: mycroft Date: Thu, 19 Sep 2002 02:13:57 +0000 Subject: [PATCH] select() -> poll() Also, remove a call to path_create() that causes the `prepend' path held by pkg_perform() to be deleted, causing a core dump later when pkg_perform() tries to remove it itself. --- usr.sbin/pkg_install/lib/ftpio.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/usr.sbin/pkg_install/lib/ftpio.c b/usr.sbin/pkg_install/lib/ftpio.c index d35a99762746..d6339917dfd8 100644 --- a/usr.sbin/pkg_install/lib/ftpio.c +++ b/usr.sbin/pkg_install/lib/ftpio.c @@ -1,8 +1,8 @@ -/* $NetBSD: ftpio.c,v 1.41 2002/07/20 08:40:19 grant Exp $ */ +/* $NetBSD: ftpio.c,v 1.42 2002/09/19 02:13:57 mycroft Exp $ */ #include #ifndef lint -__RCSID("$NetBSD: ftpio.c,v 1.41 2002/07/20 08:40:19 grant Exp $"); +__RCSID("$NetBSD: ftpio.c,v 1.42 2002/09/19 02:13:57 mycroft Exp $"); #endif /* @@ -37,6 +37,7 @@ __RCSID("$NetBSD: ftpio.c,v 1.41 2002/07/20 08:40:19 grant Exp $"); #include #include +#include #include #include #include @@ -100,7 +101,7 @@ expect(int fd, const char *str, int *ftprc) #endif /* EXPECT_DEBUG */ regex_t rstr; int done; - struct timeval timeout; + struct pollfd set[1]; int retval; regmatch_t match; int verbose_expect=0; @@ -124,16 +125,12 @@ expect(int fd, const char *str, int *ftprc) memset(buf, '\n', sizeof(buf)); - timeout.tv_sec=10*60; /* seconds until next message from tar */ - timeout.tv_usec=0; done=0; retval=0; + set[0].fd = fd; + set[0].events = POLLIN; while(!done) { - fd_set fdset; - - FD_ZERO(&fdset); - FD_SET(fd, &fdset); - rc = select(FD_SETSIZE, &fdset, NULL, NULL, &timeout); + rc = poll(set, 1, 10*60*1000); /* seconds until next message from tar */ switch (rc) { case -1: if (errno == EINTR) @@ -164,6 +161,12 @@ expect(int fd, const char *str, int *ftprc) retval = -1; break; default: + if (set[0].revents & POLLHUP) { + done = 1; + retval = -1; + break; + } + rc=read(fd,&buf[sizeof(buf)-1],1); if (verbose_expect) @@ -332,7 +335,7 @@ setupCoproc(const char *base) static void sigchld_handler (int n) { - /* Make select(2) return EINTR */ + /* Make poll(2) return EINTR */ } @@ -667,7 +670,9 @@ unpackURL(const char *url, const char *dir) /* Leave a hint for any depending pkgs that may need it */ if (getenv("PKG_PATH") == NULL) { setenv("PKG_PATH", pkg_path, 1); +#if 0 path_create(pkg_path); /* XXX */ +#endif printf("setenv PKG_PATH='%s'\n",pkg_path); }