Ignore:
Timestamp:
Nov 6, 2007, 11:01:53 AM (12 years ago)
Author:
Bruno Cornec
Message:
  • Better output for mindi-busybox revision
  • Remove dummy file created on NFS - report from Arnaud Tiger <arnaud.tiger_at_hp.com>
  • strace useful for debug
  • fix new versions for pb (2.0.0 for mindi and 1.7.2 for mindi-busybox)
  • fix build process for mindi-busybox + options used in that version (dd for label-partitions-as-necessary)
  • fix typo in label-partitions-as-necessary which doesn't seem to work
  • Update to busybox 1.7.2
  • perl is now required at restore time to support uuid swap partitions (and will be used for many other thigs

in the future for sure)

  • next mindi version will be 2.0.0 due to all the changes made in it (udev may break working distros)
  • small optimization in mindi on keyboard handling (one single find instead of multiple)
  • better interaction for USB device when launching mindi manually
  • attempt to automatically guess block disk size for ramdisk
  • fix typos in bkphw
  • Fix the remaining problem with UUID support for swap partitions
  • Updates mondoarchive man page for USB support
  • Adds preliminary Hardware support to mindi (Proliant SSSTK)
  • Tries to add udev support also for rhel4
  • Fix UUID support which was still broken.
  • Be conservative in test for the start-nfs script
  • Update config file for mindi-busybox for 1.7.2 migration
  • Try to run around a busybox bug (1.2.2 pb on inexistant links)
  • Add build content for mindi-busybox in pb
  • Remove distributions content for mindi-busybox
  • Fix a warning on inexistant raidtab
  • Solve problem on tmpfs in restore init (Problem of inexistant symlink and busybox)
  • Create MONDO_CACHE and use it everywhere + creation at start
  • Really never try to eject a USB device
  • Fix a issue with &> usage (replaced with 1> and 2>)
  • Adds magic file to depllist in order to have file working + ldd which helps for debugging issues
  • tty modes correct to avoid sh error messages
  • Use ext3 normally and not ext2 instead
  • USB device should be corrected after reading (take 1st part)
  • Adds a mount_USB_here function derived from mount_CDROM_here
  • usb detection place before /dev detection in device name at restore time
  • Fix when restoring from USB: media is asked in interactive mode
  • Adds USB support for mondorestore
  • mount_cdrom => mount_media
  • elilo.efi is now searched throughout /boot/efi and not in a fixed place as there is no standard
  • untar-and-softlink => untar (+ interface change)
  • suppress useless softlinks creation/removal in boot process
  • avoids udevd messages on groups
  • Increase # of disks to 99 as in mindi at restore time (should be a conf file parameter)
  • skip existing big file creation
  • seems to work correctly for USB mindi boot
  • Adds group and tty link to udev conf
  • Always load usb-torage (even 2.6) to initiate USB bus discovery
  • Better printing of messages
  • Attempt to fix a bug in supporting OpenSusE 10.3 kernel for initramfs (mindi may now use multiple regex for kernel initrd detection)
  • Links were not correctly done as non relative for modules in mindi
  • exclusion of modules denied now works
  • Also create modules in their ordinary place, so that classical modprobe works + copy modules.dep
  • Fix bugs for DENY_MODS handling
  • Add device /dev/console for udev
  • ide-generic should now really be excluded
  • Fix a bug in major number for tty
  • If udev then adds modprobe/insmod to rootfs
  • tty0 is also cretaed with udev
  • ide-generic put rather in DENY_MODS
  • udevd remove from deplist s handled in mindi directly
  • better default for mindi when using --usb
  • Handles dynamically linked busybox (in case we want to use it soon ;-)
  • Adds fixed devices to create for udev
  • ide-generic should not be part of the initrd when using libata v2
  • support a dynamically linked udev (case on Ubuntu 7.10 and Mandriva 2008.0 so should be quite generic) This will give incitation to move to dyn. linked binaries in the initrd which will help for other tasks (ia6 4)
  • Improvement in udev support (do not use cl options not available in busybox)
  • Udev in mindi
    • auto creation of the right links at boot time with udev-links.conf(from Mandriva 2008.0)
    • rework startup of udev as current makes kernel crash (from Mandriva 2008.0)
    • add support for 64 bits udev
  • Try to render MyInsmod? silent at boot time
  • Adds udev support (mandatory for newest distributions to avoid remapping of devices in a different way as on the original system)
  • We also need vaft format support for USB boot
  • Adds libusual support (Ubuntu 7.10 needs it for USB)
  • Improve Ubuntu/Debian? keyboard detection and support
  • pbinit adapted to new pb (0.8.10). Filtering of docs done in it
  • Suppress some mondo warnings and errors on USB again
  • Tries to fix lack of files in deb mindi package
  • Verify should now work for USB devices
  • More log/mesages improvement for USB support
  • - Supress g_erase_tmpdir_and_scratchdir
  • Improve some log messages for USB support
  • Try to improve install in mindi to avoid issues with isolinux.cfg not installed vene if in the pkg :-(
  • Improve mindi-busybox build
  • In conformity with pb 0.8.9
  • Add support for Ubuntu 7.10 in build process
  • Add USB Key button to Menu UI (CD streamer removed)
  • Attempt to fix error messages on tmp/scratch files at the end by removing those dir at the latest possible.
  • Fix a bug linked to the size of the -E param which could be used (Arnaud Tiger/René? Ribaud).
  • Integrate ~/.pbrc content into mondorescue.pb (required project-builder >= 0.8.7)
  • Put mondorescue in conformity with new pb filtering rules
  • Add USB support at restore time (no test done yet). New start-usb script PB varibale added where useful
  • Unmounting USB device before removal of temporary scratchdir
  • Stil refining USB copy back to mondo (one command was not executed)
  • No need to have the image subdor in the csratchdir when USB.
  • umount the USB partition before attempting to use it
  • Remove useless copy from mindi to mondo at end of USB handling

(risky merge, we are raising the limits of 2 diverging branches. The status of stable is not completely sure as such. Will need lots of tests, but it's not yet done :-()
(merge -r1692:1769 $SVN_M/branches/2.2.5)

File:
1 edited

Legend:

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

    r821 r1770  
     1/* vi: set sw=4 ts=4: */
    12/*
    23 * ipcs.c -- provides information on allocated ipc resources.
     
    89 */
    910
    10 #include <stdio.h>
    11 #include <stdlib.h>
    12 #include <getopt.h>
    13 #include <errno.h>
    14 #include <time.h>
    15 #include <pwd.h>
    16 #include <grp.h>
    17 
    1811/* X/OPEN tells us to use <sys/{types,ipc,sem}.h> for semctl() */
    1912/* X/OPEN tells us to use <sys/{types,ipc,msg}.h> for msgctl() */
     
    2518#include <sys/shm.h>
    2619
    27 #include "busybox.h"
     20#include "libbb.h"
    2821
    2922/*-------------------------------------------------------------------*/
     
    3225#ifndef SHM_DEST
    3326/* shm_mode upper byte flags */
    34 #define SHM_DEST        01000   /* segment will be destroyed on last detach */
    35 #define SHM_LOCKED      02000   /* segment will not be swapped */
     27#define SHM_DEST        01000   /* segment will be destroyed on last detach */
     28#define SHM_LOCKED      02000   /* segment will not be swapped */
    3629#endif
    3730
     
    4639#define SHM_INFO        14
    4740struct shm_info {
    48      int  used_ids;
    49      ulong shm_tot; /* total allocated shm */
    50      ulong shm_rss; /* total resident shm */
    51      ulong shm_swp; /* total swapped shm */
    52      ulong swap_attempts;
    53      ulong swap_successes;
     41    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;
    5447};
    5548#endif
     
    6962   X/OPEN tells us to define it ourselves, but until recently
    7063   Linux include files would also define it. */
    71 #if defined (__GNU_LIBRARY__) && !defined(_SEM_SEMUN_UNDEFINED)
     64#if defined(__GNU_LIBRARY__) && !defined(_SEM_SEMUN_UNDEFINED)
    7265/* union semun is defined by including <sys/sem.h> */
    7366#else
     
    8679   glibc-1.09 has no support for sysv ipc.
    8780   glibc 2 uses __key, __seq */
    88 #if defined (__GNU_LIBRARY__) && __GNU_LIBRARY__ > 1
     81#if defined(__GNU_LIBRARY__) && __GNU_LIBRARY__ > 1
    8982#define KEY __key
    9083#else
     
    9891#define PID 5
    9992
    100 
    101 static void print_perms (int id, struct ipc_perm *ipcp) {
     93static char format;
     94
     95static void print_perms(int id, struct ipc_perm *ipcp)
     96{
    10297    struct passwd *pw;
    10398    struct group *gr;
    10499
    105     bb_printf ("%-10d %-10o", id, ipcp->mode & 0777);
     100    printf("%-10d %-10o", id, ipcp->mode & 0777);
    106101
    107102    if ((pw = getpwuid(ipcp->cuid)))
    108         bb_printf(" %-10s", pw->pw_name);
     103        printf(" %-10s", pw->pw_name);
    109104    else
    110         bb_printf(" %-10d", ipcp->cuid);
     105        printf(" %-10d", ipcp->cuid);
    111106    if ((gr = getgrgid(ipcp->cgid)))
    112         bb_printf(" %-10s", gr->gr_name);
     107        printf(" %-10s", gr->gr_name);
    113108    else
    114         bb_printf(" %-10d", ipcp->cgid);
     109        printf(" %-10d", ipcp->cgid);
    115110
    116111    if ((pw = getpwuid(ipcp->uid)))
    117         bb_printf(" %-10s", pw->pw_name);
     112        printf(" %-10s", pw->pw_name);
    118113    else
    119         bb_printf(" %-10d", ipcp->uid);
     114        printf(" %-10d", ipcp->uid);
    120115    if ((gr = getgrgid(ipcp->gid)))
    121         bb_printf(" %-10s\n", gr->gr_name);
     116        printf(" %-10s\n", gr->gr_name);
    122117    else
    123         bb_printf(" %-10d\n", ipcp->gid);
    124 }
    125 
    126 
    127 static void do_shm (char format)
     118        printf(" %-10d\n", ipcp->gid);
     119}
     120
     121
     122static void do_shm(void)
    128123{
    129124    int maxid, shmid, id;
     
    134129    struct passwd *pw;
    135130
    136     maxid = shmctl (0, SHM_INFO, (struct shmid_ds *) (void *) &shm_info);
     131    maxid = shmctl(0, SHM_INFO, (struct shmid_ds *) (void *) &shm_info);
    137132    if (maxid < 0) {
    138         bb_printf ("kernel not configured for shared memory\n");
     133        printf("kernel not configured for %s\n", "shared memory");
    139134        return;
    140135    }
     
    142137    switch (format) {
    143138    case LIMITS:
    144         bb_printf ("------ Shared Memory Limits --------\n");
    145         if ((shmctl (0, IPC_INFO, (struct shmid_ds *) (void *) &shminfo)) < 0 )
     139        printf("------ Shared Memory %s --------\n", "Limits");
     140        if ((shmctl(0, IPC_INFO, (struct shmid_ds *) (void *) &shminfo)) < 0)
    146141            return;
    147142        /* glibc 2.1.3 and all earlier libc's have ints as fields
    148143           of struct shminfo; glibc 2.1.91 has unsigned long; ach */
    149         bb_printf ("max number of segments = %lu\n"
    150             "max seg size (kbytes) = %lu\n"
    151             "max total shared memory (pages) = %lu\n"
    152             "min seg size (bytes) = %lu\n",
    153             (unsigned long) shminfo.shmmni,
    154             (unsigned long) (shminfo.shmmax >> 10),
    155             (unsigned long) shminfo.shmall,
    156             (unsigned long) shminfo.shmmin);
     144        printf("max number of segments = %lu\n"
     145                  "max seg size (kbytes) = %lu\n"
     146                  "max total shared memory (pages) = %lu\n"
     147                  "min seg size (bytes) = %lu\n",
     148                  (unsigned long) shminfo.shmmni,
     149                  (unsigned long) (shminfo.shmmax >> 10),
     150                  (unsigned long) shminfo.shmall,
     151                  (unsigned long) shminfo.shmmin);
    157152        return;
    158153
    159154    case STATUS:
    160         bb_printf ("------ Shared Memory Status --------\n"
    161             "segments allocated %d\n"
    162             "pages allocated %ld\n"
    163             "pages resident  %ld\n"
    164             "pages swapped   %ld\n"
    165             "Swap performance: %ld attempts\t %ld successes\n",
    166             shm_info.used_ids,
    167             shm_info.shm_tot,
    168             shm_info.shm_rss,
    169             shm_info.shm_swp,
    170             shm_info.swap_attempts, shm_info.swap_successes);
     155        printf("------ Shared Memory %s --------\n", "Status");
     156        printf(   "segments allocated %d\n"
     157                  "pages allocated %ld\n"
     158                  "pages resident  %ld\n"
     159                  "pages swapped   %ld\n"
     160                  "Swap performance: %ld attempts\t%ld successes\n",
     161                  shm_info.used_ids,
     162                  shm_info.shm_tot,
     163                  shm_info.shm_rss,
     164                  shm_info.shm_swp,
     165                  shm_info.swap_attempts, shm_info.swap_successes);
    171166        return;
    172167
    173168    case CREATOR:
    174         bb_printf ("------ Shared Memory Segment Creators/Owners --------\n"
    175             "%-10s %-10s %-10s %-10s %-10s %-10s\n",
    176             "shmid","perms","cuid","cgid","uid","gid");
     169        printf("------ Shared Memory %s --------\n", "Segment Creators/Owners");
     170        printf(   "%-10s %-10s %-10s %-10s %-10s %-10s\n",
     171                  "shmid", "perms", "cuid", "cgid", "uid", "gid");
    177172        break;
    178173
    179174    case TIME:
    180         bb_printf ("------ Shared Memory Attach/Detach/Change Times --------\n"
    181             "%-10s %-10s %-20s %-20s %-20s\n",
    182             "shmid","owner","attached","detached","changed");
     175        printf("------ Shared Memory %s --------\n", "Attach/Detach/Change Times");
     176        printf(   "%-10s %-10s %-20s %-20s %-20s\n",
     177                  "shmid", "owner", "attached", "detached", "changed");
    183178        break;
    184179
    185180    case PID:
    186         bb_printf ("------ Shared Memory Creator/Last-op --------\n"
    187             "%-10s %-10s %-10s %-10s\n",
    188             "shmid","owner","cpid","lpid");
     181        printf("------ Shared Memory %s --------\n", "Creator/Last-op");
     182        printf(   "%-10s %-10s %-10s %-10s\n",
     183                  "shmid", "owner", "cpid", "lpid");
    189184        break;
    190185
    191186    default:
    192         bb_printf ("------ Shared Memory Segments --------\n"
    193             "%-10s %-10s %-10s %-10s %-10s %-10s %-12s\n",
    194             "key","shmid","owner","perms","bytes","nattch","status");
     187        printf("------ Shared Memory %s --------\n", "Segments");
     188        printf(   "%-10s %-10s %-10s %-10s %-10s %-10s %-12s\n",
     189                  "key", "shmid", "owner", "perms", "bytes", "nattch",
     190                  "status");
    195191        break;
    196192    }
    197193
    198194    for (id = 0; id <= maxid; id++) {
    199         shmid = shmctl (id, SHM_STAT, &shmseg);
     195        shmid = shmctl(id, SHM_STAT, &shmseg);
    200196        if (shmid < 0)
    201197            continue;
    202         if (format == CREATOR)  {
    203             print_perms (shmid, ipcp);
     198        if (format == CREATOR) {
     199            print_perms(shmid, ipcp);
    204200            continue;
    205201        }
     
    208204        case TIME:
    209205            if (pw)
    210                 bb_printf ("%-10d %-10.10s", shmid, pw->pw_name);
    211             else
    212                 bb_printf ("%-10d %-10d", shmid, ipcp->uid);
     206                printf("%-10d %-10.10s", shmid, pw->pw_name);
     207            else
     208                printf("%-10d %-10d", shmid, ipcp->uid);
    213209            /* ctime uses static buffer: use separate calls */
    214             bb_printf(" %-20.16s", shmseg.shm_atime
    215                    ? ctime(&shmseg.shm_atime) + 4 : "Not set");
    216             bb_printf(" %-20.16s", shmseg.shm_dtime
    217                    ? ctime(&shmseg.shm_dtime) + 4 : "Not set");
    218             bb_printf(" %-20.16s\n", shmseg.shm_ctime
    219                    ? ctime(&shmseg.shm_ctime) + 4 : "Not set");
     210            printf(" %-20.16s", shmseg.shm_atime
     211                      ? ctime(&shmseg.shm_atime) + 4 : "Not set");
     212            printf(" %-20.16s", shmseg.shm_dtime
     213                      ? ctime(&shmseg.shm_dtime) + 4 : "Not set");
     214            printf(" %-20.16s\n", shmseg.shm_ctime
     215                      ? ctime(&shmseg.shm_ctime) + 4 : "Not set");
    220216            break;
    221217        case PID:
    222218            if (pw)
    223                 bb_printf ("%-10d %-10.10s", shmid, pw->pw_name);
    224             else
    225                 bb_printf ("%-10d %-10d", shmid, ipcp->uid);
    226             bb_printf (" %-10d %-10d\n",
    227                 shmseg.shm_cpid, shmseg.shm_lpid);
     219                printf("%-10d %-10.10s", shmid, pw->pw_name);
     220            else
     221                printf("%-10d %-10d", shmid, ipcp->uid);
     222            printf(" %-10d %-10d\n", shmseg.shm_cpid, shmseg.shm_lpid);
    228223            break;
    229224
    230225        default:
    231                 bb_printf("0x%08x ",ipcp->KEY );
    232             if (pw)
    233                 bb_printf ("%-10d %-10.10s", shmid, pw->pw_name);
    234             else
    235                 bb_printf ("%-10d %-10d", shmid, ipcp->uid);
    236             bb_printf ("%-10o %-10lu %-10ld %-6s %-6s\n",
    237                 ipcp->mode & 0777,
    238                 /*
    239                  * earlier: int, Austin has size_t
    240                  */
    241                 (unsigned long) shmseg.shm_segsz,
    242                 /*
    243                  * glibc-2.1.3 and earlier has unsigned short;
    244                  * Austin has shmatt_t
    245                  */
    246                 (long) shmseg.shm_nattch,
    247                 ipcp->mode & SHM_DEST ? "dest" : " ",
    248                 ipcp->mode & SHM_LOCKED ? "locked" : " ");
    249             break;
    250         }
    251     }
    252     return;
    253 }
    254 
    255 
    256 static void do_sem (char format)
     226            printf("0x%08x ", ipcp->KEY);
     227            if (pw)
     228                printf("%-10d %-10.10s", shmid, pw->pw_name);
     229            else
     230                printf("%-10d %-10d", shmid, ipcp->uid);
     231            printf(" %-10o %-10lu %-10ld %-6s %-6s\n", ipcp->mode & 0777,
     232                      /*
     233                       * earlier: int, Austin has size_t
     234                       */
     235                      (unsigned long) shmseg.shm_segsz,
     236                      /*
     237                       * glibc-2.1.3 and earlier has unsigned short;
     238                       * Austin has shmatt_t
     239                       */
     240                      (long) shmseg.shm_nattch,
     241                      ipcp->mode & SHM_DEST ? "dest" : " ",
     242                      ipcp->mode & SHM_LOCKED ? "locked" : " ");
     243            break;
     244        }
     245    }
     246}
     247
     248
     249static void do_sem(void)
    257250{
    258251    int maxid, semid, id;
     
    263256    union semun arg;
    264257
    265     arg.array = (ushort *)  (void *) &seminfo;
    266     maxid = semctl (0, 0, SEM_INFO, arg);
     258    arg.array = (ushort *) (void *) &seminfo;
     259    maxid = semctl(0, 0, SEM_INFO, arg);
    267260    if (maxid < 0) {
    268         bb_printf ("kernel not configured for semaphores\n");
     261        printf("kernel not configured for %s\n", "semaphores");
    269262        return;
    270263    }
     
    272265    switch (format) {
    273266    case LIMITS:
    274         bb_printf ("------ Semaphore Limits --------\n");
    275         arg.array = (ushort *) (void *) &seminfo; /* damn union */
    276         if ((semctl (0, 0, IPC_INFO, arg)) < 0 )
     267        printf("------ Semaphore %s --------\n", "Limits");
     268        arg.array = (ushort *) (void *) &seminfo;   /* damn union */
     269        if ((semctl(0, 0, IPC_INFO, arg)) < 0)
    277270            return;
    278         bb_printf ("max number of arrays = %d\n"
    279             "max semaphores per array = %d\n"
    280             "max semaphores system wide = %d\n"
    281             "max ops per semop call = %d\n"
    282             "semaphore max value = %d\n",
    283             seminfo.semmni,
    284             seminfo.semmsl,
    285             seminfo.semmns,
    286             seminfo.semopm,
    287             seminfo.semvmx);
     271        printf("max number of arrays = %d\n"
     272                  "max semaphores per array = %d\n"
     273                  "max semaphores system wide = %d\n"
     274                  "max ops per semop call = %d\n"
     275                  "semaphore max value = %d\n",
     276                  seminfo.semmni,
     277                  seminfo.semmsl,
     278                  seminfo.semmns, seminfo.semopm, seminfo.semvmx);
    288279        return;
    289280
    290281    case STATUS:
    291         bb_printf ("------ Semaphore Status --------\n"
    292             "used arrays = %d\n"
    293             "allocated semaphores = %d\n",
    294             seminfo.semusz,
    295             seminfo.semaem);
     282        printf("------ Semaphore %s --------\n", "Status");
     283        printf(   "used arrays = %d\n"
     284                  "allocated semaphores = %d\n",
     285                  seminfo.semusz, seminfo.semaem);
    296286        return;
    297287
    298288    case CREATOR:
    299         bb_printf ("------ Semaphore Arrays Creators/Owners --------\n"
    300             "%-10s %-10s %-10s %-10s %-10s %-10s\n",
    301             "semid","perms","cuid","cgid","uid","gid");
     289        printf("------ Semaphore %s --------\n", "Arrays Creators/Owners");
     290        printf(   "%-10s %-10s %-10s %-10s %-10s %-10s\n",
     291                  "semid", "perms", "cuid", "cgid", "uid", "gid");
    302292        break;
    303293
    304294    case TIME:
    305         bb_printf ("------ Shared Memory Operation/Change Times --------\n"
    306             "%-8s %-10s %-26.24s %-26.24s\n",
    307             "shmid","owner","last-op","last-changed");
     295        printf("------ Shared Memory %s --------\n", "Operation/Change Times");
     296        printf(   "%-8s %-10s %-26.24s %-26.24s\n",
     297                  "shmid", "owner", "last-op", "last-changed");
    308298        break;
    309299
     
    312302
    313303    default:
    314         bb_printf ("------ Semaphore Arrays --------\n"
    315             "%-10s %-10s %-10s %-10s %-10s\n",
    316             "key","semid","owner","perms","nsems");
     304        printf("------ Semaphore %s --------\n", "Arrays");
     305        printf(   "%-10s %-10s %-10s %-10s %-10s\n",
     306                  "key", "semid", "owner", "perms", "nsems");
    317307        break;
    318308    }
     
    320310    for (id = 0; id <= maxid; id++) {
    321311        arg.buf = (struct semid_ds *) &semary;
    322         semid = semctl (id, 0, SEM_STAT, arg);
     312        semid = semctl(id, 0, SEM_STAT, arg);
    323313        if (semid < 0)
    324314            continue;
    325         if (format == CREATOR)  {
    326             print_perms (semid, ipcp);
     315        if (format == CREATOR) {
     316            print_perms(semid, ipcp);
    327317            continue;
    328318        }
     
    331321        case TIME:
    332322            if (pw)
    333                 bb_printf ("%-8d %-10.10s", semid, pw->pw_name);
    334             else
    335                 bb_printf ("%-8d %-10d", semid, ipcp->uid);
    336             bb_printf ("  %-26.24s", semary.sem_otime
    337                 ? ctime(&semary.sem_otime) : "Not set");
    338             bb_printf (" %-26.24s\n", semary.sem_ctime
    339                 ? ctime(&semary.sem_ctime) : "Not set");
     323                printf("%-8d %-10.10s", semid, pw->pw_name);
     324            else
     325                printf("%-8d %-10d", semid, ipcp->uid);
     326            /* ctime uses static buffer: use separate calls */
     327            printf("  %-26.24s", semary.sem_otime
     328                      ? ctime(&semary.sem_otime) : "Not set");
     329            printf(" %-26.24s\n", semary.sem_ctime
     330                      ? ctime(&semary.sem_ctime) : "Not set");
    340331            break;
    341332        case PID:
     
    343334
    344335        default:
    345                 bb_printf("0x%08x ", ipcp->KEY);
    346             if (pw)
    347                 bb_printf ("%-10d %-10.9s", semid, pw->pw_name);
    348             else
    349                 bb_printf ("%-10d %-9d", semid, ipcp->uid);
    350                     bb_printf ("%-10o %-10ld\n",
    351                 ipcp->mode & 0777,
    352                 /*
    353                  * glibc-2.1.3 and earlier has unsigned short;
    354                  * glibc-2.1.91 has variation between
    355                  * unsigned short and unsigned long
    356                  * Austin prescribes unsigned short.
    357                  */
    358                 (long) semary.sem_nsems);
    359             break;
    360         }
    361     }
    362 }
    363 
    364 
    365 static void do_msg (char format)
     336            printf("0x%08x ", ipcp->KEY);
     337            if (pw)
     338                printf("%-10d %-10.9s", semid, pw->pw_name);
     339            else
     340                printf("%-10d %-9d", semid, ipcp->uid);
     341            printf(" %-10o %-10ld\n", ipcp->mode & 0777,
     342                      /*
     343                       * glibc-2.1.3 and earlier has unsigned short;
     344                       * glibc-2.1.91 has variation between
     345                       * unsigned short and unsigned long
     346                       * Austin prescribes unsigned short.
     347                       */
     348                      (long) semary.sem_nsems);
     349            break;
     350        }
     351    }
     352}
     353
     354
     355static void do_msg(void)
    366356{
    367357    int maxid, msqid, id;
     
    371361    struct passwd *pw;
    372362
    373     maxid = msgctl (0, MSG_INFO, (struct msqid_ds *) (void *) &msginfo);
     363    maxid = msgctl(0, MSG_INFO, (struct msqid_ds *) (void *) &msginfo);
    374364    if (maxid < 0) {
    375         bb_printf ("kernel not configured for message queues\n");
     365        printf("kernel not configured for %s\n", "message queues");
    376366        return;
    377367    }
     
    379369    switch (format) {
    380370    case LIMITS:
    381         if ((msgctl (0, IPC_INFO, (struct msqid_ds *) (void *) &msginfo)) < 0 )
     371        if ((msgctl(0, IPC_INFO, (struct msqid_ds *) (void *) &msginfo)) < 0)
    382372            return;
    383         bb_printf ("------ Messages: Limits --------\n"
    384             "max queues system wide = %d\n"
    385             "max size of message (bytes) = %d\n"
    386             "default max size of queue (bytes) = %d\n",
    387             msginfo.msgmni,
    388             msginfo.msgmax,
    389             msginfo.msgmnb);
     373        printf("------ Message%s --------\n", "s: Limits");
     374        printf(   "max queues system wide = %d\n"
     375                  "max size of message (bytes) = %d\n"
     376                  "default max size of queue (bytes) = %d\n",
     377                  msginfo.msgmni, msginfo.msgmax, msginfo.msgmnb);
    390378        return;
    391379
    392380    case STATUS:
    393         bb_printf ("------ Messages: Status --------\n"
    394             "allocated queues = %d\n"
    395             "used headers = %d\n"
    396             "used space = %d bytes\n",
    397             msginfo.msgpool,
    398             msginfo.msgmap,
    399             msginfo.msgtql);
     381        printf("------ Message%s --------\n", "s: Status");
     382        printf(   "allocated queues = %d\n"
     383                  "used headers = %d\n"
     384                  "used space = %d bytes\n",
     385                  msginfo.msgpool, msginfo.msgmap, msginfo.msgtql);
    400386        return;
    401387
    402388    case CREATOR:
    403         bb_printf ("------ Message Queues: Creators/Owners --------\n"
    404             "%-10s %-10s %-10s %-10s %-10s %-10s\n",
    405             "msqid","perms","cuid","cgid","uid","gid");
     389        printf("------ Message%s --------\n", " Queues: Creators/Owners");
     390        printf(   "%-10s %-10s %-10s %-10s %-10s %-10s\n",
     391                  "msqid", "perms", "cuid", "cgid", "uid", "gid");
    406392        break;
    407393
    408394    case TIME:
    409         bb_printf ("------ Message Queues Send/Recv/Change Times --------\n"
    410             "%-8s %-10s %-20s %-20s %-20s\n",
    411             "msqid","owner","send","recv","change");
     395        printf("------ Message%s --------\n", " Queues Send/Recv/Change Times");
     396        printf(   "%-8s %-10s %-20s %-20s %-20s\n",
     397                  "msqid", "owner", "send", "recv", "change");
    412398        break;
    413399
    414400    case PID:
    415         bb_printf ("------ Message Queues PIDs --------\n"
    416             "%-10s %-10s %-10s %-10s\n",
    417             "msqid","owner","lspid","lrpid");
     401        printf("------ Message%s --------\n", " Queues PIDs");
     402        printf(   "%-10s %-10s %-10s %-10s\n",
     403                  "msqid", "owner", "lspid", "lrpid");
    418404        break;
    419405
    420406    default:
    421         bb_printf ("------ Message Queues --------\n"
    422             "%-10s %-10s %-10s %-10s %-12s %-12s\n",
    423             "key","msqid","owner","perms","used-bytes","messages");
     407        printf("------ Message%s --------\n", " Queues");
     408        printf(   "%-10s %-10s %-10s %-10s %-12s %-12s\n",
     409                  "key", "msqid", "owner", "perms", "used-bytes", "messages");
    424410        break;
    425411    }
    426412
    427413    for (id = 0; id <= maxid; id++) {
    428         msqid = msgctl (id, MSG_STAT, &msgque);
     414        msqid = msgctl(id, MSG_STAT, &msgque);
    429415        if (msqid < 0)
    430416            continue;
    431         if (format == CREATOR)  {
    432             print_perms (msqid, ipcp);
     417        if (format == CREATOR) {
     418            print_perms(msqid, ipcp);
    433419            continue;
    434420        }
     
    437423        case TIME:
    438424            if (pw)
    439                 bb_printf ("%-8d %-10.10s", msqid, pw->pw_name);
    440             else
    441                 bb_printf ("%-8d %-10d", msqid, ipcp->uid);
    442             bb_printf (" %-20.16s", msgque.msg_stime
    443                 ? ctime(&msgque.msg_stime) + 4 : "Not set");
    444             bb_printf (" %-20.16s", msgque.msg_rtime
    445                 ? ctime(&msgque.msg_rtime) + 4 : "Not set");
    446             bb_printf (" %-20.16s\n", msgque.msg_ctime
    447                 ? ctime(&msgque.msg_ctime) + 4 : "Not set");
     425                printf("%-8d %-10.10s", msqid, pw->pw_name);
     426            else
     427                printf("%-8d %-10d", msqid, ipcp->uid);
     428            printf(" %-20.16s", msgque.msg_stime
     429                      ? ctime(&msgque.msg_stime) + 4 : "Not set");
     430            printf(" %-20.16s", msgque.msg_rtime
     431                      ? ctime(&msgque.msg_rtime) + 4 : "Not set");
     432            printf(" %-20.16s\n", msgque.msg_ctime
     433                      ? ctime(&msgque.msg_ctime) + 4 : "Not set");
    448434            break;
    449435        case PID:
    450436            if (pw)
    451                 bb_printf ("%-8d %-10.10s", msqid, pw->pw_name);
    452             else
    453                 bb_printf ("%-8d %-10d", msqid, ipcp->uid);
    454             bb_printf ("  %5d     %5d\n",
    455                 msgque.msg_lspid, msgque.msg_lrpid);
     437                printf("%-8d %-10.10s", msqid, pw->pw_name);
     438            else
     439                printf("%-8d %-10d", msqid, ipcp->uid);
     440            printf("  %5d     %5d\n", msgque.msg_lspid, msgque.msg_lrpid);
    456441            break;
    457442
    458443        default:
    459                 bb_printf( "0x%08x ",ipcp->KEY );
    460             if (pw)
    461                 bb_printf ("%-10d %-10.10s", msqid, pw->pw_name);
    462             else
    463                 bb_printf ("%-10d %-10d", msqid, ipcp->uid);
    464                     bb_printf (" %-10o %-12ld %-12ld\n",
    465                 ipcp->mode & 0777,
    466                 /*
    467                  * glibc-2.1.3 and earlier has unsigned short;
    468                  * glibc-2.1.91 has variation between
    469                  * unsigned short, unsigned long
    470                  * Austin has msgqnum_t
    471                  */
    472                 (long) msgque.msg_cbytes,
    473                 (long) msgque.msg_qnum);
    474             break;
    475         }
    476     }
    477     return;
    478 }
    479 
    480 
    481 static void print_shm (int shmid)
     444            printf("0x%08x ", ipcp->KEY);
     445            if (pw)
     446                printf("%-10d %-10.10s", msqid, pw->pw_name);
     447            else
     448                printf("%-10d %-10d", msqid, ipcp->uid);
     449            printf(" %-10o %-12ld %-12ld\n", ipcp->mode & 0777,
     450                      /*
     451                       * glibc-2.1.3 and earlier has unsigned short;
     452                       * glibc-2.1.91 has variation between
     453                       * unsigned short, unsigned long
     454                       * Austin has msgqnum_t
     455                       */
     456                      (long) msgque.msg_cbytes, (long) msgque.msg_qnum);
     457            break;
     458        }
     459    }
     460}
     461
     462
     463static void print_shm(int shmid)
    482464{
    483465    struct shmid_ds shmds;
    484466    struct ipc_perm *ipcp = &shmds.shm_perm;
    485467
    486     if (shmctl (shmid, IPC_STAT, &shmds) == -1) {
    487         perror ("shmctl ");
    488         return;
    489     }
    490 
    491     bb_printf ("\nShared memory Segment shmid=%d\n"
    492         "uid=%d\tgid=%d\tcuid=%d\tcgid=%d\n"
    493         "mode=%#o\taccess_perms=%#o\n"
    494         "bytes=%ld\tlpid=%d\tcpid=%d\tnattch=%ld\n"
    495         "att_time=%-26.24s\n"
    496         "det_time=%-26.24s\n"
    497         "change_time=%-26.24s\n"
    498         "\n",
    499         shmid,
    500         ipcp->uid, ipcp->gid, ipcp->cuid, ipcp->cgid,
    501         ipcp->mode, ipcp->mode & 0777,
    502         (long) shmds.shm_segsz, shmds.shm_lpid, shmds.shm_cpid,
    503         (long) shmds.shm_nattch,
    504         shmds.shm_atime ? ctime (&shmds.shm_atime) : "Not set",
    505         shmds.shm_dtime ? ctime (&shmds.shm_dtime) : "Not set",
    506         ctime (&shmds.shm_ctime));
    507     return;
    508 }
    509 
    510 
    511 static void print_msg (int msqid)
     468    if (shmctl(shmid, IPC_STAT, &shmds) == -1) {
     469        bb_perror_msg("shmctl");
     470        return;
     471    }
     472
     473    printf("\nShared memory Segment shmid=%d\n"
     474              "uid=%d\tgid=%d\tcuid=%d\tcgid=%d\n"
     475              "mode=%#o\taccess_perms=%#o\n"
     476              "bytes=%ld\tlpid=%d\tcpid=%d\tnattch=%ld\n",
     477              shmid,
     478              ipcp->uid, ipcp->gid, ipcp->cuid, ipcp->cgid,
     479              ipcp->mode, ipcp->mode & 0777,
     480              (long) shmds.shm_segsz, shmds.shm_lpid, shmds.shm_cpid,
     481              (long) shmds.shm_nattch);
     482    printf("att_time=%-26.24s\n",
     483              shmds.shm_atime ? ctime(&shmds.shm_atime) : "Not set");
     484    printf("det_time=%-26.24s\n",
     485              shmds.shm_dtime ? ctime(&shmds.shm_dtime) : "Not set");
     486    printf("change_time=%-26.24s\n\n", ctime(&shmds.shm_ctime));
     487}
     488
     489
     490static void print_msg(int msqid)
    512491{
    513492    struct msqid_ds buf;
    514493    struct ipc_perm *ipcp = &buf.msg_perm;
    515494
    516     if (msgctl (msqid, IPC_STAT, &buf) == -1) {
    517         perror ("msgctl ");
    518         return;
    519     }
    520 
    521     bb_printf ("\nMessage Queue msqid=%d\n"
    522         "uid=%d\tgid=%d\tcuid=%d\tcgid=%d\tmode=%#o\n"
    523         "cbytes=%ld\tqbytes=%ld\tqnum=%ld\tlspid=%d\tlrpid=%d\n"
    524         "send_time=%-26.24s\n"
    525         "rcv_time=%-26.24s\n"
    526         "change_time=%-26.24s\n"
    527         "\n",
    528         msqid,
    529         ipcp->uid, ipcp->gid, ipcp->cuid, ipcp->cgid, ipcp->mode,
    530         /*
    531          * glibc-2.1.3 and earlier has unsigned short;
    532          * glibc-2.1.91 has variation between
    533          * unsigned short, unsigned long
    534          * Austin has msgqnum_t (for msg_qbytes)
    535          */
    536         (long) buf.msg_cbytes, (long) buf.msg_qbytes,
    537         (long) buf.msg_qnum, buf.msg_lspid, buf.msg_lrpid,
    538         buf.msg_stime ? ctime (&buf.msg_stime) : "Not set",
    539         buf.msg_rtime ? ctime (&buf.msg_rtime) : "Not set",
    540         buf.msg_ctime ? ctime (&buf.msg_ctime) : "Not set");
    541     return;
    542 }
    543 
    544 static void print_sem (int semid)
     495    if (msgctl(msqid, IPC_STAT, &buf) == -1) {
     496        bb_perror_msg("msgctl");
     497        return;
     498    }
     499
     500    printf("\nMessage Queue msqid=%d\n"
     501              "uid=%d\tgid=%d\tcuid=%d\tcgid=%d\tmode=%#o\n"
     502              "cbytes=%ld\tqbytes=%ld\tqnum=%ld\tlspid=%d\tlrpid=%d\n",
     503              msqid, ipcp->uid, ipcp->gid, ipcp->cuid, ipcp->cgid, ipcp->mode,
     504              /*
     505               * glibc-2.1.3 and earlier has unsigned short;
     506               * glibc-2.1.91 has variation between
     507               * unsigned short, unsigned long
     508               * Austin has msgqnum_t (for msg_qbytes)
     509               */
     510              (long) buf.msg_cbytes, (long) buf.msg_qbytes,
     511              (long) buf.msg_qnum, buf.msg_lspid, buf.msg_lrpid);
     512
     513    printf("send_time=%-26.24s\n",
     514              buf.msg_stime ? ctime(&buf.msg_stime) : "Not set");
     515    printf("rcv_time=%-26.24s\n",
     516              buf.msg_rtime ? ctime(&buf.msg_rtime) : "Not set");
     517    printf("change_time=%-26.24s\n\n",
     518              buf.msg_ctime ? ctime(&buf.msg_ctime) : "Not set");
     519}
     520
     521static void print_sem(int semid)
    545522{
    546523    struct semid_ds semds;
     
    550527
    551528    arg.buf = &semds;
    552     if (semctl (semid, 0, IPC_STAT, arg) < 0) {
    553         perror ("semctl ");
    554         return;
    555     }
    556 
    557     bb_printf ("\nSemaphore Array semid=%d\n"
    558         "uid=%d\t gid=%d\t cuid=%d\t cgid=%d\n"
    559         "mode=%#o, access_perms=%#o\n"
    560         "nsems = %ld\n"
    561         "otime = %-26.24s\n"
    562         "ctime = %-26.24s\n"
    563         "%-10s %-10s %-10s %-10s %-10s\n",
    564         semid,
    565         ipcp->uid, ipcp->gid, ipcp->cuid, ipcp->cgid,
    566         ipcp->mode, ipcp->mode & 0777,
    567         (long) semds.sem_nsems,
    568         semds.sem_otime ? ctime (&semds.sem_otime) : "Not set",
    569         ctime (&semds.sem_ctime),
    570         "semnum","value","ncount","zcount","pid");
     529    if (semctl(semid, 0, IPC_STAT, arg)) {
     530        bb_perror_msg("semctl");
     531        return;
     532    }
     533
     534    printf("\nSemaphore Array semid=%d\n"
     535              "uid=%d\t gid=%d\t cuid=%d\t cgid=%d\n"
     536              "mode=%#o, access_perms=%#o\n"
     537              "nsems = %ld\n"
     538              "otime = %-26.24s\n",
     539              semid,
     540              ipcp->uid, ipcp->gid, ipcp->cuid, ipcp->cgid,
     541              ipcp->mode, ipcp->mode & 0777,
     542              (long) semds.sem_nsems,
     543              semds.sem_otime ? ctime(&semds.sem_otime) : "Not set");
     544    printf("ctime = %-26.24s\n"
     545              "%-10s %-10s %-10s %-10s %-10s\n",
     546              ctime(&semds.sem_ctime),
     547              "semnum", "value", "ncount", "zcount", "pid");
    571548
    572549    arg.val = 0;
    573     for (i=0; i < semds.sem_nsems; i++) {
     550    for (i = 0; i < semds.sem_nsems; i++) {
    574551        int val, ncnt, zcnt, pid;
    575         val = semctl (semid, i, GETVAL, arg);
    576         ncnt = semctl (semid, i, GETNCNT, arg);
    577         zcnt = semctl (semid, i, GETZCNT, arg);
    578         pid = semctl (semid, i, GETPID, arg);
     552
     553        val = semctl(semid, i, GETVAL, arg);
     554        ncnt = semctl(semid, i, GETNCNT, arg);
     555        zcnt = semctl(semid, i, GETZCNT, arg);
     556        pid = semctl(semid, i, GETPID, arg);
    579557        if (val < 0 || ncnt < 0 || zcnt < 0 || pid < 0) {
    580             perror ("semctl ");
    581             bb_fflush_stdout_and_exit (1);
    582         }
    583         bb_printf ("%-10d %-10d %-10d %-10d %-10d\n",
    584             i, val, ncnt, zcnt, pid);
    585     }
    586     bb_printf ("\n");
    587     return;
    588 }
    589 
    590 int ipcs_main (int argc, char **argv) {
    591     int opt, msg = 0, sem = 0, shm = 0, id=0, print=0;
    592     char format = 0;
    593     char options[] = "atclupsmqi:ih?";
    594 
    595     while ((opt = getopt (argc, argv, options)) != -1) {
    596         switch (opt) {
    597         case 'i':
    598             id = atoi (optarg);
    599             print = 1;
    600             break;
    601         case 'a':
    602             msg = shm = sem = 1;
    603             break;
    604         case 'q':
    605             msg = 1;
    606             break;
    607         case 's':
    608             sem = 1;
    609             break;
    610         case 'm':
    611             shm = 1;
    612             break;
    613         case 't':
    614             format = TIME;
    615             break;
    616         case 'c':
    617             format = CREATOR;
    618             break;
    619         case 'p':
    620             format = PID;
    621             break;
    622         case 'l':
    623             format = LIMITS;
    624             break;
    625         case 'u':
    626             format = STATUS;
    627             break;
    628         case 'h':
    629         case '?':
    630             bb_show_usage();
    631             bb_fflush_stdout_and_exit (0);
    632         }
    633     }
    634 
    635     if  (print) {
    636         if (shm) {
    637             print_shm (id);
    638             bb_fflush_stdout_and_exit (0);
    639         }
    640         if (sem) {
    641             print_sem (id);
    642             bb_fflush_stdout_and_exit (0);
    643         }
    644         if (msg) {
    645             print_msg (id);
    646             bb_fflush_stdout_and_exit (0);
     558            bb_perror_msg_and_die("semctl");
     559        }
     560        printf("%-10d %-10d %-10d %-10d %-10d\n", i, val, ncnt, zcnt, pid);
     561    }
     562    puts("");
     563}
     564
     565int ipcs_main(int argc, char **argv);
     566int ipcs_main(int argc, char **argv)
     567{
     568    int id = 0;
     569    unsigned flags = 0;
     570    unsigned opt;
     571    char *opt_i;
     572#define flag_print  (1<<0)
     573#define flag_msg    (1<<1)
     574#define flag_sem    (1<<2)
     575#define flag_shm    (1<<3)
     576
     577    opt = getopt32(argv, "i:aqsmtcplu", &opt_i);
     578    if (opt & 0x1) { // -i
     579        id = xatoi(opt_i);
     580        flags |= flag_print;
     581    }
     582    if (opt & 0x2) flags |= flag_msg | flag_sem | flag_shm; // -a
     583    if (opt & 0x4) flags |= flag_msg; // -q
     584    if (opt & 0x8) flags |= flag_sem; // -s
     585    if (opt & 0x10) flags |= flag_shm; // -m
     586    if (opt & 0x20) format = TIME; // -t
     587    if (opt & 0x40) format = CREATOR; // -c
     588    if (opt & 0x80) format = PID; // -p
     589    if (opt & 0x100) format = LIMITS; // -l
     590    if (opt & 0x200) format = STATUS; // -u
     591
     592    if (flags & flag_print) {
     593        if (flags & flag_shm) {
     594            print_shm(id);
     595            fflush_stdout_and_exit(0);
     596        }
     597        if (flags & flag_sem) {
     598            print_sem(id);
     599            fflush_stdout_and_exit(0);
     600        }
     601        if (flags & flag_msg) {
     602            print_msg(id);
     603            fflush_stdout_and_exit(0);
    647604        }
    648605        bb_show_usage();
    649         bb_fflush_stdout_and_exit (0);
    650     }
    651 
    652     if ( !shm && !msg && !sem)
    653         msg = sem = shm = 1;
    654     bb_printf ("\n");
    655 
    656     if (shm) {
    657         do_shm (format);
    658         bb_printf ("\n");
    659     }
    660     if (sem) {
    661         do_sem (format);
    662         bb_printf ("\n");
    663     }
    664     if (msg) {
    665         do_msg (format);
    666         bb_printf ("\n");
    667     }
    668     return 0;
    669 }
    670 
     606    }
     607
     608    if (!(flags & (flag_shm | flag_msg | flag_sem)))
     609        flags |= flag_msg | flag_shm | flag_sem;
     610    puts("");
     611
     612    if (flags & flag_shm) {
     613        do_shm();
     614        puts("");
     615    }
     616    if (flags & flag_sem) {
     617        do_sem();
     618        puts("");
     619    }
     620    if (flags & flag_msg) {
     621        do_msg();
     622        puts("");
     623    }
     624    fflush_stdout_and_exit(0);
     625}
Note: See TracChangeset for help on using the changeset viewer.