diff options
author | brian <brian@cvs.openbsd.org> | 2001-04-03 08:23:28 +0000 |
---|---|---|
committer | brian <brian@cvs.openbsd.org> | 2001-04-03 08:23:28 +0000 |
commit | 78797e58aa97153b8fe7c81712529ae8b2a30ae7 (patch) | |
tree | f333f34cb77f85edfa21f2cb790cd098b30b2eff | |
parent | 0383dde0611630768842418df749dc8f8f0e639d (diff) |
Be a bit more persistent when the NET_RT_IFLIST sysctl returns ENOMEM
rather than dropping out immediately.
-rw-r--r-- | usr.sbin/ppp/ppp/iface.c | 47 |
1 files changed, 28 insertions, 19 deletions
diff --git a/usr.sbin/ppp/ppp/iface.c b/usr.sbin/ppp/ppp/iface.c index 55a992608cf..e7801e90840 100644 --- a/usr.sbin/ppp/ppp/iface.c +++ b/usr.sbin/ppp/ppp/iface.c @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $OpenBSD: iface.c,v 1.14 2001/03/28 09:52:56 brian Exp $ + * $OpenBSD: iface.c,v 1.15 2001/04/03 08:23:27 brian Exp $ */ #include <sys/param.h> @@ -94,7 +94,7 @@ bitsinmask(struct in_addr mask) struct iface * iface_Create(const char *name) { - int mib[6], s; + int mib[6], s, maxtries, err; size_t needed, namelen; char *buf, *ptr, *end; struct if_msghdr *ifm; @@ -117,25 +117,34 @@ iface_Create(const char *name) mib[4] = NET_RT_IFLIST; mib[5] = 0; - if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0) { - fprintf(stderr, "iface_Create: sysctl: estimate: %s\n", - strerror(errno)); - close(s); - return NULL; - } + maxtries = 20; + err = 0; + do { + if (maxtries-- == 0 || (err && err != ENOMEM)) { + fprintf(stderr, "iface_Create: sysctl: %s\n", strerror(err)); + close(s); + return NULL; + } - if ((buf = (char *)malloc(needed)) == NULL) { - fprintf(stderr, "iface_Create: malloc failed: %s\n", strerror(errno)); - close(s); - return NULL; - } + if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0) { + fprintf(stderr, "iface_Create: sysctl: estimate: %s\n", + strerror(errno)); + close(s); + return NULL; + } - if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0) { - fprintf(stderr, "iface_Create: sysctl: %s\n", strerror(errno)); - free(buf); - close(s); - return NULL; - } + if ((buf = (char *)malloc(needed)) == NULL) { + fprintf(stderr, "iface_Create: malloc failed: %s\n", strerror(errno)); + close(s); + return NULL; + } + + if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0) { + err = errno; + free(buf); + buf = NULL; + } + } while (buf == NULL); ptr = buf; end = buf + needed; |