Changeset 3232 in MondoRescue for branches/3.2/mindi-busybox/util-linux/ipcs.c


Ignore:
Timestamp:
Jan 1, 2014, 12:47:38 AM (10 years ago)
Author:
Bruno Cornec
Message:
  • Update mindi-busybox to 1.21.1
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.2/mindi-busybox/util-linux/ipcs.c

    r2725 r3232  
    99 */
    1010
     11//usage:#define ipcs_trivial_usage
     12//usage:       "[[-smq] -i shmid] | [[-asmq] [-tcplu]]"
     13//usage:#define ipcs_full_usage "\n\n"
     14//usage:       "    -i  Show specific resource"
     15//usage:     "\nResource specification:"
     16//usage:     "\n    -m  Shared memory segments"
     17//usage:     "\n    -q  Message queues"
     18//usage:     "\n    -s  Semaphore arrays"
     19//usage:     "\n    -a  All (default)"
     20//usage:     "\nOutput format:"
     21//usage:     "\n    -t  Time"
     22//usage:     "\n    -c  Creator"
     23//usage:     "\n    -p  Pid"
     24//usage:     "\n    -l  Limits"
     25//usage:     "\n    -u  Summary"
     26
    1127/* X/OPEN tells us to use <sys/{types,ipc,sem}.h> for semctl() */
    1228/* X/OPEN tells us to use <sys/{types,ipc,msg}.h> for msgctl() */
     
    4056struct shm_info {
    4157    int used_ids;
    42     ulong shm_tot;      /* total allocated shm */
    43     ulong shm_rss;      /* total resident shm */
    44     ulong shm_swp;      /* total swapped shm */
    45     ulong swap_attempts;
    46     ulong swap_successes;
     58    unsigned long shm_tot;      /* total allocated shm */
     59    unsigned long shm_rss;      /* total resident shm */
     60    unsigned long shm_swp;      /* total swapped shm */
     61    unsigned long swap_attempts;
     62    unsigned long swap_successes;
    4763};
    4864#endif
     
    137153            return;
    138154        /* glibc 2.1.3 and all earlier libc's have ints as fields
    139            of struct shminfo; glibc 2.1.91 has unsigned long; ach */
     155         * of struct shminfo; glibc 2.1.91 has unsigned long; ach */
    140156        printf("max number of segments = %lu\n"
    141                   "max seg size (kbytes) = %lu\n"
    142                   "max total shared memory (pages) = %lu\n"
    143                   "min seg size (bytes) = %lu\n",
    144                   (unsigned long) shminfo.shmmni,
    145                   (unsigned long) (shminfo.shmmax >> 10),
    146                   (unsigned long) shminfo.shmall,
    147                   (unsigned long) shminfo.shmmin);
     157                "max seg size (kbytes) = %lu\n"
     158                "max total shared memory (pages) = %lu\n"
     159                "min seg size (bytes) = %lu\n",
     160                (unsigned long) shminfo.shmmni,
     161                (unsigned long) (shminfo.shmmax >> 10),
     162                (unsigned long) shminfo.shmall,
     163                (unsigned long) shminfo.shmmin);
    148164        return;
    149165
    150166    case STATUS:
    151167        printf("------ Shared Memory %s --------\n", "Status");
    152         printf(   "segments allocated %d\n"
    153                   "pages allocated %ld\n"
    154                   "pages resident  %ld\n"
    155                   "pages swapped   %ld\n"
    156                   "Swap performance: %ld attempts\t%ld successes\n",
    157                   shm_info.used_ids,
    158                   shm_info.shm_tot,
    159                   shm_info.shm_rss,
    160                   shm_info.shm_swp,
    161                   shm_info.swap_attempts, shm_info.swap_successes);
     168        printf("segments allocated %d\n"
     169                "pages allocated %ld\n"
     170                "pages resident  %ld\n"
     171                "pages swapped   %ld\n"
     172                "Swap performance: %ld attempts\t%ld successes\n",
     173                shm_info.used_ids,
     174                shm_info.shm_tot,
     175                shm_info.shm_rss,
     176                shm_info.shm_swp,
     177                shm_info.swap_attempts, shm_info.swap_successes);
    162178        return;
    163179
    164180    case CREATOR:
    165181        printf("------ Shared Memory %s --------\n", "Segment Creators/Owners");
    166         printf(   "%-10s %-10s %-10s %-10s %-10s %-10s\n",
    167                   "shmid", "perms", "cuid", "cgid", "uid", "gid");
     182        printf("%-10s %-10s %-10s %-10s %-10s %-10s\n",
     183                "shmid", "perms", "cuid", "cgid", "uid", "gid");
    168184        break;
    169185
    170186    case TIME:
    171187        printf("------ Shared Memory %s --------\n", "Attach/Detach/Change Times");
    172         printf(   "%-10s %-10s %-20s %-20s %-20s\n",
    173                   "shmid", "owner", "attached", "detached", "changed");
     188        printf("%-10s %-10s %-20s %-20s %-20s\n",
     189                "shmid", "owner", "attached", "detached", "changed");
    174190        break;
    175191
    176192    case PID:
    177193        printf("------ Shared Memory %s --------\n", "Creator/Last-op");
    178         printf(   "%-10s %-10s %-10s %-10s\n",
    179                   "shmid", "owner", "cpid", "lpid");
     194        printf("%-10s %-10s %-10s %-10s\n",
     195                "shmid", "owner", "cpid", "lpid");
    180196        break;
    181197
    182198    default:
    183199        printf("------ Shared Memory %s --------\n", "Segments");
    184         printf(   "%-10s %-10s %-10s %-10s %-10s %-10s %-12s\n",
    185                   "key", "shmid", "owner", "perms", "bytes", "nattch",
    186                   "status");
     200        printf("%-10s %-10s %-10s %-10s %-10s %-10s %-12s\n",
     201                "key", "shmid", "owner", "perms", "bytes", "nattch",
     202                "status");
    187203        break;
    188204    }
     
    205221            /* ctime uses static buffer: use separate calls */
    206222            printf(" %-20.16s", shmseg.shm_atime
    207                       ? ctime(&shmseg.shm_atime) + 4 : "Not set");
     223                    ? ctime(&shmseg.shm_atime) + 4 : "Not set");
    208224            printf(" %-20.16s", shmseg.shm_dtime
    209                       ? ctime(&shmseg.shm_dtime) + 4 : "Not set");
     225                    ? ctime(&shmseg.shm_dtime) + 4 : "Not set");
    210226            printf(" %-20.16s\n", shmseg.shm_ctime
    211                       ? ctime(&shmseg.shm_ctime) + 4 : "Not set");
     227                    ? ctime(&shmseg.shm_ctime) + 4 : "Not set");
    212228            break;
    213229        case PID:
     
    226242                printf("%-10d %-10d", shmid, ipcp->uid);
    227243            printf(" %-10o %-10lu %-10ld %-6s %-6s\n", ipcp->mode & 0777,
    228                       /*
    229                        * earlier: int, Austin has size_t
    230                        */
    231                       (unsigned long) shmseg.shm_segsz,
    232                       /*
    233                        * glibc-2.1.3 and earlier has unsigned short;
    234                        * Austin has shmatt_t
    235                        */
    236                       (long) shmseg.shm_nattch,
    237                       ipcp->mode & SHM_DEST ? "dest" : " ",
    238                       ipcp->mode & SHM_LOCKED ? "locked" : " ");
     244                    /*
     245                     * earlier: int, Austin has size_t
     246                     */
     247                    (unsigned long) shmseg.shm_segsz,
     248                    /*
     249                     * glibc-2.1.3 and earlier has unsigned short;
     250                     * Austin has shmatt_t
     251                     */
     252                    (long) shmseg.shm_nattch,
     253                    ipcp->mode & SHM_DEST ? "dest" : " ",
     254                    ipcp->mode & SHM_LOCKED ? "locked" : " ");
    239255            break;
    240256        }
     
    252268    union semun arg;
    253269
    254     arg.array = (ushort *) (void *) &seminfo;
     270    arg.array = (unsigned short *) (void *) &seminfo;
    255271    maxid = semctl(0, 0, SEM_INFO, arg);
    256272    if (maxid < 0) {
     
    262278    case LIMITS:
    263279        printf("------ Semaphore %s --------\n", "Limits");
    264         arg.array = (ushort *) (void *) &seminfo;   /* damn union */
     280        arg.array = (unsigned short *) (void *) &seminfo;   /* damn union */
    265281        if ((semctl(0, 0, IPC_INFO, arg)) < 0)
    266282            return;
    267283        printf("max number of arrays = %d\n"
    268                   "max semaphores per array = %d\n"
    269                   "max semaphores system wide = %d\n"
    270                   "max ops per semop call = %d\n"
    271                   "semaphore max value = %d\n",
    272                   seminfo.semmni,
    273                   seminfo.semmsl,
    274                   seminfo.semmns, seminfo.semopm, seminfo.semvmx);
     284                "max semaphores per array = %d\n"
     285                "max semaphores system wide = %d\n"
     286                "max ops per semop call = %d\n"
     287                "semaphore max value = %d\n",
     288                seminfo.semmni,
     289                seminfo.semmsl,
     290                seminfo.semmns, seminfo.semopm, seminfo.semvmx);
    275291        return;
    276292
    277293    case STATUS:
    278294        printf("------ Semaphore %s --------\n", "Status");
    279         printf(   "used arrays = %d\n"
    280                   "allocated semaphores = %d\n",
    281                   seminfo.semusz, seminfo.semaem);
     295        printf("used arrays = %d\n"
     296                "allocated semaphores = %d\n",
     297                seminfo.semusz, seminfo.semaem);
    282298        return;
    283299
    284300    case CREATOR:
    285301        printf("------ Semaphore %s --------\n", "Arrays Creators/Owners");
    286         printf(   "%-10s %-10s %-10s %-10s %-10s %-10s\n",
    287                   "semid", "perms", "cuid", "cgid", "uid", "gid");
     302        printf("%-10s %-10s %-10s %-10s %-10s %-10s\n",
     303                "semid", "perms", "cuid", "cgid", "uid", "gid");
    288304        break;
    289305
    290306    case TIME:
    291307        printf("------ Shared Memory %s --------\n", "Operation/Change Times");
    292         printf(   "%-8s %-10s %-26.24s %-26.24s\n",
    293                   "shmid", "owner", "last-op", "last-changed");
     308        printf("%-8s %-10s %-26.24s %-26.24s\n",
     309                "shmid", "owner", "last-op", "last-changed");
    294310        break;
    295311
     
    299315    default:
    300316        printf("------ Semaphore %s --------\n", "Arrays");
    301         printf(   "%-10s %-10s %-10s %-10s %-10s\n",
    302                   "key", "semid", "owner", "perms", "nsems");
     317        printf("%-10s %-10s %-10s %-10s %-10s\n",
     318                "key", "semid", "owner", "perms", "nsems");
    303319        break;
    304320    }
     
    322338            /* ctime uses static buffer: use separate calls */
    323339            printf("  %-26.24s", semary.sem_otime
    324                       ? ctime(&semary.sem_otime) : "Not set");
     340                    ? ctime(&semary.sem_otime) : "Not set");
    325341            printf(" %-26.24s\n", semary.sem_ctime
    326                       ? ctime(&semary.sem_ctime) : "Not set");
     342                    ? ctime(&semary.sem_ctime) : "Not set");
    327343            break;
    328344        case PID:
     
    336352                printf("%-10d %-9d", semid, ipcp->uid);
    337353            printf(" %-10o %-10ld\n", ipcp->mode & 0777,
    338                       /*
    339                        * glibc-2.1.3 and earlier has unsigned short;
    340                        * glibc-2.1.91 has variation between
    341                        * unsigned short and unsigned long
    342                        * Austin prescribes unsigned short.
    343                        */
    344                       (long) semary.sem_nsems);
     354                    /*
     355                     * glibc-2.1.3 and earlier has unsigned short;
     356                     * glibc-2.1.91 has variation between
     357                     * unsigned short and unsigned long
     358                     * Austin prescribes unsigned short.
     359                     */
     360                    (long) semary.sem_nsems);
    345361            break;
    346362        }
     
    368384            return;
    369385        printf("------ Message%s --------\n", "s: Limits");
    370         printf(   "max queues system wide = %d\n"
    371                   "max size of message (bytes) = %d\n"
    372                   "default max size of queue (bytes) = %d\n",
    373                   msginfo.msgmni, msginfo.msgmax, msginfo.msgmnb);
     386        printf("max queues system wide = %d\n"
     387                "max size of message (bytes) = %d\n"
     388                "default max size of queue (bytes) = %d\n",
     389                msginfo.msgmni, msginfo.msgmax, msginfo.msgmnb);
    374390        return;
    375391
    376392    case STATUS:
    377393        printf("------ Message%s --------\n", "s: Status");
    378         printf(   "allocated queues = %d\n"
    379                   "used headers = %d\n"
    380                   "used space = %d bytes\n",
    381                   msginfo.msgpool, msginfo.msgmap, msginfo.msgtql);
     394        printf("allocated queues = %d\n"
     395                "used headers = %d\n"
     396                "used space = %d bytes\n",
     397                msginfo.msgpool, msginfo.msgmap, msginfo.msgtql);
    382398        return;
    383399
    384400    case CREATOR:
    385401        printf("------ Message%s --------\n", " Queues: Creators/Owners");
    386         printf(   "%-10s %-10s %-10s %-10s %-10s %-10s\n",
    387                   "msqid", "perms", "cuid", "cgid", "uid", "gid");
     402        printf("%-10s %-10s %-10s %-10s %-10s %-10s\n",
     403                "msqid", "perms", "cuid", "cgid", "uid", "gid");
    388404        break;
    389405
    390406    case TIME:
    391407        printf("------ Message%s --------\n", " Queues Send/Recv/Change Times");
    392         printf(   "%-8s %-10s %-20s %-20s %-20s\n",
    393                   "msqid", "owner", "send", "recv", "change");
     408        printf("%-8s %-10s %-20s %-20s %-20s\n",
     409                "msqid", "owner", "send", "recv", "change");
    394410        break;
    395411
    396412    case PID:
    397413        printf("------ Message%s --------\n", " Queues PIDs");
    398         printf(   "%-10s %-10s %-10s %-10s\n",
    399                   "msqid", "owner", "lspid", "lrpid");
     414        printf("%-10s %-10s %-10s %-10s\n",
     415                "msqid", "owner", "lspid", "lrpid");
    400416        break;
    401417
    402418    default:
    403419        printf("------ Message%s --------\n", " Queues");
    404         printf(   "%-10s %-10s %-10s %-10s %-12s %-12s\n",
    405                   "key", "msqid", "owner", "perms", "used-bytes", "messages");
     420        printf("%-10s %-10s %-10s %-10s %-12s %-12s\n",
     421                "key", "msqid", "owner", "perms", "used-bytes", "messages");
    406422        break;
    407423    }
     
    423439                printf("%-8d %-10d", msqid, ipcp->uid);
    424440            printf(" %-20.16s", msgque.msg_stime
    425                       ? ctime(&msgque.msg_stime) + 4 : "Not set");
     441                    ? ctime(&msgque.msg_stime) + 4 : "Not set");
    426442            printf(" %-20.16s", msgque.msg_rtime
    427                       ? ctime(&msgque.msg_rtime) + 4 : "Not set");
     443                    ? ctime(&msgque.msg_rtime) + 4 : "Not set");
    428444            printf(" %-20.16s\n", msgque.msg_ctime
    429                       ? ctime(&msgque.msg_ctime) + 4 : "Not set");
     445                    ? ctime(&msgque.msg_ctime) + 4 : "Not set");
    430446            break;
    431447        case PID:
     
    444460                printf("%-10d %-10d", msqid, ipcp->uid);
    445461            printf(" %-10o %-12ld %-12ld\n", ipcp->mode & 0777,
    446                       /*
    447                        * glibc-2.1.3 and earlier has unsigned short;
    448                        * glibc-2.1.91 has variation between
    449                        * unsigned short, unsigned long
    450                        * Austin has msgqnum_t
    451                        */
    452                       (long) msgque.msg_cbytes, (long) msgque.msg_qnum);
     462                    /*
     463                     * glibc-2.1.3 and earlier has unsigned short;
     464                     * glibc-2.1.91 has variation between
     465                     * unsigned short, unsigned long
     466                     * Austin has msgqnum_t
     467                     */
     468                    (long) msgque.msg_cbytes, (long) msgque.msg_qnum);
    453469            break;
    454470        }
     
    468484
    469485    printf("\nShared memory Segment shmid=%d\n"
    470               "uid=%d\tgid=%d\tcuid=%d\tcgid=%d\n"
    471               "mode=%#o\taccess_perms=%#o\n"
    472               "bytes=%ld\tlpid=%d\tcpid=%d\tnattch=%ld\n",
    473               shmid,
    474               ipcp->uid, ipcp->gid, ipcp->cuid, ipcp->cgid,
    475               ipcp->mode, ipcp->mode & 0777,
    476               (long) shmds.shm_segsz, shmds.shm_lpid, shmds.shm_cpid,
    477               (long) shmds.shm_nattch);
     486            "uid=%d\tgid=%d\tcuid=%d\tcgid=%d\n"
     487            "mode=%#o\taccess_perms=%#o\n"
     488            "bytes=%ld\tlpid=%d\tcpid=%d\tnattch=%ld\n",
     489            shmid,
     490            ipcp->uid, ipcp->gid, ipcp->cuid, ipcp->cgid,
     491            ipcp->mode, ipcp->mode & 0777,
     492            (long) shmds.shm_segsz, shmds.shm_lpid, shmds.shm_cpid,
     493            (long) shmds.shm_nattch);
    478494    printf("att_time=%-26.24s\n",
    479               shmds.shm_atime ? ctime(&shmds.shm_atime) : "Not set");
     495            shmds.shm_atime ? ctime(&shmds.shm_atime) : "Not set");
    480496    printf("det_time=%-26.24s\n",
    481               shmds.shm_dtime ? ctime(&shmds.shm_dtime) : "Not set");
     497            shmds.shm_dtime ? ctime(&shmds.shm_dtime) : "Not set");
    482498    printf("change_time=%-26.24s\n\n", ctime(&shmds.shm_ctime));
    483499}
     
    495511
    496512    printf("\nMessage Queue msqid=%d\n"
    497               "uid=%d\tgid=%d\tcuid=%d\tcgid=%d\tmode=%#o\n"
    498               "cbytes=%ld\tqbytes=%ld\tqnum=%ld\tlspid=%d\tlrpid=%d\n",
    499               msqid, ipcp->uid, ipcp->gid, ipcp->cuid, ipcp->cgid, ipcp->mode,
    500               /*
    501                * glibc-2.1.3 and earlier has unsigned short;
    502                * glibc-2.1.91 has variation between
    503                * unsigned short, unsigned long
    504                * Austin has msgqnum_t (for msg_qbytes)
    505                */
    506               (long) buf.msg_cbytes, (long) buf.msg_qbytes,
    507               (long) buf.msg_qnum, buf.msg_lspid, buf.msg_lrpid);
     513            "uid=%d\tgid=%d\tcuid=%d\tcgid=%d\tmode=%#o\n"
     514            "cbytes=%ld\tqbytes=%ld\tqnum=%ld\tlspid=%d\tlrpid=%d\n",
     515            msqid, ipcp->uid, ipcp->gid, ipcp->cuid, ipcp->cgid, ipcp->mode,
     516            /*
     517             * glibc-2.1.3 and earlier has unsigned short;
     518             * glibc-2.1.91 has variation between
     519             * unsigned short, unsigned long
     520             * Austin has msgqnum_t (for msg_qbytes)
     521             */
     522            (long) buf.msg_cbytes, (long) buf.msg_qbytes,
     523            (long) buf.msg_qnum, buf.msg_lspid, buf.msg_lrpid);
    508524
    509525    printf("send_time=%-26.24s\n",
    510               buf.msg_stime ? ctime(&buf.msg_stime) : "Not set");
     526            buf.msg_stime ? ctime(&buf.msg_stime) : "Not set");
    511527    printf("rcv_time=%-26.24s\n",
    512               buf.msg_rtime ? ctime(&buf.msg_rtime) : "Not set");
     528            buf.msg_rtime ? ctime(&buf.msg_rtime) : "Not set");
    513529    printf("change_time=%-26.24s\n\n",
    514               buf.msg_ctime ? ctime(&buf.msg_ctime) : "Not set");
     530            buf.msg_ctime ? ctime(&buf.msg_ctime) : "Not set");
    515531}
    516532
     
    529545
    530546    printf("\nSemaphore Array semid=%d\n"
    531               "uid=%d\t gid=%d\t cuid=%d\t cgid=%d\n"
    532               "mode=%#o, access_perms=%#o\n"
    533               "nsems = %ld\n"
    534               "otime = %-26.24s\n",
    535               semid,
    536               ipcp->uid, ipcp->gid, ipcp->cuid, ipcp->cgid,
    537               ipcp->mode, ipcp->mode & 0777,
    538               (long) semds.sem_nsems,
    539               semds.sem_otime ? ctime(&semds.sem_otime) : "Not set");
     547            "uid=%d\t gid=%d\t cuid=%d\t cgid=%d\n"
     548            "mode=%#o, access_perms=%#o\n"
     549            "nsems = %ld\n"
     550            "otime = %-26.24s\n",
     551            semid,
     552            ipcp->uid, ipcp->gid, ipcp->cuid, ipcp->cgid,
     553            ipcp->mode, ipcp->mode & 0777,
     554            (long) semds.sem_nsems,
     555            semds.sem_otime ? ctime(&semds.sem_otime) : "Not set");
    540556    printf("ctime = %-26.24s\n"
    541               "%-10s %-10s %-10s %-10s %-10s\n",
    542               ctime(&semds.sem_ctime),
    543               "semnum", "value", "ncount", "zcount", "pid");
     557            "%-10s %-10s %-10s %-10s %-10s\n",
     558            ctime(&semds.sem_ctime),
     559            "semnum", "value", "ncount", "zcount", "pid");
    544560
    545561    arg.val = 0;
Note: See TracChangeset for help on using the changeset viewer.