This is an automated email from the ASF dual-hosted git repository.

abudnik pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mesos.git

commit ea670eca55af847bd7fcba1510726dd0059edf32
Author: Andrei Budnik <abud...@apache.org>
AuthorDate: Thu Feb 20 17:30:18 2020 +0100

    Fixed systemd socket activation on old systemd versions.
    
    This patch fixes the bug when `listenFdsWithName` function returns
    an empty set of file descriptors on pre-227 systemd versions when
    `domain_socket_location` value is not equals to the "systemd:unknown".
    This happens when a user expects a newer version of systemd and
    specifies a "systemd/<value taken from FileDescriptorName>", but
    the actual systemd version does not support `FileDescriptorName`.
    In this case, `LISTEN_FDNAMES` env variable is not specified,
    so all socket FDs, which are specified by the `LISTEN_FDS`,
    must be used to locate the path to the domain socket.
    
    Review: https://reviews.apache.org/r/72158
---
 src/linux/systemd.cpp | 6 +++---
 src/linux/systemd.hpp | 3 ++-
 src/slave/main.cpp    | 5 ++++-
 3 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/src/linux/systemd.cpp b/src/linux/systemd.cpp
index c7815a0..75d3c2b 100644
--- a/src/linux/systemd.cpp
+++ b/src/linux/systemd.cpp
@@ -395,7 +395,7 @@ Try<std::vector<int>> listenFds()
 }
 
 
-Try<std::vector<int>> listenFdsWithName(const std::string& name)
+Try<std::vector<int>> listenFdsWithNames(const hashset<string>& names)
 {
   Try<std::vector<int>> fds = listenFds();
   if (fds.isError()) {
@@ -420,8 +420,8 @@ Try<std::vector<int>> listenFdsWithName(const std::string& 
name)
   }
 
   std::vector<int> result;
-  for (size_t i=0; i < listenFdnames.size(); ++i) {
-    if (listenFdnames[i] == name) {
+  for (size_t i = 0; i < listenFdnames.size(); ++i) {
+    if (names.contains(listenFdnames[i])) {
       result.push_back(fds->at(i));
     }
   }
diff --git a/src/linux/systemd.hpp b/src/linux/systemd.hpp
index ba96000..e3644c0 100644
--- a/src/linux/systemd.hpp
+++ b/src/linux/systemd.hpp
@@ -20,6 +20,7 @@
 #include <process/subprocess.hpp>
 
 #include <stout/flags.hpp>
+#include <stout/hashset.hpp>
 #include <stout/nothing.hpp>
 #include <stout/path.hpp>
 #include <stout/try.hpp>
@@ -101,7 +102,7 @@ Try<std::vector<int>> listenFds();
 // The names are set by the `FileDescriptorName=` directive in the unit file.
 // This requires systemd 227 or newer. Since any number of unit files can
 // specify the same name, this can return more than one file descriptor.
-Try<std::vector<int>> listenFdsWithName(const std::string& name);
+Try<std::vector<int>> listenFdsWithNames(const hashset<std::string>& names);
 
 // Clear the `$LISTEN_PID`, `$LISTEN_FDS` and `$LISTEN_FDNAMES` environment
 // variables.
diff --git a/src/slave/main.cpp b/src/slave/main.cpp
index c1e6551..0aa2cc9 100644
--- a/src/slave/main.cpp
+++ b/src/slave/main.cpp
@@ -651,8 +651,11 @@ int main(int argc, char** argv)
       // Chop off `systemd:` prefix.
       std::string name = flags.domain_socket_location->substr(8);
 #ifdef __linux__
+      // NOTE: Some systemd versions do not support FileDescriptorName,
+      // thus we also need to listen on descriptors with name "unknown",
+      // which is used for sockets where no name could be determined.
       Try<std::vector<int>> socketFds =
-        systemd::socket_activation::listenFdsWithName(name);
+        systemd::socket_activation::listenFdsWithNames({name, "unknown"});
 #else
       Try<std::vector<int>> socketFds =
         Try<std::vector<int>>({}); // Dummy to avoid compile errors.

Reply via email to