diff options
author | Martin Schwenke <martin@meltin.net> | 2014-11-19 17:15:21 +1100 |
---|---|---|
committer | Martin Schwenke <martins@samba.org> | 2014-12-05 21:02:39 +0100 |
commit | 3b90e45bae555cc4a47fe9958b86628d41084868 (patch) | |
tree | bf0b672c9e21229b4f20edc2337ad4a268d848f6 /ctdb/tools | |
parent | fbacbb9c7868e22c04980af3602bae59dd5fe34d (diff) | |
download | samba-3b90e45bae555cc4a47fe9958b86628d41084868.tar.gz |
ctdb-tools: Add -x option to specify delimiter for machine readable output
To support this, update printm() to replace ':' in format string with
options.machineseparator, which is a string but must contain a single
character.
Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
Diffstat (limited to 'ctdb/tools')
-rw-r--r-- | ctdb/tools/ctdb.c | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/ctdb/tools/ctdb.c b/ctdb/tools/ctdb.c index d886be14ec3..3a1985bf22d 100644 --- a/ctdb/tools/ctdb.c +++ b/ctdb/tools/ctdb.c @@ -43,6 +43,7 @@ static struct { uint32_t pnn; uint32_t *nodes; int machinereadable; + const char *machineseparator; int verbose; int maxruntime; int printemptyrecords; @@ -75,9 +76,18 @@ static int printm(const char *format, ...) { va_list ap; int ret; + size_t len = strlen(format); + char new_format[len+1]; + + strcpy(new_format, format); + + if (options.machineseparator[0] != ':') { + all_string_sub(new_format, + ":", options.machineseparator, len + 1); + } va_start(ap, format); - ret = vprintf(format, ap); + ret = vprintf(new_format, ap); va_end(ap); return ret; @@ -6340,7 +6350,8 @@ static void usage(void) "Usage: ctdb [options] <control>\n" \ "Options:\n" \ " -n <node> choose node number, or 'all' (defaults to local node)\n" -" -Y generate machinereadable output\n" +" -Y generate machine readable output\n" +" -x <char> specify delimiter for machine readable output\n" " -v generate verbose output\n" " -t <timelimit> set timelimit for control in seconds (default %u)\n", options.timelimit); printf("Controls:\n"); @@ -6372,7 +6383,8 @@ int main(int argc, const char *argv[]) POPT_CTDB_CMDLINE { "timelimit", 't', POPT_ARG_INT, &options.timelimit, 0, "timelimit", "integer" }, { "node", 'n', POPT_ARG_STRING, &nodestring, 0, "node", "integer|all" }, - { "machinereadable", 'Y', POPT_ARG_NONE, &options.machinereadable, 0, "enable machinereadable output", NULL }, + { "machinereadable", 'Y', POPT_ARG_NONE, &options.machinereadable, 0, "enable machine readable output", NULL }, + { NULL, 'x', POPT_ARG_STRING, &options.machineseparator, 0, "specify separator for machine readable output", "char" }, { "verbose", 'v', POPT_ARG_NONE, &options.verbose, 0, "enable verbose output", NULL }, { "maxruntime", 'T', POPT_ARG_INT, &options.maxruntime, 0, "die if runtime exceeds this limit (in seconds)", "integer" }, { "print-emptyrecords", 0, POPT_ARG_NONE, &options.printemptyrecords, 0, "print the empty records when dumping databases (catdb, cattdb, dumpdbbackup)", NULL }, @@ -6430,6 +6442,20 @@ int main(int argc, const char *argv[]) } } + if (options.machineseparator != NULL) { + if (strlen(options.machineseparator) != 1) { + printf("Invalid separator \"%s\" - " + "must be single character\n", + options.machineseparator); + exit(1); + } + + /* -x implies -Y */ + options.machinereadable = true; + } else if (options.machinereadable) { + options.machineseparator = ":"; + } + signal(SIGALRM, ctdb_alarm); alarm(options.maxruntime); |