Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Make (push) Successful in 5s
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-CMake (push) Successful in 10s
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Meson (push) Successful in 8s
30 lines
763 B
C
30 lines
763 B
C
#include "settings.h"
|
|
|
|
#define DNSMASQ_RESOLV_FILE_TMP "resolv.conf.tmp"
|
|
|
|
char *set_resolvs(cJSON *resolvs) {
|
|
FILE *resolvs_file_tmp = fopen(DNSMASQ_RESOLV_FILE_TMP, "w");
|
|
if (!resolvs_file_tmp) {
|
|
return "Failed to open resolv file";
|
|
}
|
|
|
|
cJSON *resolv = resolvs->child;
|
|
while (resolv) {
|
|
if (!cJSON_IsString(resolv)) {
|
|
remove(DNSMASQ_RESOLV_FILE_TMP);
|
|
return "Invalid resolv";
|
|
}
|
|
fprintf(resolvs_file_tmp, "nameserver %s\n", resolv->valuestring);
|
|
resolv = resolv->next;
|
|
}
|
|
|
|
fclose(resolvs_file_tmp);
|
|
|
|
if (rename(DNSMASQ_RESOLV_FILE_TMP, "/etc/dnsmasq.conf.d/resolv.conf") != 0) {
|
|
remove(DNSMASQ_RESOLV_FILE_TMP);
|
|
return "Failed to rename resolv file";
|
|
}
|
|
remove(DNSMASQ_RESOLV_FILE_TMP);
|
|
return nullptr;
|
|
}
|