summaryrefslogtreecommitdiffstats
path: root/sys-utils/ipcs.c
diff options
context:
space:
mode:
authorBenno Schulenberg2013-01-27 13:09:51 +0100
committerKarel Zak2013-02-06 10:54:39 +0100
commitfa03fa051a2ae0db751fd3478aaee45e9ed0bcb5 (patch)
treeb29a13da5721857f2522aafff0eeb124d069aa89 /sys-utils/ipcs.c
parentsetpriv: move paths to pathnames.h (diff)
downloadkernel-qcow2-util-linux-fa03fa051a2ae0db751fd3478aaee45e9ed0bcb5.tar.gz
kernel-qcow2-util-linux-fa03fa051a2ae0db751fd3478aaee45e9ed0bcb5.tar.xz
kernel-qcow2-util-linux-fa03fa051a2ae0db751fd3478aaee45e9ed0bcb5.zip
ipcs: report an error when -i is used with multiple resources
Also put everything in POSIX order: queues, memory, sempahores. Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
Diffstat (limited to 'sys-utils/ipcs.c')
-rw-r--r--sys-utils/ipcs.c38
1 files changed, 19 insertions, 19 deletions
diff --git a/sys-utils/ipcs.c b/sys-utils/ipcs.c
index 1e1b02274..352732a3d 100644
--- a/sys-utils/ipcs.c
+++ b/sys-utils/ipcs.c
@@ -77,13 +77,13 @@ static void __attribute__ ((__noreturn__)) usage(FILE * out)
int main (int argc, char **argv)
{
- int opt, msg = 0, sem = 0, shm = 0, id=0, print=0;
+ int opt, msg = 0, shm = 0, sem = 0, id = 0, specific = 0;
char format = NOTSPECIFIED;
int unit = IPC_UNIT_DEFAULT;
static const struct option longopts[] = {
{"id", required_argument, NULL, 'i'},
- {"shmems", no_argument, NULL, 'm'},
{"queues", no_argument, NULL, 'q'},
+ {"shmems", no_argument, NULL, 'm'},
{"semaphores", no_argument, NULL, 's'},
{"all", no_argument, NULL, 'a'},
{"time", no_argument, NULL, 't'},
@@ -97,7 +97,7 @@ int main (int argc, char **argv)
{"help", no_argument, NULL, 'h'},
{NULL, 0, NULL, 0}
};
- char options[] = "i:mqsatpclubVh";
+ char options[] = "i:qmsatpclubVh";
setlocale(LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
@@ -108,7 +108,7 @@ int main (int argc, char **argv)
switch (opt) {
case 'i':
id = atoi (optarg);
- print = 1;
+ specific = 1;
break;
case 'a':
msg = shm = sem = 1;
@@ -116,12 +116,12 @@ int main (int argc, char **argv)
case 'q':
msg = 1;
break;
- case 's':
- sem = 1;
- break;
case 'm':
shm = 1;
break;
+ case 's':
+ sem = 1;
+ break;
case 't':
format = TIME;
break;
@@ -153,20 +153,24 @@ int main (int argc, char **argv)
}
}
- if (print) {
+ if (specific && (msg + shm + sem != 1))
+ errx (EXIT_FAILURE,
+ _("when using an ID, a single resource must be specified"));
+ if (specific) {
+ if (msg)
+ print_msg (id, unit);
if (shm)
print_shm (id, unit);
if (sem)
print_sem (id);
- if (msg)
- print_msg (id, unit);
- if (!shm && !sem && !msg )
- usage (stderr);
} else {
- if ( !shm && !msg && !sem)
- msg = sem = shm = 1;
+ if (!msg && !shm && !sem)
+ msg = shm = sem = 1;
printf ("\n");
-
+ if (msg) {
+ do_msg (format, unit);
+ printf ("\n");
+ }
if (shm) {
do_shm (format, unit);
printf ("\n");
@@ -175,10 +179,6 @@ int main (int argc, char **argv)
do_sem (format);
printf ("\n");
}
- if (msg) {
- do_msg (format, unit);
- printf ("\n");
- }
}
return EXIT_SUCCESS;
}