]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
common: make it safe to call env_to_vec multiple times
authorJeff Layton <jlayton@redhat.com>
Wed, 11 Oct 2017 15:16:38 +0000 (11:16 -0400)
committerJeff Layton <jlayton@redhat.com>
Wed, 11 Oct 2017 15:16:38 +0000 (11:16 -0400)
After it has been called once and we have outstanding CephContexts with
pointers into str_vec, we can't call get_str_vec on it again.

Add a static local mutex to protect access to str_vec.

Tracker: http://tracker.ceph.com/issues/21512
Signed-off-by: Jeff Layton <jlayton@redhat.com>
src/common/ceph_argparse.cc

index 355224d0a84f0b975d10a722ed1d036145031207..7630d20322e4d62ed344de81ae15172dbe4a20a5 100644 (file)
@@ -98,10 +98,20 @@ void env_to_vec(std::vector<const char*>& args, const char *name)
 
   std::vector<const char*> env_options;
   std::vector<const char*> env_arguments;
-  static vector<string> str_vec;
   std::vector<const char*> env;
-  str_vec.clear();
-  get_str_vec(p, " ", str_vec);
+
+  static std::mutex str_vec_lock;
+  static vector<string> str_vec;
+
+  /*
+   * We can only populate str_vec once. Other threads could hold pointers into
+   * it, so clearing it out and replacing it is not currently safe.
+   */
+  str_vec_lock.lock();
+  if (str_vec.empty())
+    get_str_vec(p, " ", str_vec);
+  str_vec_lock.unlock();
+
   for (vector<string>::iterator i = str_vec.begin();
        i != str_vec.end();
        ++i)