diff options
author | brian <brian@FreeBSD.org> | 2001-04-03 08:21:28 +0000 |
---|---|---|
committer | brian <brian@FreeBSD.org> | 2001-04-03 08:21:28 +0000 |
commit | 626603131bb3fde0d341e4ca885bb1b3803bbab7 (patch) | |
tree | b60dd4bfdcad0ab9bc9cc2d4bfc38622a6a557d1 /usr.sbin | |
parent | 281e45eb31cb2f712ab3e3d776eea8918fb856ee (diff) | |
download | FreeBSD-src-626603131bb3fde0d341e4ca885bb1b3803bbab7.zip FreeBSD-src-626603131bb3fde0d341e4ca885bb1b3803bbab7.tar.gz |
Be a bit more persistent when the NET_RT_IFLIST sysctl returns ENOMEM
rather than dropping out immediately.
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/ppp/iface.c | 45 |
1 files changed, 27 insertions, 18 deletions
diff --git a/usr.sbin/ppp/iface.c b/usr.sbin/ppp/iface.c index c64ad5a..a58fdac 100644 --- a/usr.sbin/ppp/iface.c +++ b/usr.sbin/ppp/iface.c @@ -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; |