Fix some compiler warnings emitted by gcc-4.8.0
[oweals/busybox.git] / util-linux / ipcs.c
index d7d901921b7961baa036f747bd28f0fc69f8125d..2668cafd4622687197728ee483633f57b51714f5 100644 (file)
@@ -5,9 +5,25 @@
  * 01 Sept 2004 - Rodney Radford <rradford@mindspring.com>
  * Adapted for busybox from util-linux-2.12a.
  *
- * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
+ * Licensed under GPLv2 or later, see file LICENSE in this source tree.
  */
 
+//usage:#define ipcs_trivial_usage
+//usage:       "[[-smq] -i shmid] | [[-asmq] [-tcplu]]"
+//usage:#define ipcs_full_usage "\n\n"
+//usage:       "       -i      Show specific resource"
+//usage:     "\nResource specification:"
+//usage:     "\n       -m      Shared memory segments"
+//usage:     "\n       -q      Message queues"
+//usage:     "\n       -s      Semaphore arrays"
+//usage:     "\n       -a      All (default)"
+//usage:     "\nOutput format:"
+//usage:     "\n       -t      Time"
+//usage:     "\n       -c      Creator"
+//usage:     "\n       -p      Pid"
+//usage:     "\n       -l      Limits"
+//usage:     "\n       -u      Summary"
+
 /* X/OPEN tells us to use <sys/{types,ipc,sem}.h> for semctl() */
 /* X/OPEN tells us to use <sys/{types,ipc,msg}.h> for msgctl() */
 /* X/OPEN tells us to use <sys/{types,ipc,shm}.h> for shmctl() */
 #define SHM_INFO        14
 struct shm_info {
        int used_ids;
-       ulong shm_tot;          /* total allocated shm */
-       ulong shm_rss;          /* total resident shm */
-       ulong shm_swp;          /* total swapped shm */
-       ulong swap_attempts;
-       ulong swap_successes;
+       unsigned long shm_tot;          /* total allocated shm */
+       unsigned long shm_rss;          /* total resident shm */
+       unsigned long shm_swp;          /* total swapped shm */
+       unsigned long swap_attempts;
+       unsigned long swap_successes;
 };
 #endif
 
@@ -68,7 +84,7 @@ struct shm_info {
 union semun {
        int val;
        struct semid_ds *buf;
-       unsigned short int *array;
+       unsigned short *array;
        struct seminfo *__buf;
 };
 #endif
@@ -99,27 +115,23 @@ static void print_perms(int id, struct ipc_perm *ipcp)
 
        printf("%-10d %-10o", id, ipcp->mode & 0777);
 
-       if ((pw = getpwuid(ipcp->cuid)))
-               printf(" %-10s", pw->pw_name);
-       else
-               printf(" %-10d", ipcp->cuid);
-       if ((gr = getgrgid(ipcp->cgid)))
-               printf(" %-10s", gr->gr_name);
-       else
-               printf(" %-10d", ipcp->cgid);
-
-       if ((pw = getpwuid(ipcp->uid)))
-               printf(" %-10s", pw->pw_name);
-       else
-               printf(" %-10d", ipcp->uid);
-       if ((gr = getgrgid(ipcp->gid)))
-               printf(" %-10s\n", gr->gr_name);
-       else
-               printf(" %-10d\n", ipcp->gid);
+       pw = getpwuid(ipcp->cuid);
+       if (pw) printf(" %-10s", pw->pw_name);
+       else    printf(" %-10d", ipcp->cuid);
+       gr = getgrgid(ipcp->cgid);
+       if (gr) printf(" %-10s", gr->gr_name);
+       else    printf(" %-10d", ipcp->cgid);
+
+       pw = getpwuid(ipcp->uid);
+       if (pw) printf(" %-10s", pw->pw_name);
+       else    printf(" %-10d", ipcp->uid);
+       gr = getgrgid(ipcp->gid);
+       if (gr) printf(" %-10s\n", gr->gr_name);
+       else    printf(" %-10d\n", ipcp->gid);
 }
 
 
