From eba05f308a6e1014d8551cd34d4dc44c609928e0 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Mon, 14 Feb 2022 14:00:14 +0100 Subject: [PATCH] lsipc: add -y,--shell Signed-off-by: Karel Zak --- sys-utils/lsipc.1.adoc | 5 ++++- sys-utils/lsipc.c | 11 ++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/sys-utils/lsipc.1.adoc b/sys-utils/lsipc.1.adoc index fdf29ec27..3ee790e21 100644 --- a/sys-utils/lsipc.1.adoc +++ b/sys-utils/lsipc.1.adoc @@ -45,7 +45,7 @@ Write information about active semaphore sets. Show creator and owner. *-e*, *--export*:: -Produce output in the form of key="value" pairs. All potentially unsafe value characters are hex-escaped (\x). The key (variable name) will be modified to contain only characters allowed for a shell variable identifiers, for example, USE_PCT instead of USE%. +Produce output in the form of key="value" pairs. All potentially unsafe value characters are hex-escaped (\x). See also option *--shell*. *-J*, *--json*:: Use the JSON output format. @@ -80,6 +80,9 @@ Display dates in short, full or iso format. The default is short, this time form *-P*, *--numeric-perms*:: Print numeric permissions in PERMS column. +*-y*, *--shell*:: +The column name will be modified to contain only characters allowed for shell variable identifiers. This is usable, for example, with *--export*. Note that this feature has been automatically enabled for *--export* in version 2.37, but due to compatibility issues, now it's necessary to request this behavior by *--shell*. + == EXIT STATUS 0:: diff --git a/sys-utils/lsipc.c b/sys-utils/lsipc.c index d209f4507..0f3cd94bb 100644 --- a/sys-utils/lsipc.c +++ b/sys-utils/lsipc.c @@ -129,6 +129,7 @@ struct lsipc_control { int outmode; unsigned int noheadings : 1, /* don't print header line */ notrunc : 1, /* don't truncate columns */ + shellvar : 1, /* use shell compatible colum names */ bytes : 1, /* SIZE in bytes */ numperms : 1, /* numeric permissions */ time_mode : 2; @@ -315,6 +316,8 @@ static void __attribute__((__noreturn__)) usage(void) fputs(_(" -P, --numeric-perms print numeric permissions (PERMS column)\n"), out); fputs(_(" -r, --raw display in raw mode\n"), out); fputs(_(" -t, --time show attach, detach and change times\n"), out); + fputs(_(" -y, --shell use column names to be usable as shell variable identifiers\n"), out); + fputs(USAGE_SEPARATOR, out); printf(USAGE_HELP_OPTIONS(26)); @@ -352,6 +355,8 @@ static struct libscols_table *new_table(struct lsipc_control *ctl) if (ctl->noheadings) scols_table_enable_noheadings(table, 1); + if (ctl->shellvar) + scols_table_enable_shellvar(table, 1); switch(ctl->outmode) { case OUT_NEWLINE: @@ -1132,6 +1137,7 @@ int main(int argc, char *argv[]) { "time", no_argument, NULL, 't' }, { "time-format", required_argument, NULL, OPT_TIME_FMT }, { "version", no_argument, NULL, 'V' }, + { "shell", no_argument, NULL, 'y' }, {NULL, 0, NULL, 0} }; @@ -1153,7 +1159,7 @@ int main(int argc, char *argv[]) scols_init_debug(0); - while ((opt = getopt_long(argc, argv, "bceghi:Jlmno:PqrstV", longopts, NULL)) != -1) { + while ((opt = getopt_long(argc, argv, "bceghi:Jlmno:PqrstVy", longopts, NULL)) != -1) { err_exclusive_options(opt, longopts, excl, excl_st); @@ -1242,6 +1248,9 @@ int main(int argc, char *argv[]) case 'c': show_creat = 1; break; + case 'y': + ctl->shellvar = 1; + break; case 'h': usage();