Bump to version 1.22.1
[platform/upstream/busybox.git] / util-linux / ipcrm.c
index 6360c70..888f70e 100644 (file)
@@ -8,6 +8,15 @@
  * Licensed under GPLv2 or later, see file LICENSE in this source tree.
  */
 
+//usage:#define ipcrm_trivial_usage
+//usage:       "[-MQS key] [-mqs id]"
+//usage:#define ipcrm_full_usage "\n\n"
+//usage:       "Upper-case options MQS remove an object by shmkey value.\n"
+//usage:       "Lower-case options remove an object by shmid value.\n"
+//usage:     "\n       -mM     Remove memory segment after last detach"
+//usage:     "\n       -qQ     Remove message queue"
+//usage:     "\n       -sS     Remove semaphore"
+
 #include "libbb.h"
 
 /* X/OPEN tells us to use <sys/{types,ipc,sem}.h> for semctl() */
@@ -40,21 +49,21 @@ typedef enum type_id {
        MSG
 } type_id;
 
-static int remove_ids(type_id type, int argc, char **argv)
+static int remove_ids(type_id type, char **argv)
 {
        unsigned long id;
-       int ret = 0;            /* silence gcc */
        int nb_errors = 0;
        union semun arg;
 
        arg.val = 0;
 
-       while (argc) {
+       while (argv[0]) {
                id = bb_strtoul(argv[0], NULL, 10);
                if (errno || id > INT_MAX) {
                        bb_error_msg("invalid id: %s", argv[0]);
                        nb_errors++;
                } else {
+                       int ret = 0;
                        if (type == SEM)
                                ret = semctl(id, 0, IPC_RMID, arg);
                        else if (type == MSG)
@@ -67,7 +76,6 @@ static int remove_ids(type_id type, int argc, char **argv)
                                nb_errors++;
                        }
                }
-               argc--;
                argv++;
        }
 
@@ -92,14 +100,13 @@ int ipcrm_main(int argc, char **argv)
                type_id what = 0; /* silence gcc */
                char w;
 
-               w=argv[1][0];
+               w = argv[1][0];
                if ( ((w == 'm' && argv[1][1] == 's' && argv[1][2] == 'g')
                       || (argv[1][0] == 's'
-                          && ((w=argv[1][1]) == 'h' || w == 'e')
+                          && ((w = argv[1][1]) == 'h' || w == 'e')
                           && argv[1][2] == 'm')
                     ) && argv[1][3] == '\0'
                ) {
-
                        if (argc < 3)
                                bb_show_usage();
 
@@ -110,7 +117,7 @@ int ipcrm_main(int argc, char **argv)
                        else if (w == 'e')
                                what = SEM;
 
-                       if (remove_ids(what, argc-2, &argv[2]))
+                       if (remove_ids(what, &argv[2]))
                                fflush_stdout_and_exit(EXIT_FAILURE);
                        printf("resource(s) deleted\n");
                        return 0;
@@ -153,7 +160,7 @@ int ipcrm_main(int argc, char **argv)
 
                        /* convert key to id */
                        id = ((c == 'q') ? msgget(key, 0) :
-                                 (c == 'm') ? shmget(key, 0, 0) : semget(key, 0, 0));
+                               (c == 'm') ? shmget(key, 0, 0) : semget(key, 0, 0));
 
                        if (id < 0) {
                                const char *errmsg;
@@ -182,8 +189,8 @@ int ipcrm_main(int argc, char **argv)
                }
 
                result = ((c == 'q') ? msgctl(id, IPC_RMID, NULL) :
-                                 (c == 'm') ? shmctl(id, IPC_RMID, NULL) :
-                                 semctl(id, 0, IPC_RMID, arg));
+                               (c == 'm') ? shmctl(id, IPC_RMID, NULL) :
+                               semctl(id, 0, IPC_RMID, arg));
 
                if (result) {
                        const char *errmsg;