]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cconf: added utility to read configuration
authorYehuda Sadeh <yehuda@hq.newdream.net>
Wed, 28 Jan 2009 18:49:37 +0000 (10:49 -0800)
committerYehuda Sadeh <yehuda@hq.newdream.net>
Wed, 28 Jan 2009 18:49:37 +0000 (10:49 -0800)
src/Makefile.am
src/cconf.cc [new file with mode: 0644]

index 09eb5504b41c20d9c5b3248515cee848806c4909..827e5565ea63683e61c6d46269f4f1f95d908cc5 100644 (file)
@@ -19,6 +19,8 @@ crushtool_SOURCES = crushtool.cc
 crushtool_LDADD = libcommon.a libcrush.a
 osdmaptool_SOURCES = osdmaptool.cc
 osdmaptool_LDADD = libcommon.a libcrush.a
+cconf_SOURCES = cconf.cc
+cconf_LDADD = libcommon.a
 
 mount_ceph_SOURCES = mount.ceph.c
 
@@ -43,7 +45,7 @@ csyn_LDADD = libcommon.a libclient.a libosdc.a libcrush.a libcommon.a
 
 bin_PROGRAMS = \
        cmon cmds cosd csyn \
-       ceph \
+       ceph cconf \
        mkmonfs monmaptool osdmaptool crushtool \
        streamtest dupstore dumpjournal testmsgr \
        mount.ceph
diff --git a/src/cconf.cc b/src/cconf.cc
new file mode 100644 (file)
index 0000000..1f4f03e
--- /dev/null
@@ -0,0 +1,70 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- 
+// vim: ts=8 sw=2 smarttab
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#include <sys/stat.h>
+#include <iostream>
+#include <string>
+using namespace std;
+
+#include "config.h"
+#include "common/ConfUtils.h"
+
+void usage() 
+{
+  cerr << "usage: cconf [--conf_file filename] <section> <key> [defval]" << std::endl;
+  exit(1);
+}
+
+int main(int argc, const char **argv) 
+{
+  const char *fname = NULL, *section = NULL;
+  const char *key = NULL, *defval = NULL;
+  char *val;
+  int param = 0;
+  vector<const char*> args;
+  argv_to_vec(argc, argv, args);
+  env_to_vec(args);
+
+  if (args.size() < 2)
+    usage();
+
+  for (unsigned i=0; i<args.size(); i++) {
+    if (strcmp(args[i],"--conf_file") == 0) {
+      if (i < args.size() - 1)
+        fname = args[++i];
+      else
+       usage();
+    } else {
+      switch (param) {
+       case 0:
+           section = args[i];
+           break;
+       case 1:
+           key = args[i];
+           break;
+       case 2:
+           defval = args[i];
+           break;
+      }
+      param++;
+    }
+  }
+
+  if ((param < 1) || (param > 3))
+    usage();
+
+  ConfFile cf(fname);
+
+  cf.parse();
+  cf.read(section, key, (char **)&val, defval);
+
+  if (val)
+    cout << val << std::endl;
+  else
+    exit(1);
+
+  exit(0);
+}