aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--util-linux/ipcrm.c40
1 files changed, 16 insertions, 24 deletions
diff --git a/util-linux/ipcrm.c b/util-linux/ipcrm.c
index c51d33143..fa1159f03 100644
--- a/util-linux/ipcrm.c
+++ b/util-linux/ipcrm.c
@@ -19,15 +19,6 @@
19 19
20//kbuild:lib-$(CONFIG_IPCRM) += ipcrm.o 20//kbuild:lib-$(CONFIG_IPCRM) += ipcrm.o
21 21
22//usage:#define ipcrm_trivial_usage
23//usage: "[-MQS key] [-mqs id]"
24//usage:#define ipcrm_full_usage "\n\n"
25//usage: "Upper-case options MQS remove an object by shmkey value.\n"
26//usage: "Lower-case options remove an object by shmid value.\n"
27//usage: "\n -mM Remove memory segment after last detach"
28//usage: "\n -qQ Remove message queue"
29//usage: "\n -sS Remove semaphore"
30
31#include "libbb.h" 22#include "libbb.h"
32 23
33/* X/OPEN tells us to use <sys/{types,ipc,sem}.h> for semctl() */ 24/* X/OPEN tells us to use <sys/{types,ipc,sem}.h> for semctl() */
@@ -94,6 +85,14 @@ static int remove_ids(type_id type, char **argv)
94} 85}
95#endif /* IPCRM_LEGACY */ 86#endif /* IPCRM_LEGACY */
96 87
88//usage:#define ipcrm_trivial_usage
89//usage: "[-MQS key] [-mqs id]"
90//usage:#define ipcrm_full_usage "\n\n"
91//usage: "Upper-case options MQS remove an object by shmkey value.\n"
92//usage: "Lower-case options remove an object by shmid value.\n"
93//usage: "\n -mM Remove memory segment after last detach"
94//usage: "\n -qQ Remove message queue"
95//usage: "\n -sS Remove semaphore"
97 96
98int ipcrm_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 97int ipcrm_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
99int ipcrm_main(int argc, char **argv) 98int ipcrm_main(int argc, char **argv)
@@ -137,28 +136,20 @@ int ipcrm_main(int argc, char **argv)
137#endif /* IPCRM_LEGACY */ 136#endif /* IPCRM_LEGACY */
138 137
139 /* process new syntax to conform with SYSV ipcrm */ 138 /* process new syntax to conform with SYSV ipcrm */
140 while ((c = getopt(argc, argv, "q:m:s:Q:M:S:h?")) != -1) { 139 while ((c = getopt(argc, argv, "q:m:s:Q:M:S:")) != -1) {
141 int result; 140 int result;
142 int id = 0; 141 int id;
143 int iskey = isupper(c); 142 int iskey;
144
145 /* needed to delete semaphores */ 143 /* needed to delete semaphores */
146 union semun arg; 144 union semun arg;
147 145
148 arg.val = 0; 146 if (c == '?') /* option not in the string */
149
150 if ((c == '?') || (c == 'h')) {
151 bb_show_usage(); 147 bb_show_usage();
152 }
153
154 /* we don't need case information any more */
155 c = tolower(c);
156 148
157 /* make sure the option is in range: allowed are q, m, s */ 149 id = 0;
158 if (c != 'q' && c != 'm' && c != 's') { 150 arg.val = 0;
159 bb_show_usage();
160 }
161 151
152 iskey = !(c & 0x20); /* uppercase? */
162 if (iskey) { 153 if (iskey) {
163 /* keys are in hex or decimal */ 154 /* keys are in hex or decimal */
164 key_t key = xstrtoul(optarg, 0); 155 key_t key = xstrtoul(optarg, 0);
@@ -169,6 +160,7 @@ int ipcrm_main(int argc, char **argv)
169 continue; 160 continue;
170 } 161 }
171 162
163 c |= 0x20; /* lowercase. c is 'q', 'm' or 's' now */
172 /* convert key to id */ 164 /* convert key to id */
173 id = ((c == 'q') ? msgget(key, 0) : 165 id = ((c == 'q') ? msgget(key, 0) :
174 (c == 'm') ? shmget(key, 0, 0) : semget(key, 0, 0)); 166 (c == 'm') ? shmget(key, 0, 0) : semget(key, 0, 0));