diff options
| author | Roy Marples <roy@marples.name> | 2019-06-18 11:33:53 +0100 |
|---|---|---|
| committer | Roy Marples <roy@marples.name> | 2019-06-18 11:33:53 +0100 |
| commit | ae3c3144861a285e77d69e888cd7cd732fb2d7a1 (patch) | |
| tree | d692e469c71cd8f9e64a0fb62d701ae48bbbfc5e /src/ipv6.c | |
| parent | 6da1356363264bcfb6237797965ef59c234fa795 (diff) | |
| download | dhcpcd-ae3c3144861a285e77d69e888cd7cd732fb2d7a1.tar.xz | |
script: Write variables to a FILE
Each variable is NULL terminated inside the file just like the
control stream which saves us from having to flatten it when
writing to the control stream.
Once written, create env pointers to the start of each string
just after the NULL terminator.
This also means that we just need to free two buffers when
dhcpcd exits (FILE buffer and env buffer) rather than each variable
individually.
If open_memstream(3) is not supported by libc then dhcpcd will
write to a file in /tmp instead.
Diffstat (limited to 'src/ipv6.c')
| -rw-r--r-- | src/ipv6.c | 18 |
1 files changed, 6 insertions, 12 deletions
@@ -1540,23 +1540,17 @@ ipv6_staticdadcallback(void *arg) } ssize_t -ipv6_env(char **env, const char *prefix, const struct interface *ifp) +ipv6_env(FILE *fp, const char *prefix, const struct interface *ifp) { - char **ep; - ssize_t n; struct ipv6_addr *ia; - ep = env; - n = 0; ia = ipv6_iffindaddr(UNCONST(ifp), &ifp->options->req_addr6, IN6_IFF_NOTUSEABLE); - if (ia) { - if (env) - addvar(&ep, prefix, "ip6_address", ia->saddr); - n++; - } - - return n; + if (ia == NULL) + return 0; + if (efprintf(fp, "%s_ip6_address=%s", prefix, ia->saddr) == -1) + return -1; + return 1; } int |
