summaryrefslogtreecommitdiffstats
path: root/src/ipv6.c
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2019-06-18 11:33:53 +0100
committerRoy Marples <roy@marples.name>2019-06-18 11:33:53 +0100
commitae3c3144861a285e77d69e888cd7cd732fb2d7a1 (patch)
treed692e469c71cd8f9e64a0fb62d701ae48bbbfc5e /src/ipv6.c
parent6da1356363264bcfb6237797965ef59c234fa795 (diff)
downloaddhcpcd-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.c18
1 files changed, 6 insertions, 12 deletions
diff --git a/src/ipv6.c b/src/ipv6.c
index 8288cb40..01286173 100644
--- a/src/ipv6.c
+++ b/src/ipv6.c
@@ -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