Merge pull request #1698 from pi-hole/fix/config_put_delete

PUT/DELETE /api/config fixes
This commit is contained in:
DL6ER
2023-10-28 17:32:24 +02:00
committed by GitHub
5 changed files with 24 additions and 4 deletions
+4 -1
View File
@@ -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
+7 -1
View File
@@ -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);
}
+9 -2
View File
@@ -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;
+3
View File
@@ -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
+1
View File
@@ -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);