]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
test/admin_socket_output: Don't invalidate 'target' iterator 38076/head
authorBrad Hubbard <bhubbard@redhat.com>
Sat, 14 Nov 2020 01:53:06 +0000 (11:53 +1000)
committerBrad Hubbard <bhubbard@redhat.com>
Sat, 14 Nov 2020 01:53:06 +0000 (11:53 +1000)
Fixes: https://tracker.ceph.com/issues/48204
Signed-off-by: Brad Hubbard <bhubbard@redhat.com>
src/test/admin_socket_output.cc

index 1302391c9cb3a2b46079bcb26fe2147d308056d5..76e6e567726fd6a15531ca9a27c205cbb6efd85b 100644 (file)
@@ -74,16 +74,20 @@ void AdminSocketOutput::postpone(const std::string &target,
 
 bool AdminSocketOutput::init_sockets() {
   std::cout << "Initialising sockets" << std::endl;
-  for (const auto &x : fs::directory_iterator(socketdir)) {
+  std::string socket_regex = R"(\..*\.asok)";
+  for (const auto &x : fs::recursive_directory_iterator(socketdir)) {
     std::cout << x.path() << std::endl;
     if (x.path().extension() == ".asok") {
-      for (auto &target : targets) {
-        if (std::regex_search(x.path().filename().string(),
-            std::regex(prefix + target + R"(\..*\.asok)"))) {
-          std::cout << "Found " << target << " socket " << x.path()
+      for (auto target = targets.cbegin(); target != targets.cend();) {
+        std::regex reg(prefix + *target + socket_regex);
+        if (std::regex_search(x.path().filename().string(), reg)) {
+          std::cout << "Found " << *target << " socket " << x.path()
                     << std::endl;
-          sockets.insert(std::make_pair(target, x.path().string()));
-          targets.erase(target);
+          sockets.insert(std::make_pair(*target, x.path().string()));
+          target = targets.erase(target);
+        }
+        else {
+          ++target;
         }
       }
       if (targets.empty()) {