diff --git a/src/api/config.c b/src/api/config.c index 5624f392..02312621 100644 --- a/src/api/config.c +++ b/src/api/config.c @@ -940,7 +940,10 @@ static int api_config_put_delete(struct ftl_conn *api) // Store changed configuration to disk writeFTLtoml(true); - return api->method == HTTP_PUT ? 201 : 204; // 201 - Created or 204 - No content + // Send empty reply with matching HTTP status code + // 201 - Created or 204 - No content + cJSON *json = JSON_NEW_OBJECT(); + JSON_SEND_OBJECT_CODE(json, api->method == HTTP_PUT ? 201 : 204); } // Endpoint /api/config router diff --git a/src/args.c b/src/args.c index 0d923ed9..f80a046e 100644 --- a/src/args.c +++ b/src/args.c @@ -862,12 +862,18 @@ void parse_args(int argc, char* argv[]) // defined in src/dnsmasq/option.c extern void reset_usage_indicator(void); +// defined in src/log.h +bool only_testing = false; void test_dnsmasq_options(int argc, const char *argv[]) { // Reset getopt before calling read_opts optind = 0; + + // Signal we don't want to jump back to FTL's main() + // but die after configuration parsing + only_testing = true; + // Call dnsmasq's option parser reset_usage_indicator(); - // Call read_opts read_opts(argc, (char**)argv, NULL); } diff --git a/src/config/dnsmasq_config.c b/src/config/dnsmasq_config.c index 2b1f2e42..e727e3a7 100644 --- a/src/config/dnsmasq_config.c +++ b/src/config/dnsmasq_config.c @@ -66,7 +66,6 @@ static bool test_dnsmasq_config(char errbuf[ERRBUF_SIZE]) // Redirect STDERR into our pipe dup2(pipefd[1], STDERR_FILENO); - dup2(pipefd[1], STDOUT_FILENO); // Call dnsmasq's option parser test_dnsmasq_options(3, argv); @@ -99,6 +98,10 @@ static bool test_dnsmasq_config(char errbuf[ERRBUF_SIZE]) // Strip newline character (if present) if(errbuf[strlen(errbuf)-1] == '\n') errbuf[strlen(errbuf)-1] = '\0'; + // Replace any possible internal newline characters by spaces + char *ptr = errbuf; + while((ptr = strchr(ptr, '\n')) != NULL) + *ptr = ' '; log_debug(DEBUG_CONFIG, "dnsmasq pipe: %s", errbuf); } } @@ -106,8 +109,12 @@ static bool test_dnsmasq_config(char errbuf[ERRBUF_SIZE]) // Wait until child has exited to get its return code int status; waitpid(cpid, &status, 0); - code = WEXITSTATUS(status); + // Get return code if child exited normally + if(WIFEXITED(status)) + code = WEXITSTATUS(status); + + // Check if child crashed if(WIFSIGNALED(status)) { crashed = true; diff --git a/src/dnsmasq/log.c b/src/dnsmasq/log.c index 67f059ad..6cd8a696 100644 --- a/src/dnsmasq/log.c +++ b/src/dnsmasq/log.c @@ -517,6 +517,9 @@ void die(char *message, char *arg1, int exit_code) flush_log(); /********** Pi-hole modification *************/ + if(only_testing) + exit(exit_code); + FTL_log_dnsmasq_fatal(message, arg1, errmess); // Jump back into main() to exit gracefully diff --git a/src/log.h b/src/log.h index 228e9780..5c5bf888 100644 --- a/src/log.h +++ b/src/log.h @@ -38,6 +38,7 @@ FPRINTF_CENTER(fp, width, "#", fmt , "#\n", __VA_ARGS__) extern bool debug_flags[DEBUG_MAX]; +extern bool only_testing; void clear_debug_flags(void); void init_FTL_log(const char *name);