diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2017-08-09 19:20:08 +0200 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2017-08-09 19:20:08 +0200 |
| commit | 7943be1e13d6c09f2adda5e954d56ff019a79008 (patch) | |
| tree | f76ad8861a5b2ab0b38da46de121df4dc8111689 /util-linux | |
| parent | a4d4ab04c3706af1cb2f65fb00c96d3ccba1020c (diff) | |
| download | busybox-w32-7943be1e13d6c09f2adda5e954d56ff019a79008.tar.gz busybox-w32-7943be1e13d6c09f2adda5e954d56ff019a79008.tar.bz2 busybox-w32-7943be1e13d6c09f2adda5e954d56ff019a79008.zip | |
ipcrm: code shrink
function old new delta
ipcrm_main 698 663 -35
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'util-linux')
| -rw-r--r-- | util-linux/ipcrm.c | 40 |
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 | ||
| 98 | int ipcrm_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 97 | int ipcrm_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
| 99 | int ipcrm_main(int argc, char **argv) | 98 | int 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)); |
