Skip to content

Commit

Permalink
Merge pull request #13646 from omoerbeek/backport-13588-to-rec-5.0.x
Browse files Browse the repository at this point in the history
tec: Backport 13588 to rec 5.0.x: fix handling of RUNTIME_DIRETCORY and NOD dirs
  • Loading branch information
omoerbeek committed Dec 18, 2023
2 parents 2225719 + 3d3d375 commit d1499af
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .github/actions/spell-check/expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,8 @@ noaction
noad
noall
nocookie
NODCACHEDIRNOD
NODCACHEDIRUDR
noedns
noerrors
NOLOCK
Expand Down
4 changes: 1 addition & 3 deletions pdns/recursordist/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@ AM_CXXFLAGS = \
-DPKGLIBDIR=\"$(pkglibdir)\" \
-DLOCALSTATEDIR=\"$(socketdir)\"

if NOD_ENABLED
AM_CXXFLAGS += \
-DNODCACHEDIR=\"$(nodcachedir)\"
endif
-DNODCACHEDIRNOD=\"$(nodcachedir)/nod\" -DNODCACHEDIRUDR=\"$(nodcachedir)/udr\"

if FSTRM
AM_CPPFLAGS += \
Expand Down
7 changes: 7 additions & 0 deletions pdns/recursordist/rec-main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2939,6 +2939,13 @@ static void handleRuntimeDefaults(Logr::log_t log)
::arg().set("server-id") = myHostname.has_value() ? *myHostname : "";
}

if (::arg()["socket-dir"].empty()) {
auto* runtimeDir = getenv("RUNTIME_DIRECTORY"); // NOLINT(concurrency-mt-unsafe,cppcoreguidelines-pro-type-vararg)
if (runtimeDir != nullptr) {
::arg().set("socket-dir") = runtimeDir;
}
}

if (::arg()["socket-dir"].empty()) {
if (::arg()["chroot"].empty()) {
::arg().set("socket-dir") = std::string(LOCALSTATEDIR) + "/pdns-recursor";
Expand Down
8 changes: 6 additions & 2 deletions pdns/recursordist/settings/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@ def quote(arg):
"""Return a quoted string"""
return '"' + arg + '"'

def isEnvVar(name):
return name in ('SYSCONFDIR', 'NODCACHEDIRNOD', 'NODCACHEDIRUDR')

def gen_cxx_defineoldsettings(file, entries):
"""Generate C++ code to declare old-style settings"""
file.write('void pdns::settings::rec::defineOldStyleSettings()\n{\n')
Expand All @@ -221,7 +224,7 @@ def gen_cxx_defineoldsettings(file, entries):
elif entry['type'] == LType.Command:
file.write(f" ::arg().setCmd({oldname}, {helptxt});\n")
else:
cxxdef = 'SYSCONFDIR' if entry['default'] == 'SYSCONFDIR' else quote(entry['default'])
cxxdef = entry['default'] if isEnvVar(entry['default']) else quote(entry['default'])
file.write(f" ::arg().set({oldname}, {helptxt}) = {cxxdef};\n")
file.write('}\n\n')

Expand Down Expand Up @@ -415,7 +418,8 @@ def gen_rust_default_functions(entry, name, rust_type):
return gen_rust_authzonevec_default_functions(name)
ret = f'// DEFAULT HANDLING for {name}\n'
ret += f'fn default_value_{name}() -> {rust_type} {{\n'
rustdef = 'env!("SYSCONFDIR")' if entry['default'] == 'SYSCONFDIR' else quote(entry['default'])
defvalue = entry['default']
rustdef = f'env!("{defvalue}")' if isEnvVar(defvalue) else quote(defvalue)
ret += f" String::from({rustdef})\n"
ret += '}\n'
if rust_type == 'String':
Expand Down
2 changes: 1 addition & 1 deletion pdns/recursordist/settings/rust/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ EXTRA_DIST = \

# should actually end up in a target specific dir...
libsettings.a lib.rs.h: src/bridge.rs src/lib.rs src/helpers.rs Cargo.toml Cargo.lock build.rs
SYSCONFDIR=$(sysconfdir) $(CARGO) build --release $(RUST_TARGET)
SYSCONFDIR=$(sysconfdir) NODCACHEDIRNOD=$(localstatedir)/nod NODCACHEDIRUDR=$(localstatedir)/udr $(CARGO) build --release $(RUST_TARGET)
cp target/$(RUSTC_TARGET_ARCH)/release/libsettings.a libsettings.a
cp target/$(RUSTC_TARGET_ARCH)/cxxbridge/settings/src/lib.rs.h lib.rs.h
cp target/$(RUSTC_TARGET_ARCH)/cxxbridge/rust/cxx.h cxx.h
Expand Down
8 changes: 6 additions & 2 deletions pdns/recursordist/settings/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@
'section' : 'recursor',
'type' : LType.String,
'default' : 'SYSCONFDIR',
'docdefault': 'Determined by distribution',
'help' : 'Location of configuration directory (recursor.conf or recursor.yml)',
'doc' : '''
Location of configuration directory (where ``recursor.conf`` or ``recursor.yml`` is stored).
Expand Down Expand Up @@ -1715,7 +1716,8 @@
'section' : 'nod',
'oldname' : 'new-domain-history-dir',
'type' : LType.String,
'default' : '/usr/local/var/lib/pdns-recursor/nod',
'default' : 'NODCACHEDIRNOD',
'docdefault': 'Determined by distribution',
'help' : 'Persist new domain tracking data here to persist between restarts',
'doc' : '''
This setting controls which directory is used to store the on-disk
Expand Down Expand Up @@ -2358,6 +2360,7 @@
The default depends on ``LOCALSTATEDIR`` or the ``--with-socketdir`` setting when building (usually ``/var/run`` or ``/run``).
When using :ref:`setting-chroot` the default becomes ``/``.
The default value is overruled by the ``RUNTIME_DIRECTORY`` environment variable when that variable has a value (e.g. under systemd).
''',
},
{
Expand Down Expand Up @@ -2821,7 +2824,8 @@
'name' : 'unique_response_history_dir',
'section' : 'nod',
'type' : LType.String,
'default' : '/usr/local/var/lib/pdns-recursor/udr',
'default' : 'NODCACHEDIRUDR',
'docdefault': 'Determined by distribution',
'help' : 'Persist unique response tracking data here to persist between restarts',
'doc' : '''
This setting controls which directory is used to store the on-disk
Expand Down

0 comments on commit d1499af

Please sign in to comment.