summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarel Zak2015-07-23 11:09:49 +0200
committerKarel Zak2015-07-23 11:09:49 +0200
commit2916afa3f510182987f88c17bade5dffb4aaf0b8 (patch)
tree43297888b518246861c43d9b3bbaabb84a8156d9
parentlsipc: the default --global is mutually exclusive with -c --id and -t (diff)
downloadkernel-qcow2-util-linux-2916afa3f510182987f88c17bade5dffb4aaf0b8.tar.gz
kernel-qcow2-util-linux-2916afa3f510182987f88c17bade5dffb4aaf0b8.tar.xz
kernel-qcow2-util-linux-2916afa3f510182987f88c17bade5dffb4aaf0b8.zip
lsipc: make --id usable with all output formats and with -o
This patch allows to use things like: # lsipc -m --id 47611910 -o COMMAND,SIZE,KEY --json or # lsipc -m --id 47611910 -o SIZE --bytes --noheadings --raw to get just one value for the resource. Signed-off-by: Karel Zak <kzak@redhat.com>
-rw-r--r--sys-utils/lsipc.111
-rw-r--r--sys-utils/lsipc.c28
2 files changed, 23 insertions, 16 deletions
diff --git a/sys-utils/lsipc.1 b/sys-utils/lsipc.1
index e1e12c103..5ef714cf2 100644
--- a/sys-utils/lsipc.1
+++ b/sys-utils/lsipc.1
@@ -19,6 +19,8 @@ This option needs to be combined with one of the three resource options:
.BR \-m ,
.BR \-q " or"
.BR \-s .
+The default \fB\-\-id\fR output format is possible to override by
+the \fB\-\-list \-\-raw \-\-json\fR or \fB\-\-export\fR options.
.TP
\fB\-g\fR, \fB\-\-global\fR
Show system-wide usage and limits for a single IPC type.
@@ -48,15 +50,15 @@ Write information about active semaphore sets.
\fB\-c\fR, \fB\-\-creator\fR
Show creator and owner.
.TP
-\fB\-\-colon\-separate\fR
-Separate info about each user with a colon instead of a newline.
-.TP
\fB\-e\fR, \fB\-\-export\fR
Output data in the format of NAME=VALUE.
.TP
\fB\-J\fR, \fB\-\-json\fR
Use the JSON output format.
.TP
+\fB\-l\fR, \fB\-\-list\fR
+Use the list output format. This is the default except for \fB\-\-id\fR.
+.TP
\fB\-n\fR, \fB\-\-newline\fR
Display each piece of information on a separate line.
.TP
@@ -94,9 +96,6 @@ operation on semaphores.
\fB\-\-time\-format\fR \fItype\fP
Display dates in short, full or iso format. The default is short, this time
format is designed to be space efficient and human readable.
-.TP
-\fB\-z\fR, \fB\-\-print0\fR
-Delimit user entries with a nul character, instead of a newline.
.SH EXIT STATUS
.TP
diff --git a/sys-utils/lsipc.c b/sys-utils/lsipc.c
index 8912c8da4..045c0e8c1 100644
--- a/sys-utils/lsipc.c
+++ b/sys-utils/lsipc.c
@@ -121,7 +121,8 @@ enum {
OUT_NEWLINE,
OUT_RAW,
OUT_JSON,
- OUT_PRETTY
+ OUT_PRETTY,
+ OUT_LIST
};
struct lsipc_control {
@@ -279,6 +280,7 @@ static void __attribute__ ((__noreturn__)) usage(FILE * out)
fputs(_(" -e, --export display in an export-able output format\n"), out);
fputs(_(" -J, --json use the JSON output format\n"), out);
fputs(_(" -n, --newline display each piece of information on a new line\n"), out);
+ fputs(_(" -l, --list force list output format (for example with --id)\n"), out);
fputs(_(" -o, --output[=<list>] define the columns to output\n"), out);
fputs(_(" -P, --numeric-perms print numeric permissions (PERMS column)\n"), out);
fputs(_(" -r, --raw display in raw mode\n"), out);
@@ -1124,6 +1126,7 @@ int main(int argc, char *argv[])
{ "help", no_argument, 0, 'h' },
{ "id", required_argument, 0, 'i' },
{ "json", no_argument, 0, 'J' },
+ { "list", no_argument, 0, 'l' },
{ "newline", no_argument, 0, 'n' },
{ "noheadings", no_argument, 0, OPT_NOHEAD },
{ "notruncate", no_argument, 0, OPT_NOTRUNC },
@@ -1141,10 +1144,9 @@ int main(int argc, char *argv[])
};
static const ul_excl_t excl[] = { /* rows and cols in ASCII order */
- { 'J', 'e', 'n', 'r' },
- { 'J', 'i' },
- { 'c', 'g', 'i', 't' },
- { 'c', 'i', 'o', 't' },
+ { 'J', 'e', 'l', 'n', 'r' },
+ { 'g', 'i' },
+ { 'c', 'o', 't' },
{ 'm', 'q', 's' },
{ 0 }
};
@@ -1159,7 +1161,7 @@ int main(int argc, char *argv[])
scols_init_debug(0);
- while ((opt = getopt_long(argc, argv, "bceghi:Jmno:PqrstuV", longopts, NULL)) != -1) {
+ while ((opt = getopt_long(argc, argv, "bceghi:Jlmno:PqrstuV", longopts, NULL)) != -1) {
err_exclusive_options(opt, longopts, excl, excl_st);
@@ -1169,7 +1171,6 @@ int main(int argc, char *argv[])
break;
case 'i':
id = strtos32_or_err(optarg, _("failed to parse IPC identifier"));
- ctl->outmode = OUT_PRETTY;
break;
case 'e':
ctl->outmode = OUT_EXPORT;
@@ -1182,7 +1183,7 @@ int main(int argc, char *argv[])
break;
case 'g':
global = 1;
- break;
+ break;
case 'q':
msg = 1;
add_column(columns, ncolumns++, COL_KEY);
@@ -1196,6 +1197,9 @@ int main(int argc, char *argv[])
LOWER = COLDESC_IDX_MSG_FIRST;
UPPER = COLDESC_IDX_MSG_LAST;
break;
+ case 'l':
+ ctl->outmode = OUT_LIST;
+ break;
case 'm':
shm = 1;
add_column(columns, ncolumns++, COL_KEY);
@@ -1259,7 +1263,7 @@ int main(int argc, char *argv[])
/* default is global */
if (msg + shm + sem == 0) {
msg = shm = sem = global = 1;
- if (show_time || show_creat || id)
+ if (show_time || show_creat || id != -1)
errx(EXIT_FAILURE, _("the --global is mutually exclusive with --creator, --id and --time"));
}
if (global) {
@@ -1272,10 +1276,14 @@ int main(int argc, char *argv[])
UPPER = COLDESC_IDX_SUM_LAST;
}
+ /* default to pretty-print if --id specified */
+ if (id != -1 && !ctl->outmode)
+ ctl->outmode = OUT_PRETTY;
+
if (!ctl->time_mode)
ctl->time_mode = ctl->outmode == OUT_PRETTY ? TIME_FULL : TIME_SHORT;
- if (ctl->outmode == OUT_PRETTY && !optarg) {
+ if (ctl->outmode == OUT_PRETTY && !(optarg || show_creat || show_time)) {
/* all columns for lsipc --<RESOURCE> --id <ID> */
for (ncolumns = 0, i = 0; i < ARRAY_SIZE(coldescs); i++)
columns[ncolumns++] = i;