]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
common: CEPH_ARGS should trim whitespaces
authorLoic Dachary <loic@dachary.org>
Wed, 1 Jan 2014 20:23:18 +0000 (21:23 +0100)
committerLoic Dachary <loic@dachary.org>
Wed, 1 Jan 2014 20:23:18 +0000 (21:23 +0100)
CEPH_ARGS when parsed by env_to_vec did not trim trailing and leading
whitespaces: they would unexpectedly be parsed as empty arguments and
lead to confusing errors such as :

    CEPH_ARGS=' --id 3' ceph-conf --lookup mon-data
    unable to parse option: ''

The parsing code is replaced with str_vec(). It also resolves the
problem of the hard limit to 1000 characters imposed by the static
buffer that would silently truncate any CEPH_ARGS content.

Signed-off-by: Loic Dachary <loic@dachary.org>
src/common/ceph_argparse.cc

index 245b38e234ace18fbfdb349334f847ba90f501e2..6d1c613c9221bc70a4f62746e6b4124c6a477c58 100644 (file)
@@ -64,22 +64,13 @@ void env_to_vec(std::vector<const char*>& args, const char *name)
   if (!p)
     return;
 
-  static char buf[1000];
-  int len = MIN(strlen(p), sizeof(buf)-1);  // bleh.
-  memcpy(buf, p, len);
-  buf[len] = 0;
-  //cout << "CEPH_ARGS='" << p << ";" << endl;
-
-  p = buf;
-  while (*p && p < buf + len) {
-    char *e = p;
-    while (*e && *e != ' ')
-      e++;
-    *e = 0;
-    args.push_back(p);
-    //cout << "arg " << p << std::endl;
-    p = e+1;
-  }
+  static vector<string> str_vec;
+  str_vec.clear();
+  get_str_vec(p, " ", str_vec);
+  for (vector<string>::iterator i = str_vec.begin();
+       i != str_vec.end();
+       i++)
+    args.push_back(i->c_str());
 }
 
 void argv_to_vec(int argc, const char **argv,