Prevent duplicate renderd sections (#421)

In order to remove any confusion if the user has duplicate `renderd` sections in their `renderd.conf` file.

Currently with a configuration like this one:
```ini
[renderd]
pid_file=/run/renderd/renderd.pid
socketname=/run/renderd/renderd.sock
stats_file=/run/renderd/renderd.stats
tile_dir=/var/cache/renderd/tiles

[renderd0]
pid_file=/run/renderd/renderd0.pid
socketname=/run/renderd/renderd0.sock
stats_file=/run/renderd/renderd0.stats
tile_dir=/var/cache/renderd/tiles
```
only the second `renderd` section (`renderd0`) will actually be used.

After this patch is merged, an error message will be shown and the application will exit.
This commit is contained in:
Hummeltech
2024-03-24 21:25:57 -07:00
committed by GitHub
parent aebb506485
commit 7f91d53ec3
2 changed files with 27 additions and 0 deletions

View File

@ -400,6 +400,11 @@ void process_renderd_sections(const char *config_file_name, renderd_config *conf
exit(7); exit(7);
} }
if (configs_dest[renderd_section_num].name != NULL) {
g_logger(G_LOG_LEVEL_CRITICAL, "Duplicate renderd config section names for section %i: %s & %s", renderd_section_num, configs_dest[renderd_section_num].name, section);
exit(7);
}
copy_string(section, &configs_dest[renderd_section_num].name, renderd_strlen + 2); copy_string(section, &configs_dest[renderd_section_num].name, renderd_strlen + 2);
process_config_int(ini, section, "ipport", &configs_dest[renderd_section_num].ipport, 0); process_config_int(ini, section, "ipport", &configs_dest[renderd_section_num].ipport, 0);

View File

@ -573,4 +573,26 @@ TEST_CASE("renderd_config config parser", "specific testing")
found = err_log_lines.find("Specified socketname (" + renderd_socketname + ") exceeds maximum allowed length of " + std::to_string(renderd_socketname_maxlen) + "."); found = err_log_lines.find("Specified socketname (" + renderd_socketname + ") exceeds maximum allowed length of " + std::to_string(renderd_socketname_maxlen) + ".");
REQUIRE(found > -1); REQUIRE(found > -1);
} }
SECTION("renderd.conf duplicate renderd section names", "should return 7") {
std::string renderd_conf = std::tmpnam(nullptr);
std::ofstream renderd_conf_file;
renderd_conf_file.open(renderd_conf);
renderd_conf_file << "[mapnik]\n[map]\n";
renderd_conf_file << "[renderd0]\n[renderd]\n";
renderd_conf_file.close();
std::string option = "--config " + renderd_conf;
std::string command = test_binary + " " + option;
// flawfinder: ignore
FILE *pipe = popen(command.c_str(), "r");
int status = pclose(pipe);
std::remove(renderd_conf.c_str());
REQUIRE(WEXITSTATUS(status) == 7);
err_log_lines = read_stderr();
found = err_log_lines.find("Duplicate renderd config section names for section 0: renderd0 & renderd");
REQUIRE(found > -1);
}
} }