-static void do_shm(void)
+static NOINLINE void do_shm(void)
 {
        int maxid, shmid, id;
        struct shmid_ds shmseg;
@@ -140,54 +152,54 @@ static void do_shm(void)
                if ((shmctl(0, IPC_INFO, (struct shmid_ds *) (void *) &shminfo)) < 0)
                        return;
                /* glibc 2.1.3 and all earlier libc's have ints as fields
-                  of struct shminfo; glibc 2.1.91 has unsigned long; ach */
+                * of struct shminfo; glibc 2.1.91 has unsigned long; ach */
                printf("max number of segments = %lu\n"
-                                 "max seg size (kbytes) = %lu\n"
-                                 "max total shared memory (pages) = %lu\n"
-                                 "min seg size (bytes) = %lu\n",
-                                 (unsigned long) shminfo.shmmni,
-                                 (unsigned long) (shminfo.shmmax >> 10),
-                                 (unsigned long) shminfo.shmall,
-                                 (unsigned long) shminfo.shmmin);
+                               "max seg size (kbytes) = %lu\n"
+                               "max total shared memory (pages) = %lu\n"
+                               "min seg size (bytes) = %lu\n",
+                               (unsigned long) shminfo.shmmni,
+                               (unsigned long) (shminfo.shmmax >> 10),
+                               (unsigned long) shminfo.shmall,
+                               (unsigned long) shminfo.shmmin);
                return;
 
        case STATUS:
                printf("------ Shared Memory %s --------\n", "Status");
-               printf(   "segments allocated %d\n"
-                                 "pages allocated %ld\n"
-                                 "pages resident  %ld\n"
-                                 "pages swapped   %ld\n"
-                                 "Swap performance: %ld attempts\t%ld successes\n",
-                                 shm_info.used_ids,
-                                 shm_info.shm_tot,
-                                 shm_info.shm_rss,
-                                 shm_info.shm_swp,
-                                 shm_info.swap_attempts, shm_info.swap_successes);
+               printf("segments allocated %d\n"
+                               "pages allocated %ld\n"
+                               "pages resident  %ld\n"
+                               "pages swapped   %ld\n"
+                               "Swap performance: %ld attempts\t%ld successes\n",
+                               shm_info.used_ids,
+                               shm_info.shm_tot,
+                               shm_info.shm_rss,
+                               shm_info.shm_swp,
+                               shm_info.swap_attempts, shm_info.swap_successes);
                return;
 
        case CREATOR:
                printf("------ Shared Memory %s --------\n", "Segment Creators/Owners");
-               printf(   "%-10s %-10s %-10s %-10s %-10s %-10s\n",
-                                 "shmid", "perms", "cuid", "cgid", "uid", "gid");
+               printf("%-10s %-10s %-10s %-10s %-10s %-10s\n",
+                               "shmid", "perms", "cuid", "cgid", "uid", "gid");
                break;
 
        case TIME:
                printf("------ Shared Memory %s --------\n", "Attach/Detach/Change Times");
-               printf(   "%-10s %-10s %-20s %-20s %-20s\n",
-                                 "shmid", "owner", "attached", "detached", "changed");
+               printf("%-10s %-10s %-20s %-20s %-20s\n",
+                               "shmid", "owner", "attached", "detached", "changed");
                break;
 
        case PID:
                printf("------ Shared Memory %s --------\n", "Creator/Last-op");
-               printf(   "%-10s %-10s %-10s %-10s\n",
-                                 "shmid", "owner", "cpid", "lpid");
+               printf("%-10s %-10s %-10s %-10s\n",
+                               "shmid", "owner", "cpid", "lpid");
                break;
 
        default:
                printf("------ Shared Memory %s --------\n", "Segments");
-               printf(   "%-10s %-10s %-10s %-10s %-10s %-10s %-12s\n",
-                                 "key", "shmid", "owner", "perms", "bytes", "nattch",
-                                 "status");
+               printf("%-10s %-10s %-10s %-10s %-10s %-10s %-12s\n",
+                               "key", "shmid", "owner", "perms", "bytes", "nattch",
+                               "status");
                break;
        }
 
