ctdb: Accept the key in hex format for the pstore command
authorChristof Schmitt <cs@samba.org>
Thu, 2 Jul 2015 20:06:32 +0000 (13:06 -0700)
committerJeremy Allison <jra@samba.org>
Mon, 6 Jul 2015 21:23:22 +0000 (23:23 +0200)
This follows the same pattern as the tstore command, and it allows
specifying key strings with a trailing \0 character.

Signed-off-by: Christof Schmitt <cs@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
Autobuild-User(master): Jeremy Allison <jra@samba.org>
Autobuild-Date(master): Mon Jul  6 23:23:22 CEST 2015 on sn-devel-104

ctdb/tools/ctdb.c

index 9b7fb11831eaf91372ecf8ca8b0d6be6a69cf474..91ada44a28b65352e88e6b428eb0dceaefd6a5f8 100644 (file)
@@ -4231,8 +4231,17 @@ static int control_pstore(struct ctdb_context *ctdb, int argc, const char **argv
                return -1;
        }
 
-       key.dptr  = discard_const(argv[1]);
-       key.dsize = strlen(argv[1]);
+       if (!strncmp(argv[1], "0x", 2)) {
+               key = hextodata(tmp_ctx, argv[1] + 2);
+               if (key.dsize == 0) {
+                       printf("Failed to convert \"%s\" into a TDB_DATA\n", argv[1]);
+                       return -1;
+               }
+       } else {
+               key.dptr  = discard_const(argv[1]);
+               key.dsize = strlen(argv[1]);
+       }
+
        ret = ctdb_transaction_store(h, key, data);
        if (ret != 0) {
                DEBUG(DEBUG_ERR,("Failed to store record\n"));