@@ -50,7 +50,6 @@ static struct {
};
static int did_fail;
-static int jflag = JSON_C_TO_STRING_PRETTY;
#define fail(fmt, ...) \
do { \
@@ -130,9 +129,9 @@ int cmd_list(int argc, const char **argv, void *ctx)
}
if (jregions)
- util_display_json_array(stdout, jregions, jflag);
+ util_display_json_array(stdout, jregions);
else if (jdevs)
- util_display_json_array(stdout, jdevs, jflag);
+ util_display_json_array(stdout, jdevs);
if (did_fail)
return -ENOMEM;
@@ -88,8 +88,7 @@ static int bus_action(int argc, const char **argv, const char *usage,
}
if (success)
- util_display_json_array(stdout, jbuses,
- JSON_C_TO_STRING_PRETTY);
+ util_display_json_array(stdout, jbuses);
else
json_object_put(jbuses);
@@ -1081,8 +1081,7 @@ static int dimm_action(int argc, const char **argv, void *ctx,
}
if (actx.jdimms)
- util_display_json_array(actx.f_out, actx.jdimms,
- JSON_C_TO_STRING_PRETTY);
+ util_display_json_array(actx.f_out, actx.jdimms);
if (actx.f_out != stdout)
fclose(actx.f_out);
@@ -375,8 +375,7 @@ static int dimm_inject_smart(struct ndctl_dimm *dimm)
jhealth = util_dimm_health_to_json(dimm);
if (jhealth) {
json_object_object_add(jdimm, "health", jhealth);
- util_display_json_array(stdout, jdimms,
- JSON_C_TO_STRING_PRETTY);
+ util_display_json_array(stdout, jdimms);
}
}
out:
@@ -56,7 +56,6 @@ static unsigned long listopts_to_flags(void)
struct util_filter_params param;
static int did_fail;
-static int jflag = JSON_C_TO_STRING_PRETTY;
#define fail(fmt, ...) \
do { \
@@ -380,7 +379,7 @@ static int list_display(struct list_filter_arg *lfa)
struct json_object *jbuses = lfa->jbuses;
if (jbuses)
- util_display_json_array(stdout, jbuses, jflag);
+ util_display_json_array(stdout, jbuses);
else if ((!!jdimms + !!jregions + !!jnamespaces) > 1) {
struct json_object *jplatform = json_object_new_object();
@@ -397,14 +396,14 @@ static int list_display(struct list_filter_arg *lfa)
json_object_object_add(jplatform, "namespaces",
jnamespaces);
printf("%s\n", json_object_to_json_string_ext(jplatform,
- jflag));
+ JSON_C_TO_STRING_PRETTY));
json_object_put(jplatform);
} else if (jdimms)
- util_display_json_array(stdout, jdimms, jflag);
+ util_display_json_array(stdout, jdimms);
else if (jregions)
- util_display_json_array(stdout, jregions, jflag);
+ util_display_json_array(stdout, jregions);
else if (jnamespaces)
- util_display_json_array(stdout, jnamespaces, jflag);
+ util_display_json_array(stdout, jnamespaces);
return 0;
}
@@ -105,9 +105,10 @@ struct json_object *util_json_object_hex(unsigned long long val,
return jobj;
}
-void util_display_json_array(FILE *f_out, struct json_object *jarray, int jflag)
+void util_display_json_array(FILE *f_out, struct json_object *jarray)
{
int len = json_object_array_length(jarray);
+ int jflag = JSON_C_TO_STRING_PRETTY;
if (json_object_array_length(jarray) > 1)
fprintf(f_out, "%s\n", json_object_to_json_string_ext(jarray, jflag));
@@ -26,7 +26,7 @@ enum util_json_flags {
};
struct json_object;
-void util_display_json_array(FILE *f_out, struct json_object *jarray, int jflag);
+void util_display_json_array(FILE *f_out, struct json_object *jarray);
struct json_object *util_bus_to_json(struct ndctl_bus *bus);
struct json_object *util_dimm_to_json(struct ndctl_dimm *dimm,
unsigned long flags);
json_object_to_json_string_ext()'s second argument is a flags field which we always want to be JSON_C_TO_STRING_PRETTY. We were going to a lot of trouble for this, though. We had multiple variables set to be this one flag and util_display_json_array() took it as an argument, even though it never varied. Instead, just pass in the necessary flag when calling json_object_to_json_string_ext(), removing the local variables and the extra argument to util_display_json_array(). Signed-off-by: Ross Zwisler <ross.zwisler@linux.intel.com> --- daxctl/list.c | 5 ++--- ndctl/bus.c | 3 +-- ndctl/dimm.c | 3 +-- ndctl/inject-smart.c | 3 +-- ndctl/list.c | 11 +++++------ util/json.c | 3 ++- util/json.h | 2 +- 7 files changed, 13 insertions(+), 17 deletions(-)