X-Git-Url: https://git.archive.openwrt.org/?p=project%2Fnetifd.git;a=blobdiff_plain;f=interface-ip.c;h=fc5a4a3aabfae0b945cd2f4a69b1963e57cfa1c8;hp=df2904faf3eb3e76ac376b03f0182a4ee2215b0b;hb=486aa750a164d41905beb61afec89268e3eb7f48;hpb=35d767f41931df99533fccd0fbf3aa844d869139 diff --git a/interface-ip.c b/interface-ip.c index df2904f..fc5a4a3 100644 --- a/interface-ip.c +++ b/interface-ip.c @@ -781,10 +781,11 @@ interface_write_resolv_conf(void) struct interface *iface; char *path = alloca(strlen(resolv_conf) + 5); FILE *f; + uint32_t crcold, crcnew; sprintf(path, "%s.tmp", resolv_conf); unlink(path); - f = fopen(path, "w"); + f = fopen(path, "w+"); if (!f) { D(INTERFACE, "Failed to open %s for writing\n", path); return; @@ -805,8 +806,21 @@ interface_write_resolv_conf(void) if (!iface->proto_ip.no_dns) write_resolv_conf_entries(f, &iface->proto_ip); } + fflush(f); + rewind(f); + crcnew = crc32_file(f); fclose(f); - if (rename(path, resolv_conf) < 0) { + + crcold = crcnew + 1; + f = fopen(resolv_conf, "r"); + if (f) { + crcold = crc32_file(f); + fclose(f); + } + + if (crcold == crcnew) { + unlink(path); + } else if (rename(path, resolv_conf) < 0) { D(INTERFACE, "Failed to replace %s\n", resolv_conf); unlink(path); }