|
41 | 41 | // Debugs |
42 | 42 | namespace header_rewrite_ns |
43 | 43 | { |
44 | | -std::once_flag initHRWLibs; |
| 44 | +std::once_flag initGeoLibs; |
| 45 | +std::once_flag initPlugin; |
45 | 46 | PluginFactory plugin_factory; |
46 | 47 | } // namespace header_rewrite_ns |
47 | 48 |
|
48 | 49 | static void |
49 | | -initHRWLibraries(const std::string &dbPath) |
| 50 | +initPluginFactory() |
50 | 51 | { |
51 | 52 | header_rewrite_ns::plugin_factory.setRuntimeDir(RecConfigReadRuntimeDir()).addSearchDir(RecConfigReadPluginDir()); |
| 53 | +} |
52 | 54 |
|
| 55 | +static void |
| 56 | +initGeoLibraries(const std::string &dbPath) |
| 57 | +{ |
53 | 58 | if (dbPath.empty()) { |
54 | 59 | return; |
55 | 60 | } |
@@ -597,7 +602,8 @@ TSPluginInit(int argc, const char *argv[]) |
597 | 602 |
|
598 | 603 | Dbg(pi_dbg_ctl, "Global geo db %s", geoDBpath.c_str()); |
599 | 604 |
|
600 | | - std::call_once(initHRWLibs, [&geoDBpath]() { initHRWLibraries(geoDBpath); }); |
| 605 | + std::call_once(initGeoLibs, [&geoDBpath]() { initGeoLibraries(geoDBpath); }); |
| 606 | + std::call_once(initPlugin, initPluginFactory); |
601 | 607 |
|
602 | 608 | // Parse the global config file(s). All rules are just appended |
603 | 609 | // to the "global" Rules configuration. |
@@ -705,17 +711,19 @@ TSRemapNewInstance(int argc, char *argv[], void **ih, char * /* errbuf ATS_UNUSE |
705 | 711 | } |
706 | 712 | } |
707 | 713 |
|
708 | | - if (!geoDBpath.empty() && !geoDBpath.starts_with('/')) { |
709 | | - geoDBpath = std::string(TSConfigDirGet()) + '/' + geoDBpath; |
710 | | - } |
711 | | - |
712 | 714 | if (!geoDBpath.empty()) { |
| 715 | + if (!geoDBpath.starts_with('/')) { |
| 716 | + geoDBpath = std::string(TSConfigDirGet()) + '/' + geoDBpath; |
| 717 | + } |
713 | 718 | Dbg(pi_dbg_ctl, "Remap geo db %s", geoDBpath.c_str()); |
| 719 | + |
| 720 | + // This MUST be called only if the geoDBpath is set. If called without a geoDBPath (i.e. outside of this if) then |
| 721 | + // NO hrw remap rule can load a mmdb file. |
| 722 | + // The call_once applies to every remap instance as its a plugin global |
| 723 | + std::call_once(initGeoLibs, [&geoDBpath]() { initGeoLibraries(geoDBpath); }); |
714 | 724 | } |
715 | 725 |
|
716 | | - // Always initialize the plugin factory, even if no geo DB is specified. This |
717 | | - // is needed for run-plugin to work with relative paths. |
718 | | - std::call_once(initHRWLibs, [&geoDBpath]() { initHRWLibraries(geoDBpath); }); |
| 726 | + std::call_once(initPlugin, initPluginFactory); |
719 | 727 |
|
720 | 728 | auto *conf = new RulesConfig(timezone, inboundIpSource); |
721 | 729 |
|
|
0 commit comments