mirror of
https://github.com/ibm-s390-linux/s390-tools.git
synced 2026-08-05 02:14:52 +00:00
libutil: Make formatted meta-data configurable
Output generated using libutil's util_fmt_*() functions contains meta-data such as hostname and time of invocation. When writing test cases that compare expected and actual tool output, this run-time variable information needs to be filtered out, resulting in increased complexity. To address this, add a global option to suppress meta-data output via environment variable FMT_NOMETA. If set to '1', no meta-data will be generated. Example: $ FMT_NOMETA=1 chpstat --format json Reviewed-by: Steffen Eiden <seiden@linux.ibm.com> Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com> Signed-off-by: Peter Oberparleiter <oberpar@linux.ibm.com> Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
This commit is contained in:
committed by
Steffen Eiden
parent
7e31c425c9
commit
f6e932e0fd
@@ -710,6 +710,14 @@ static void csv_map(struct obj_t *UNUSED(obj), unsigned int mflags,
|
||||
free(qval);
|
||||
}
|
||||
|
||||
static bool hide_meta_env(void)
|
||||
{
|
||||
char *v;
|
||||
|
||||
v = secure_getenv("FMT_NOMETA");
|
||||
return (v && strcmp(v, "1") == 0);
|
||||
}
|
||||
|
||||
void util_fmt_init(FILE *fd, enum util_fmt_t type, unsigned int flags,
|
||||
int api_level)
|
||||
{
|
||||
@@ -719,7 +727,7 @@ void util_fmt_init(FILE *fd, enum util_fmt_t type, unsigned int flags,
|
||||
f.fileno = fileno(fd);
|
||||
f.hide_prefix = (flags & FMT_NOPREFIX);
|
||||
f.hide_inval = !(flags & FMT_KEEPINVAL);
|
||||
f.hide_meta = (flags & FMT_NOMETA);
|
||||
f.hide_meta = (flags & FMT_NOMETA) || hide_meta_env();
|
||||
f.quote_all = (flags & FMT_QUOTEALL);
|
||||
f.do_filter = (flags & FMT_FILTER);
|
||||
f.do_warn = (flags & FMT_WARN);
|
||||
|
||||
Reference in New Issue
Block a user