@@ -208,11 +220,11 @@ static void do_shm(void)
                                printf("%-10d %-10d", shmid, ipcp->uid);
                        /* ctime uses static buffer: use separate calls */
                        printf(" %-20.16s", shmseg.shm_atime
-                                         ? ctime(&shmseg.shm_atime) + 4 : "Not set");
+                                       ? ctime(&shmseg.shm_atime) + 4 : "Not set");
                        printf(" %-20.16s", shmseg.shm_dtime
-                                         ? ctime(&shmseg.shm_dtime) + 4 : "Not set");
+                                       ? ctime(&shmseg.shm_dtime) + 4 : "Not set");
                        printf(" %-20.16s\n", shmseg.shm_ctime
-                                         ? ctime(&shmseg.shm_ctime) + 4 : "Not set");
+                                       ? ctime(&shmseg.shm_ctime) + 4 : "Not set");
                        break;
                case PID:
                        if (pw)
@@ -229,24 +241,24 @@ static void do_shm(void)
                        else
                                printf("%-10d %-10d", shmid, ipcp->uid);
                        printf(" %-10o %-10lu %-10ld %-6s %-6s\n", ipcp->mode & 0777,
-                                         /*
-                                          * earlier: int, Austin has size_t
-                                          */
-                                         (unsigned long) shmseg.shm_segsz,
-                                         /*
-                                          * glibc-2.1.3 and earlier has unsigned short;
-                                          * Austin has shmatt_t
-                                          */
-                                         (long) shmseg.shm_nattch,
-                                         ipcp->mode & SHM_DEST ? "dest" : " ",
-                                         ipcp->mode & SHM_LOCKED ? "locked" : " ");
+                                       /*
+                                        * earlier: int, Austin has size_t
+                                        */
+                                       (unsigned long) shmseg.shm_segsz,
+                                       /*
+                                        * glibc-2.1.3 and earlier has unsigned short;
+                                        * Austin has shmatt_t
+                                        */
+                                       (long) shmseg.shm_nattch,
+                                       ipcp->mode & SHM_DEST ? "dest" : " ",
+                                       ipcp->mode & SHM_LOCKED ? "locked" : " ");
                        break;
                }
        }
 }
 
 
