+ fchmod(fileno(f), 0644);
+
+ fputs("# This file is managed by systemd-networkd(8). Do not edit.\n#\n"
+ "# Third party programs must not access this file directly, but\n"
+ "# only through the symlink at /etc/resolv.conf. To manage\n"
+ "# resolv.conf(5) in a different way, replace the symlink by a\n"
+ "# static file or a different symlink.\n\n", f);
+
+ HASHMAP_FOREACH(link, m->links, i) {
+ if (link->dhcp_lease) {
+ struct in_addr *nameservers;
+ size_t nameservers_size;
+
+ if (link->network->dhcp_dns) {
+ r = sd_dhcp_lease_get_dns(link->dhcp_lease, &nameservers, &nameservers_size);
+ if (r >= 0) {
+ unsigned j;
+
+ for (j = 0; j < nameservers_size; j++)
+ append_dns(f, &nameservers[j], AF_INET, &count);
+ }
+ }
+
+ if (link->network->dhcp_domainname && !domainname) {
+ r = sd_dhcp_lease_get_domainname(link->dhcp_lease, &domainname);
+ if (r >= 0)
+ fprintf(f, "domain %s\n", domainname);
+ }
+ }
+ }
+
+ HASHMAP_FOREACH(link, m->links, i) {
+ if (link->network && link->network->dns) {
+ Address *address;
+ Iterator j;
+
+ SET_FOREACH(address, link->network->dns, j) {
+ append_dns(f, &address->in_addr.in,
+ address->family, &count);
+ }
+ }
+ }
+
+ fflush(f);
+
+ if (ferror(f) || rename(temp_path, "/run/systemd/network/resolv.conf") < 0) {
+ r = -errno;
+ unlink("/run/systemd/network/resolv.conf");
+ unlink(temp_path);