FreeBSD Bugzilla – Attachment 203750 Details for
Bug 195191
rtadvd(8): Retry on NET_RT_IFLIST sysctl failure like getifaddrs
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Retry NET_RT_IFLIST sysctl
rtadvd_retry_sysctl_12-RELEASE.patch (text/plain), 2.04 KB, created by
guyyur
on 2019-04-17 18:48:07 UTC
(
hide
)
Description:
Retry NET_RT_IFLIST sysctl
Filename:
MIME Type:
Creator:
guyyur
Created:
2019-04-17 18:48:07 UTC
Size:
2.04 KB
patch
obsolete
>Index: usr.sbin/rtadvd/if.c >=================================================================== >--- usr.sbin/rtadvd/if.c (revision 344217) >+++ usr.sbin/rtadvd/if.c (working copy) >@@ -408,6 +408,7 @@ > return (0); > } > >+#define MAX_SYSCTL_TRY 5 > struct ifinfo * > update_ifinfo(struct ifilist_head_t *ifi_head, int ifindex) > { >@@ -419,27 +420,45 @@ > size_t len; > char *lim; > int mib[] = { CTL_NET, PF_ROUTE, 0, AF_INET6, NET_RT_IFLIST, 0 }; >- int error; >+ int error, ntry = 0; > > syslog(LOG_DEBUG, "<%s> enter", __func__); > >- if (sysctl(mib, sizeof(mib)/sizeof(mib[0]), NULL, &len, NULL, 0) < >- 0) { >- syslog(LOG_ERR, >- "<%s> sysctl: NET_RT_IFLIST size get failed", __func__); >- exit(1); >- } >- if ((msg = malloc(len)) == NULL) { >- syslog(LOG_ERR, "<%s> malloc failed", __func__); >- exit(1); >- } >- if (sysctl(mib, sizeof(mib)/sizeof(mib[0]), msg, &len, NULL, 0) < >- 0) { >- syslog(LOG_ERR, >- "<%s> sysctl: NET_RT_IFLIST get failed", __func__); >- exit(1); >- } >+ do { >+ /* >+ * We'll try to get addresses several times in case that >+ * the number of addresses is unexpectedly increased during >+ * the two sysctl calls. This should rarely happen. >+ * Portability note: since FreeBSD does not add margin of >+ * memory at the first sysctl, the possibility of failure on >+ * the second sysctl call is a bit higher. >+ */ > >+ if (sysctl(mib, sizeof(mib)/sizeof(mib[0]), NULL, &len, NULL, >+ 0) < 0) { >+ syslog(LOG_ERR, >+ "<%s> sysctl: NET_RT_IFLIST size get failed", >+ __func__); >+ exit(1); >+ } >+ if ((msg = malloc(len)) == NULL) { >+ syslog(LOG_ERR, "<%s> malloc failed", __func__); >+ exit(1); >+ } >+ if (sysctl(mib, sizeof(mib)/sizeof(mib[0]), msg, &len, NULL, >+ 0) < 0) { >+ if (errno != ENOMEM || ++ntry >= MAX_SYSCTL_TRY) { >+ free(msg); >+ syslog(LOG_ERR, >+ "<%s> sysctl: NET_RT_IFLIST get failed", >+ __func__); >+ exit(1); >+ } >+ free(msg); >+ msg = NULL; >+ } >+ } while (msg == NULL); >+ > lim = msg + len; > for (ifm = (struct if_msghdr *)msg; > ifm != NULL && ifm < (struct if_msghdr *)lim;
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 195191
:
149611
| 203750