From: Karel Zak Date: Mon, 9 Dec 2024 11:20:55 +0000 (+0100) Subject: lscpu: add --raw command line option X-Git-Tag: v2.42-start~123^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1fc0e152664bee7082e9dd96eb4ec07e7b39cac9;p=thirdparty%2Futil-linux.git lscpu: add --raw command line option In certain situations, data alignment is not desired. Addresses: https://github.com/util-linux/util-linux/pull/3255 Signed-off-by: Karel Zak --- diff --git a/bash-completion/lscpu b/bash-completion/lscpu index d79c4c9a6..fc55a1922 100644 --- a/bash-completion/lscpu +++ b/bash-completion/lscpu @@ -40,6 +40,7 @@ _lscpu_module() --hex --physical --output-all + --raw --help --version" COMPREPLY=( $(compgen -W "${OPTS_ALL[*]}" -- $cur) ) diff --git a/sys-utils/lscpu.1.adoc b/sys-utils/lscpu.1.adoc index 26c078bcd..60c769c04 100644 --- a/sys-utils/lscpu.1.adoc +++ b/sys-utils/lscpu.1.adoc @@ -78,6 +78,9 @@ When specifying the _list_ argument, the string of option, equal sign (=), and _ + The default list of columns may be extended if list is specified in the format +list (e.g., lscpu -p=+MHZ). +*-r*, *--raw*:: +Produce output in its raw format. This option is only applicable for the *--extended*, *--parse*, and *--caches* outputs. + *-s*, *--sysroot* _directory_:: Gather CPU data for a Linux instance other than the instance from which the *lscpu* command is issued. The specified _directory_ is the system root of the Linux instance to be inspected. diff --git a/sys-utils/lscpu.c b/sys-utils/lscpu.c index 17eaea9f4..21c5a99cf 100644 --- a/sys-utils/lscpu.c +++ b/sys-utils/lscpu.c @@ -598,6 +598,8 @@ static void print_caches_readable(struct lscpu_cxt *cxt, int cols[], size_t ncol scols_table_enable_json(tb, 1); scols_table_set_name(tb, "caches"); } + if (cxt->raw) + scols_table_enable_raw(tb, 1); for (i = 0; i < ncols; i++) { struct lscpu_coldesc *cd = &coldescs_cache[cols[i]]; @@ -753,6 +755,8 @@ static void print_cpus_readable(struct lscpu_cxt *cxt, int cols[], size_t ncols) scols_table_enable_json(tb, 1); scols_table_set_name(tb, "cpus"); } + if (cxt->raw) + scols_table_enable_raw(tb, 1); for (i = 0; i < ncols; i++) { data = get_cell_header(cxt, cols[i], buf, sizeof(buf)); @@ -1183,6 +1187,7 @@ static void __attribute__((__noreturn__)) usage(void) fputs(_(" -J, --json use JSON for default or extended format\n"), out); fputs(_(" -e, --extended[=] print out an extended readable format\n"), out); fputs(_(" -p, --parse[=] print out a parsable format\n"), out); + fputs(_(" -r, --raw use raw output format (for -e, -p and -C)\n"), out); fputs(_(" -s, --sysroot use specified directory as system root\n"), out); fputs(_(" -x, --hex print hexadecimal masks rather than lists of CPUs\n"), out); fputs(_(" -y, --physical print physical instead of logical IDs\n"), out); @@ -1226,6 +1231,7 @@ int main(int argc, char *argv[]) { "extended", optional_argument, NULL, 'e' }, { "json", no_argument, NULL, 'J' }, { "parse", optional_argument, NULL, 'p' }, + { "raw", no_argument, NULL, 'r' }, { "sysroot", required_argument, NULL, 's' }, { "physical", no_argument, NULL, 'y' }, { "hex", no_argument, NULL, 'x' }, @@ -1249,7 +1255,7 @@ int main(int argc, char *argv[]) cxt = lscpu_new_context(); - while ((c = getopt_long(argc, argv, "aBbC::ce::hJp::s:xyV", longopts, NULL)) != -1) { + while ((c = getopt_long(argc, argv, "aBbC::ce::hJp::rs:xyV", longopts, NULL)) != -1) { err_exclusive_options(c, longopts, excl, excl_st); @@ -1289,6 +1295,9 @@ int main(int argc, char *argv[]) } cxt->mode = c == 'p' ? LSCPU_OUTPUT_PARSABLE : LSCPU_OUTPUT_READABLE; break; + case 'r': + cxt->raw = 1; + break; case 's': cxt->prefix = optarg; cxt->noalive = 1; diff --git a/sys-utils/lscpu.h b/sys-utils/lscpu.h index 4d394a81d..062c55c8a 100644 --- a/sys-utils/lscpu.h +++ b/sys-utils/lscpu.h @@ -260,6 +260,7 @@ struct lscpu_cxt { show_compatible : 1, hex : 1, json : 1, + raw : 1, bytes : 1; int is_cluster; /* For aarch64 if the machine doesn't have ACPI PPTT */