-static void do_sem(void)
+static NOINLINE void do_sem(void)
 {
        int maxid, semid, id;
        struct semid_ds semary;
@@ -255,7 +267,7 @@ static void do_sem(void)
        struct passwd *pw;
        union semun arg;
 
-       arg.array = (ushort *) (void *) &seminfo;
+       arg.array = (unsigned short *) (void *) &seminfo;
        maxid = semctl(0, 0, SEM_INFO, arg);
        if (maxid < 0) {
                printf("kernel not configured for %s\n", "semaphores");
@@ -265,36 +277,36 @@ static void do_sem(void)
        switch (format) {
        case LIMITS:
                printf("------ Semaphore %s --------\n", "Limits");
-               arg.array = (ushort *) (void *) &seminfo;       /* damn union */
+               arg.array = (unsigned short *) (void *) &seminfo;       /* damn union */
                if ((semctl(0, 0, IPC_INFO, arg)) < 0)
                        return;
                printf("max number of arrays = %d\n"
-                                 "max semaphores per array = %d\n"
-                                 "max semaphores system wide = %d\n"
-                                 "max ops per semop call = %d\n"
-                                 "semaphore max value = %d\n",
-                                 seminfo.semmni,
-                                 seminfo.semmsl,
-                                 seminfo.semmns, seminfo.semopm, seminfo.semvmx);
+                               "max semaphores per array = %d\n"
+                               "max semaphores system wide = %d\n"
+                               "max ops per semop call = %d\n"
+                               "semaphore max value = %d\n",
+                               seminfo.semmni,
+                               seminfo.semmsl,
+                               seminfo.semmns, seminfo.semopm, seminfo.semvmx);
                return;
 
        case STATUS:
                printf("------ Semaphore %s --------\n", "Status");
-               printf(   "used arrays = %d\n"
-                                 "allocated semaphores = %d\n",
-                                 seminfo.semusz, seminfo.semaem);
+               printf("used arrays = %d\n"
+                               "allocated semaphores = %d\n",
+                               seminfo.semusz, seminfo.semaem);
                return;
 
        case CREATOR:
                printf("------ Semaphore %s --------\n", "Arrays Creators/Owners");
-               printf(   "%-10s %-10s %-10s %-10s %-10s %-10s\n",
-                                 "semid", "perms", "cuid", "cgid", "uid", "gid");
+               printf("%-10s %-10s %-10s %-10s %-10s %-10s\n",
+                               "semid", "perms", "cuid", "cgid", "uid", "gid");
                break;
 
        case TIME:
                printf("------ Shared Memory %s --------\n", "Operation/Change Times");
-               printf(   "%-8s %-10s %-26.24s %-26.24s\n",
-                                 "shmid", "owner", "last-op", "last-changed");
+               printf("%-8s %-10s %-26.24s %-26.24s\n",
+                               "shmid", "owner", "last-op", "last-changed");
                break;
 
        case PID:
@@ -302,8 +314,8 @@ static void do_sem(void)
 
        default:
                printf("------ Semaphore %s --------\n", "Arrays");
-               printf(   "%-10s %-10s %-10s %-10s %-10s\n",
-                                 "key", "semid", "owner", "perms", "nsems");
+               printf("%-10s %-10s %-10s %-10s %-10s\n",
+                               "key", "semid", "owner", "perms", "nsems");
                break;
        }
 
@@ -325,9 +337,9 @@ static void do_sem(void)
                                printf("%-8d %-10d", semid, ipcp->uid);
                        /* ctime uses static buffer: use separate calls */
                        printf("  %-26.24s", semary.sem_otime
-                                         ? ctime(&semary.sem_otime) : "Not set");
+                                       ? ctime(&semary.sem_otime) : "Not set");
                        printf(" %-26.24s\n", semary.sem_ctime
-                                         ? ctime(&semary.sem_ctime) : "Not set");
+                                       ? ctime(&semary.sem_ctime) : "Not set");
                        break;
                case PID:
                        break;
@@ -339,20 +351,20 @@ static void do_sem(void)
                        else
                                printf("%-10d %-9d", semid, ipcp->uid);
                        printf(" %-10o %-10ld\n", ipcp->mode & 0777,
-                                         /*
-                                          * glibc-2.1.3 and earlier has unsigned short;
-                                          * glibc-2.1.91 has variation between
-                                          * unsigned short and unsigned long
-                                          * Austin prescribes unsigned short.
-                                          */
-                                         (long) semary.sem_nsems);
+                                       /*
+                                        * glibc-2.1.3 and earlier has unsigned short;
+                                        * glibc-2.1.91 has variation between
+                                        * unsigned short and unsigned long
+                                        * Austin prescribes unsigned short.
+                                        */
+                                       (long) semary.sem_nsems);
                        break;
                }
        }
 }
 
 
