cluster: RHEL56 - ccs: Allow ccs_tool to use alternate base ports

Lon Hohberger lon at fedoraproject.org
Mon Mar 28 13:48:31 UTC 2011


Gitweb:        http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=2f81d99e85673db1989b17f9b4f5a3f37a405775
Commit:        2f81d99e85673db1989b17f9b4f5a3f37a405775
Parent:        98f3a54ca8b1bf4536fb3caac62e5e15cfda2675
Author:        Lon Hohberger <lhh at redhat.com>
AuthorDate:    Wed Feb 9 14:48:53 2011 -0500
Committer:     Lon Hohberger <lhh at redhat.com>
CommitterDate: Mon Mar 28 09:45:34 2011 -0400

ccs: Allow ccs_tool to use alternate base ports

Resolves: rhbz#677814

Signed-off-by: Lon Hohberger <lhh at redhat.com>
---
 ccs/ccs_tool/ccs_tool.c |    2 +-
 ccs/ccs_tool/update.c   |   64 ++++++++++++++++++++++++++++++++++++++++++++++-
 ccs/ccs_tool/update.h   |    1 +
 3 files changed, 65 insertions(+), 2 deletions(-)

diff --git a/ccs/ccs_tool/ccs_tool.c b/ccs/ccs_tool/ccs_tool.c
index dc54146..5fcd667 100644
--- a/ccs/ccs_tool/ccs_tool.c
+++ b/ccs/ccs_tool/ccs_tool.c
@@ -36,7 +36,7 @@ int main(int argc, char *argv[])
 		"Try 'ccs_tool help' for help.\n");
 	exit(EXIT_FAILURE);
       }
-      if(update(argv[optind+1])){
+      if(update2(argc-1, argv+1)){
 	fprintf(stderr, "\nFailed to update config file.\n");
 	exit(EXIT_FAILURE);
       }
diff --git a/ccs/ccs_tool/update.c b/ccs/ccs_tool/update.c
index 1defdaf..3af779b 100644
--- a/ccs/ccs_tool/update.c
+++ b/ccs/ccs_tool/update.c
@@ -113,11 +113,70 @@ fail:
 }
 
 
-int update(char *location)
+static int parse_args(int argc, char **argv, char **loc)
+{
+  int c, error, ret;
+
+  while ((c = getopt(argc, argv, "P:")) != EOF) {
+    switch(c) {
+    case 'P':
+      if(optarg[1] != ':'){
+        fprintf(stderr, "Bad argument to '-P' option.\n"
+                "Try '-h' for help.\n");
+        error = -EINVAL;
+        goto fail;
+      }
+      switch(optarg[0]){
+      case 'b': /* backend port number */
+        /* Not used by ccs_tool */
+        break;
+      case 'c': /* cluster base port number */
+        ret = atoi(optarg+2);
+        if(ret < 1024){
+          fprintf(stderr, "Bad cluster base port number.\n");
+          error = -EINVAL;
+          goto fail;
+        }
+        cluster_base_port = ret;
+        printf("Set cluster base port to %d\n", cluster_base_port);
+        break;
+      case 'f': /* frontend port number */
+        /* Not used by ccs_tool */
+        break;
+      }
+      break;
+    default:
+      goto fail;
+    }
+  }
+
+  *loc = argv[optind];
+
+  return 0;
+fail:
+  return error;
+}
+
+int update(const char *location)
+{
+  char *args[3];
+  char **argv;
+
+  args[0] = "update";
+  args[1] = location;
+  args[2] = NULL;
+
+  argv = args;
+
+  return update2(2, argv);
+}
+
+int update2(int argc, char **argv)
 {
   int error = 0;
   int i, fd;
   int cluster_fd = -1;
+  char *location = NULL;
   char true_location[256];
   xmlDocPtr doc = NULL;
   xmlChar *mem_doc;
@@ -132,6 +191,9 @@ int update(char *location)
 
   struct timeval tv;
 
+  if (parse_args(argc, argv, &location))
+    return -1;
+
   if (location[0] != '/') {
     memset(true_location, 0, 256);
     if (!getcwd(true_location, 256)) {
diff --git a/ccs/ccs_tool/update.h b/ccs/ccs_tool/update.h
index 19fd7cb..f706963 100644
--- a/ccs/ccs_tool/update.h
+++ b/ccs/ccs_tool/update.h
@@ -14,5 +14,6 @@
 #define __UPDATE_DOT_H__
 
 int update(char *location);
+int update2(int argc, char **argv);
 
 #endif /* __UPDATE_DOT_H__ */


More information about the cluster-commits mailing list