[Ocfs2-tools-commits] jlbec commits r1078 - branches/global-heartbeat/ocfs2_hb_ctl

svn-commits at oss.oracle.com svn-commits at oss.oracle.com
Wed Sep 7 04:33:29 CDT 2005


Author: jlbec
Date: 2005-09-07 04:33:28 -0500 (Wed, 07 Sep 2005)
New Revision: 1078

Modified:
   branches/global-heartbeat/ocfs2_hb_ctl/ocfs2_hb_ctl.c
Log:

o Teach ocfs2_hb_ctl to understand --help and --version



Modified: branches/global-heartbeat/ocfs2_hb_ctl/ocfs2_hb_ctl.c
===================================================================
--- branches/global-heartbeat/ocfs2_hb_ctl/ocfs2_hb_ctl.c	2005-09-07 03:14:03 UTC (rev 1077)
+++ branches/global-heartbeat/ocfs2_hb_ctl/ocfs2_hb_ctl.c	2005-09-07 09:33:28 UTC (rev 1078)
@@ -50,6 +50,7 @@
 enum hb_ctl_action {
 	HB_ACTION_UNKNOWN,
 	HB_ACTION_USAGE,
+	HB_ACTION_VERSION,
 	HB_ACTION_START,
 	HB_ACTION_STOP,
 	HB_ACTION_REFINFO,
@@ -371,6 +372,11 @@
 	return ret;
 }
 
+static void print_version(void)
+{
+	fprintf(stdout, "%s: version %s\n", progname, VERSION);
+}
+
 static int read_options(int argc, char **argv, struct hb_ctl_options *hbo)
 {
 	int c, ret;
@@ -378,7 +384,7 @@
 	ret = 0;
 
 	while(1) {
-		c = getopt(argc, argv, "ISKLd:u:h");
+		c = getopt(argc, argv, "ISKLd:u:hV-:");
 		if (c == -1)
 			break;
 
@@ -387,6 +393,24 @@
 			hbo->action = HB_ACTION_USAGE;
 			break;
 
+		case 'V':
+			hbo->action = HB_ACTION_VERSION;
+			break;
+
+		case '-':
+			if (!strcmp(optarg, "version"))
+				hbo->action = HB_ACTION_VERSION;
+			else if (!strcmp(optarg, "help"))
+				hbo->action = HB_ACTION_USAGE;
+			else
+			{
+				fprintf(stderr,
+					"%s: Invalid option: \'--%s\'\n",
+					progname, optarg);
+				ret = -1;
+			}
+			break;
+
 		case 'K':
 			hbo->action = HB_ACTION_STOP;
 			break;
@@ -512,6 +536,11 @@
 		goto bail;
 	}
 
+	if (hbo.action == HB_ACTION_VERSION) {
+		print_version();
+		goto bail;
+	}
+
 	if (hbo.action == HB_ACTION_LIST) {
 		ret = run_list(&hbo);
 		goto bail;
@@ -543,6 +572,11 @@
 		print_usage(0);
 		break;
 
+	case HB_ACTION_VERSION:
+		ret = 0;
+		print_version();
+		break;
+
 	case HB_ACTION_START:
 		err = start_heartbeat(&hbo);
 		if (err) {



More information about the Ocfs2-tools-commits mailing list