-static void do_msg(void)
+static NOINLINE void do_msg(void)
 {
        int maxid, msqid, id;
        struct msqid_ds msgque;
@@ -371,42 +383,42 @@ static void do_msg(void)
                if ((msgctl(0, IPC_INFO, (struct msqid_ds *) (void *) &msginfo)) < 0)
                        return;
                printf("------ Message%s --------\n", "s: Limits");
-               printf(   "max queues system wide = %d\n"
-                                 "max size of message (bytes) = %d\n"
-                                 "default max size of queue (bytes) = %d\n",
-                                 msginfo.msgmni, msginfo.msgmax, msginfo.msgmnb);
+               printf("max queues system wide = %d\n"
+                               "max size of message (bytes) = %d\n"
+                               "default max size of queue (bytes) = %d\n",
+                               msginfo.msgmni, msginfo.msgmax, msginfo.msgmnb);
                return;
 
        case STATUS:
                printf("------ Message%s --------\n", "s: Status");
-               printf(   "allocated queues = %d\n"
-                                 "used headers = %d\n"
-                                 "used space = %d bytes\n",
-                                 msginfo.msgpool, msginfo.msgmap, msginfo.msgtql);
+               printf("allocated queues = %d\n"
+                               "used headers = %d\n"
+                               "used space = %d bytes\n",
+                               msginfo.msgpool, msginfo.msgmap, msginfo.msgtql);
                return;
 
        case CREATOR:
                printf("------ Message%s --------\n", " Queues: Creators/Owners");
-               printf(   "%-10s %-10s %-10s %-10s %-10s %-10s\n",
-                                 "msqid", "perms", "cuid", "cgid", "uid", "gid");
+               printf("%-10s %-10s %-10s %-10s %-10s %-10s\n",
+                               "msqid", "perms", "cuid", "cgid", "uid", "gid");
                break;
 
        case TIME:
                printf("------ Message%s --------\n", " Queues Send/Recv/Change Times");
-               printf(   "%-8s %-10s %-20s %-20s %-20s\n",
-                                 "msqid", "owner", "send", "recv", "change");
+               printf("%-8s %-10s %-20s %-20s %-20s\n",
+                               "msqid", "owner", "send", "recv", "change");
                break;
 
        case PID:
                printf("------ Message%s --------\n", " Queues PIDs");
-               printf(   "%-10s %-10s %-10s %-10s\n",
-                                 "msqid", "owner", "lspid", "lrpid");
+               printf("%-10s %-10s %-10s %-10s\n",
+                               "msqid", "owner", "lspid", "lrpid");
                break;
 
        default:
                printf("------ Message%s --------\n", " Queues");
-               printf(   "%-10s %-10s %-10s %-10s %-12s %-12s\n",
-                                 "key", "msqid", "owner", "perms", "used-bytes", "messages");
+               printf("%-10s %-10s %-10s %-10s %-12s %-12s\n",
+                               "key", "msqid", "owner", "perms", "used-bytes", "messages");
                break;
        }
 
@@ -426,11 +438,11 @@ static void do_msg(void)
                        else
                                printf("%-8d %-10d", msqid, ipcp->uid);
                        printf(" %-20.16s", msgque.msg_stime
-                                         ? ctime(&msgque.msg_stime) + 4 : "Not set");
+                                       ? ctime(&msgque.msg_stime) + 4 : "Not set");
                        printf(" %-20.16s", msgque.msg_rtime
-                                         ? ctime(&msgque.msg_rtime) + 4 : "Not set");
+                                       ? ctime(&msgque.msg_rtime) + 4 : "Not set");
                        printf(" %-20.16s\n", msgque.msg_ctime
-                                         ? ctime(&msgque.msg_ctime) + 4 : "Not set");
+                                       ? ctime(&msgque.msg_ctime) + 4 : "Not set");
                        break;
                case PID:
                        if (pw)
@@ -447,13 +459,13 @@ static void do_msg(void)
                        else
                                printf("%-10d %-10d", msqid, ipcp->uid);
                        printf(" %-10o %-12ld %-12ld\n", ipcp->mode & 0777,
-                                         /*
-                                          * glibc-2.1.3 and earlier has unsigned short;
-                                          * glibc-2.1.91 has variation between
-                                          * unsigned short, unsigned long
-                                          * Austin has msgqnum_t
-                                          */
-                                         (long) msgque.msg_cbytes, (long) msgque.msg_qnum);
+                                       /*
+                                        * glibc-2.1.3 and earlier has unsigned short;
+                                        * glibc-2.1.91 has variation between
+                                        * unsigned short, unsigned long
+                                        * Austin has msgqnum_t
+                                        */
+                                       (long) msgque.msg_cbytes, (long) msgque.msg_qnum);
                        break;
                }
        }
