From 07f5399408b080d775786e45a5055cc0772741dc Mon Sep 17 00:00:00 2001 From: Loic Dachary Date: Wed, 1 Jan 2014 21:23:18 +0100 Subject: [PATCH] common: CEPH_ARGS should trim whitespaces 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 --- src/common/ceph_argparse.cc | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/src/common/ceph_argparse.cc b/src/common/ceph_argparse.cc index 245b38e234a..6d1c613c922 100644 --- a/src/common/ceph_argparse.cc +++ b/src/common/ceph_argparse.cc @@ -64,22 +64,13 @@ void env_to_vec(std::vector& 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 str_vec; + str_vec.clear(); + get_str_vec(p, " ", str_vec); + for (vector::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, -- 2.47.3