summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Rajnoha <prajnoha@redhat.com>2015-10-20 16:36:11 +0200
committerPeter Rajnoha <prajnoha@redhat.com>2015-10-30 15:47:56 +0100
commite149fe7fdfd22b496bbd870d19412b0e9f090149 (patch)
tree1599d8066159d5f7b82a88fbf38703dd609717b9
parent77605457e7cf550364355b03cb5544b57d3c046d (diff)
downloadlvm2-e149fe7fdfd22b496bbd870d19412b0e9f090149.tar.gz
refactor: move code detecting report options to a separate function
-rw-r--r--tools/reporter.c46
1 files changed, 27 insertions, 19 deletions
diff --git a/tools/reporter.c b/tools/reporter.c
index 6c937394a..4cf099bee 100644
--- a/tools/reporter.c
+++ b/tools/reporter.c
@@ -604,13 +604,35 @@ static void _check_pv_list(struct cmd_context *cmd, int argc, char **argv,
}
}
+static int _get_report_options(struct cmd_context *cmd, const char **options)
+{
+ const char *opts;
+ char *str;
+
+ opts = arg_str_value(cmd, options_ARG, "");
+ if (!opts || !*opts) {
+ log_error("Invalid options string: %s", opts);
+ return EINVALID_CMD_LINE;
+ }
+ if (*opts == '+') {
+ if (!(str = dm_pool_alloc(cmd->mem,
+ strlen(*options) + strlen(opts) + 1))) {
+ log_error("options string allocation failed");
+ return ECMD_FAILED;
+ }
+ (void) sprintf(str, "%s,%s", *options, opts + 1);
+ *options = str;
+ } else
+ *options = opts;
+
+ return ECMD_PROCESSED;
+}
+
static int _report(struct cmd_context *cmd, int argc, char **argv,
report_type_t report_type)
{
void *report_handle;
struct processing_handle handle = {0};
- const char *opts;
- char *str;
const char *keys = NULL, *options = NULL, *selection = NULL, *separator;
int r = ECMD_PROCESSED;
int aligned, buffered, headings, field_prefixes, quoted;
@@ -689,23 +711,9 @@ static int _report(struct cmd_context *cmd, int argc, char **argv,
}
/* If -o supplied use it, else use default for report_type */
- if (arg_count(cmd, options_ARG)) {
- opts = arg_str_value(cmd, options_ARG, "");
- if (!opts || !*opts) {
- log_error("Invalid options string: %s", opts);
- return EINVALID_CMD_LINE;
- }
- if (*opts == '+') {
- if (!(str = dm_pool_alloc(cmd->mem,
- strlen(options) + strlen(opts) + 1))) {
- log_error("options string allocation failed");
- return ECMD_FAILED;
- }
- (void) sprintf(str, "%s,%s", options, opts + 1);
- options = str;
- } else
- options = opts;
- }
+ if (arg_count(cmd, options_ARG) &&
+ ((r = _get_report_options(cmd, &options) != ECMD_PROCESSED)))
+ return r;
/* -O overrides default sort settings */
keys = arg_str_value(cmd, sort_ARG, keys);