TFETCH add verbose flag to print also the record ltdb heaer
authorRonnie Sahlberg <ronniesahlberg@gmail.com>
Mon, 6 Feb 2012 23:53:49 +0000 (10:53 +1100)
committerRonnie Sahlberg <ronniesahlberg@gmail.com>
Mon, 6 Feb 2012 23:53:49 +0000 (10:53 +1100)
tools/ctdb.c

index 8ef869b3eb9e838a2a06a53e10b9d4a719ed85dd..baf5d24535a3d19627edd832f0a8f28cf1e7e164 100644 (file)
@@ -3487,14 +3487,14 @@ static int control_tfetch(struct ctdb_context *ctdb, int argc, const char **argv
 
        tdb = tdb_open(tdb_file, 0, 0, O_RDONLY, 0);
        if (tdb == NULL) {
-               fprintf(stderr, "Failed to open TDB file %s\n", tdb_file);
+               printf("Failed to open TDB file %s\n", tdb_file);
                return -1;
        }
 
        if (!strncmp(argv[1], "0x", 2)) {
                key = hextodata(tmp_ctx, argv[1] + 2);
                if (key.dsize == 0) {
-                       fprintf(stderr, "Failed to convert \"%s\" into a TDB_DATA\n", argv[1]);
+                       printf("Failed to convert \"%s\" into a TDB_DATA\n", argv[1]);
                        return -1;
                }
        } else {
@@ -3503,7 +3503,7 @@ static int control_tfetch(struct ctdb_context *ctdb, int argc, const char **argv
        }
        data = tdb_fetch(tdb, key);
        if (data.dptr == NULL || data.dsize < sizeof(struct ctdb_ltdb_header)) {
-               fprintf(stderr, "Failed to read record %s from tdb %s\n", argv[1], tdb_file);
+               printf("Failed to read record %s from tdb %s\n", argv[1], tdb_file);
                tdb_close(tdb);
                return -1;
        }
@@ -3516,10 +3516,18 @@ static int control_tfetch(struct ctdb_context *ctdb, int argc, const char **argv
                        printf("Failed to open output file %s\n", argv[2]);
                        return -1;
                }
-               write(fd, data.dptr+sizeof(struct ctdb_ltdb_header), data.dsize-sizeof(struct ctdb_ltdb_header));
+               if (options.verbose){
+                       write(fd, data.dptr, data.dsize);
+               } else {
+                       write(fd, data.dptr+sizeof(struct ctdb_ltdb_header), data.dsize-sizeof(struct ctdb_ltdb_header));
+               }
                close(fd);
        } else {
-               write(1, data.dptr+sizeof(struct ctdb_ltdb_header), data.dsize-sizeof(struct ctdb_ltdb_header));
+               if (options.verbose){
+                       write(1, data.dptr, data.dsize);
+               } else {
+                       write(1, data.dptr+sizeof(struct ctdb_ltdb_header), data.dsize-sizeof(struct ctdb_ltdb_header));
+               }
        }
 
        talloc_free(tmp_ctx);