]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Refuse to start with chroot set in a systemd env 4912/head
authorPieter Lexis <pieter.lexis@powerdns.com>
Mon, 16 Jan 2017 11:37:13 +0000 (12:37 +0100)
committerPieter Lexis <pieter.lexis@powerdns.com>
Tue, 14 Feb 2017 16:08:56 +0000 (17:08 +0100)
Closes #4848

docs/markdown/authoritative/settings.md
docs/markdown/recursor/settings.md
pdns/common_startup.cc
pdns/pdns_recursor.cc

index bf5bef67d68b41b5a765ca023d601e9dd278e8ab..c49f1ab9d077556c52e51029e9f5a273a9bf2063 100644 (file)
@@ -142,6 +142,9 @@ When setting `chroot`, all other paths in the config (except for
 [`config-dir`](#config-dir) and [`module-dir`](#module-dir)) set in the configuration
 are relative to the new root.
 
+When running on a system where systemd manages services, `chroot` does not work out of the box, as PowerDNS cannot use the `NOTIFY_SOCKET`.
+Either don't `chroot` on these systems or set the 'Type' of the this service to 'simple' instead of 'notify' (refer to the systemd documentation on how to modify unit-files)
+
 ## `config-dir`
 * Path
 
index 95f4b57aa598f8883c330ad77eabc58825ea62f3..5e242458f014624015c7f4723deeb3ed86512578 100644 (file)
@@ -129,6 +129,9 @@ in the configuration are relative to the new root.
 When using `chroot` and the API ([`webserver`](#webserver)), [`api-readonly`](#api-readonly)
 must be set and [`api-config-dir`](#api-config-dir) unset.
 
+When running on a system where systemd manages services, `chroot` does not work out of the box, as PowerDNS cannot use the `NOTIFY_SOCKET`.
+Either do not `chroot` on these systems or set the 'Type' of this service to 'simple' instead of 'notify' (refer to the systemd documentation on how to modify unit-files)
+
 ## `client-tcp-timeout`
 * Integer
 * Default: 2
index 66f06fcdcb25bbbf71f476a37e202104cdb5dae6..13b7860ff727dff424c8ddca9487d238e33ab0e6 100644 (file)
@@ -498,6 +498,14 @@ void mainthread()
    stubParseResolveConf();
 
    if(!::arg()["chroot"].empty()) {
+#ifdef HAVE_SYSTEMD
+     char *ns;
+     ns = getenv("NOTIFY_SOCKET");
+     if (ns != nullptr) {
+       L<<Logger::Error<<"Unable to chroot when running from systemd. Please disable chroot= or set the 'Type' for this service to 'simple'"<<endl;
+       exit(1);
+     }
+#endif
      triggerLoadOfLibraries();
      if(::arg().mustDo("master") || ::arg().mustDo("slave"))
         gethostbyname("a.root-servers.net"); // this forces all lookup libraries to be loaded
index 16c11466733ad0669b10c54379d5585a9428fb16..8e774d303e076f7c2198d22ada532db7b3b463e4 100644 (file)
@@ -2819,6 +2819,14 @@ int serviceMain(int argc, char*argv[])
   Utility::dropGroupPrivs(newuid, newgid);
 
   if (!::arg()["chroot"].empty()) {
+#ifdef HAVE_SYSTEMD
+     char *ns;
+     ns = getenv("NOTIFY_SOCKET");
+     if (ns != nullptr) {
+       L<<Logger::Error<<"Unable to chroot when running from systemd. Please disable chroot= or set the 'Type' for this service to 'simple'"<<endl;
+       exit(1);
+     }
+#endif
     if (chroot(::arg()["chroot"].c_str())<0 || chdir("/") < 0) {
       L<<Logger::Error<<"Unable to chroot to '"+::arg()["chroot"]+"': "<<strerror (errno)<<", exiting"<<endl;
       exit(1);