@@ -471,18 +483,18 @@ static void print_shm(int shmid)
        }
 
        printf("\nShared memory Segment shmid=%d\n"
-                         "uid=%d\tgid=%d\tcuid=%d\tcgid=%d\n"
-                         "mode=%#o\taccess_perms=%#o\n"
-                         "bytes=%ld\tlpid=%d\tcpid=%d\tnattch=%ld\n",
-                         shmid,
-                         ipcp->uid, ipcp->gid, ipcp->cuid, ipcp->cgid,
-                         ipcp->mode, ipcp->mode & 0777,
-                         (long) shmds.shm_segsz, shmds.shm_lpid, shmds.shm_cpid,
-                         (long) shmds.shm_nattch);
+                       "uid=%d\tgid=%d\tcuid=%d\tcgid=%d\n"
+                       "mode=%#o\taccess_perms=%#o\n"
+                       "bytes=%ld\tlpid=%d\tcpid=%d\tnattch=%ld\n",
+                       shmid,
+                       ipcp->uid, ipcp->gid, ipcp->cuid, ipcp->cgid,
+                       ipcp->mode, ipcp->mode & 0777,
+                       (long) shmds.shm_segsz, shmds.shm_lpid, shmds.shm_cpid,
+                       (long) shmds.shm_nattch);
        printf("att_time=%-26.24s\n",
-                         shmds.shm_atime ? ctime(&shmds.shm_atime) : "Not set");
+                       shmds.shm_atime ? ctime(&shmds.shm_atime) : "Not set");
        printf("det_time=%-26.24s\n",
-                         shmds.shm_dtime ? ctime(&shmds.shm_dtime) : "Not set");
+                       shmds.shm_dtime ? ctime(&shmds.shm_dtime) : "Not set");
        printf("change_time=%-26.24s\n\n", ctime(&shmds.shm_ctime));
 }
 
@@ -498,24 +510,24 @@ static void print_msg(int msqid)
        }
 
        printf("\nMessage Queue msqid=%d\n"
-                         "uid=%d\tgid=%d\tcuid=%d\tcgid=%d\tmode=%#o\n"
-                         "cbytes=%ld\tqbytes=%ld\tqnum=%ld\tlspid=%d\tlrpid=%d\n",
-                         msqid, ipcp->uid, ipcp->gid, ipcp->cuid, ipcp->cgid, ipcp->mode,
-                         /*
-                          * glibc-2.1.3 and earlier has unsigned short;
-                          * glibc-2.1.91 has variation between
-                          * unsigned short, unsigned long
-                          * Austin has msgqnum_t (for msg_qbytes)
-                          */
-                         (long) buf.msg_cbytes, (long) buf.msg_qbytes,
-                         (long) buf.msg_qnum, buf.msg_lspid, buf.msg_lrpid);
+                       "uid=%d\tgid=%d\tcuid=%d\tcgid=%d\tmode=%#o\n"
+                       "cbytes=%ld\tqbytes=%ld\tqnum=%ld\tlspid=%d\tlrpid=%d\n",
+                       msqid, ipcp->uid, ipcp->gid, ipcp->cuid, ipcp->cgid, ipcp->mode,
+                       /*
+                        * glibc-2.1.3 and earlier has unsigned short;
+                        * glibc-2.1.91 has variation between
+                        * unsigned short, unsigned long
+                        * Austin has msgqnum_t (for msg_qbytes)
+                        */
+                       (long) buf.msg_cbytes, (long) buf.msg_qbytes,
+                       (long) buf.msg_qnum, buf.msg_lspid, buf.msg_lrpid);
 
        printf("send_time=%-26.24s\n",
-                         buf.msg_stime ? ctime(&buf.msg_stime) : "Not set");
+                       buf.msg_stime ? ctime(&buf.msg_stime) : "Not set");
        printf("rcv_time=%-26.24s\n",
-                         buf.msg_rtime ? ctime(&buf.msg_rtime) : "Not set");
+                       buf.msg_rtime ? ctime(&buf.msg_rtime) : "Not set");
        printf("change_time=%-26.24s\n\n",
-                         buf.msg_ctime ? ctime(&buf.msg_ctime) : "Not set");
+                       buf.msg_ctime ? ctime(&buf.msg_ctime) : "Not set");
 }
 
 static void print_sem(int semid)
