4
0
Эх сурвалжийг харах

corosync-objctl: Option to display binary data

Signed-off-by: Jan Friesse <jfriesse@redhat.com>
Reviewed-by: Steven Dake <sdake@redhat.com>
Jan Friesse 14 жил өмнө
parent
commit
801717e463

+ 4 - 1
man/corosync-objctl.8

@@ -35,7 +35,7 @@
 .SH NAME
 corosync-objctl \- Configure objects in the Object Database
 .SH SYNOPSIS
-.B "corosync-objctl [\-c|\-w|\-d|\-a|\-t\-h] <OBJECT-SPEC>..."
+.B "corosync-objctl [\-b] [\-c|\-w|\-d|\-a|\-t\-h] <OBJECT-SPEC>..."
 .SH DESCRIPTION
 .B corosync-objctl
 is used to configure objects within the object database at runtime.
@@ -74,6 +74,9 @@ they are printed out. this is kind of like a "tail -f" for the object database.
 .TP
 .B -h
 Print basic usage.
+.TP
+.B -b
+Display binary values in BASH backslash escape sequences format.
 .SH EXAMPLES
 .TP
 Print the objOne object (shouldn't exist yet).

+ 33 - 4
tools/corosync-objctl.c

@@ -103,8 +103,29 @@ static confdb_callbacks_t callbacks = {
 };
 
 static int debug = 0;
+static int show_binary = 0;
 static int action;
 
+static void print_binary_key (char *value, size_t value_len)
+{
+	size_t i;
+	char c;
+
+	for (i = 0; i < value_len; i++) {
+		c = value[i];
+		if (c >= ' ' && c < 0x7f && c != '\\') {
+			fputc (c, stdout);
+		} else {
+			if (c == '\\') {
+				printf ("\\\\");
+			} else {
+				printf ("\\x%02X", c);
+			}
+		}
+	}
+	printf ("\n");
+}
+
 static void print_key (char *key_name, void *value, size_t value_len, confdb_value_types_t type)
 {
 	switch (type) {
@@ -145,7 +166,12 @@ static void print_key (char *key_name, void *value, size_t value_len, confdb_val
 			break;
 		default:
 		case CONFDB_VALUETYPE_ANY:
-			printf ("%s=**binary**(%d)\n", key_name, type);
+			if (!show_binary) {
+				printf ("%s=**binary**(%d)\n", key_name, type);
+			} else {
+				printf ("%s=", key_name);
+				print_binary_key ((char *)value, value_len);
+			}
 			break;
 	}
 }
@@ -312,13 +338,13 @@ static int print_all(void)
 static int print_help(void)
 {
 	printf("\n");
-	printf ("usage:  corosync-objctl object%ckey ...                    Print an object\n", SEPERATOR);
+	printf ("usage:  corosync-objctl [-b] object%ckey ...               Print an object\n", SEPERATOR);
 	printf ("        corosync-objctl -c object%cchild_obj ...           Create Object\n", SEPERATOR);
 	printf ("        corosync-objctl -d object%cchild_obj ...           Delete object\n", SEPERATOR);
 	printf ("        corosync-objctl -w object%cchild_obj.key=value ... Create a key\n", SEPERATOR);
 	printf ("        corosync-objctl -n object%cchild_obj.key=value ... Create a new object with the key\n", SEPERATOR);
 	printf ("        corosync-objctl -t object%cchild_obj ...           Track changes\n", SEPERATOR);
-	printf ("        corosync-objctl -a                                Print all objects\n");
+	printf ("        corosync-objctl [-b] -a                           Print all objects\n");
 	printf ("        corosync-objctl -p <filename> Load in config from the specified file.\n");
 	printf("\n");
 	return 0;
@@ -802,7 +828,7 @@ int main (int argc, char *argv[]) {
 	action = ACTION_READ;
 
 	for (;;){
-		c = getopt (argc,argv,"hawncvdtp:");
+		c = getopt (argc,argv,"habwncvdtp:");
 		if (c==-1) {
 			break;
 		}
@@ -816,6 +842,9 @@ int main (int argc, char *argv[]) {
 			case 'a':
 				action = ACTION_PRINT_ALL;
 				break;
+			case 'b':
+				show_binary++;
+				break;
 			case 'p':
 				return read_in_config_file (optarg);
 				break;