@@ -532,19 +544,19 @@ static void print_sem(int semid)
        }
 
        printf("\nSemaphore Array semid=%d\n"
-                         "uid=%d\t gid=%d\t cuid=%d\t cgid=%d\n"
-                         "mode=%#o, access_perms=%#o\n"
-                         "nsems = %ld\n"
-                         "otime = %-26.24s\n",
-                         semid,
-                         ipcp->uid, ipcp->gid, ipcp->cuid, ipcp->cgid,
-                         ipcp->mode, ipcp->mode & 0777,
-                         (long) semds.sem_nsems,
-                         semds.sem_otime ? ctime(&semds.sem_otime) : "Not set");
+                       "uid=%d\t gid=%d\t cuid=%d\t cgid=%d\n"
+                       "mode=%#o, access_perms=%#o\n"
+                       "nsems = %ld\n"
+                       "otime = %-26.24s\n",
+                       semid,
+                       ipcp->uid, ipcp->gid, ipcp->cuid, ipcp->cgid,
+                       ipcp->mode, ipcp->mode & 0777,
+                       (long) semds.sem_nsems,
+                       semds.sem_otime ? ctime(&semds.sem_otime) : "Not set");
        printf("ctime = %-26.24s\n"
-                         "%-10s %-10s %-10s %-10s %-10s\n",
-                         ctime(&semds.sem_ctime),
-                         "semnum", "value", "ncount", "zcount", "pid");
+                       "%-10s %-10s %-10s %-10s %-10s\n",
+                       ctime(&semds.sem_ctime),
+                       "semnum", "value", "ncount", "zcount", "pid");
 
        arg.val = 0;
        for (i = 0; i < semds.sem_nsems; i++) {
@@ -559,11 +571,11 @@ static void print_sem(int semid)
                }
                printf("%-10d %-10d %-10d %-10d %-10d\n", i, val, ncnt, zcnt, pid);
        }
-       puts("");
+       bb_putchar('\n');
 }
 
-int ipcs_main(int argc, char **argv);
-int ipcs_main(int argc, char **argv)
+int ipcs_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
+int ipcs_main(int argc UNUSED_PARAM, char **argv)
 {
        int id = 0;
        unsigned flags = 0;
@@ -574,7 +586,7 @@ int ipcs_main(int argc, char **argv)
 #define flag_sem       (1<<2)
 #define flag_shm       (1<<3)
 
-       opt = getopt32(argc, argv, "i:aqsmtcplu", &opt_i);
+       opt = getopt32(argv, "i:aqsmtcplu", &opt_i);
        if (opt & 0x1) { // -i
                id = xatoi(opt_i);
                flags |= flag_print;
@@ -592,34 +604,34 @@ int ipcs_main(int argc, char **argv)
        if (flags & flag_print) {
                if (flags & flag_shm) {
                        print_shm(id);
-                       fflush_stdout_and_exit(0);
+                       fflush_stdout_and_exit(EXIT_SUCCESS);
                }
                if (flags & flag_sem) {
                        print_sem(id);
-                       fflush_stdout_and_exit(0);
+                       fflush_stdout_and_exit(EXIT_SUCCESS);
                }
                if (flags & flag_msg) {
                        print_msg(id);
-                       fflush_stdout_and_exit(0);
+                       fflush_stdout_and_exit(EXIT_SUCCESS);
                }
                bb_show_usage();
        }
 
        if (!(flags & (flag_shm | flag_msg | flag_sem)))
                flags |= flag_msg | flag_shm | flag_sem;
-       puts("");
+       bb_putchar('\n');
 
        if (flags & flag_shm) {
                do_shm();
-               puts("");
+               bb_putchar('\n');
        }
        if (flags & flag_sem) {
                do_sem();
-               puts("");
+               bb_putchar('\n');
        }
        if (flags & flag_msg) {
                do_msg();
-               puts("");
+               bb_putchar('\n');
        }
-       fflush_stdout_and_exit(0);
+       fflush_stdout_and_exit(EXIT_SUCCESS);
 }