summaryrefslogtreecommitdiff
path: root/util-linux
diff options
context:
space:
mode:
authorBernhard Reutner-Fischer2006-08-28 23:31:54 +0000
committerBernhard Reutner-Fischer2006-08-28 23:31:54 +0000
commit73561cc75ac31e63bcab4b4ebfaf738e4ca225e6 (patch)
tree2a57564b8917a983365c765d4daa83032d9f0a17 /util-linux
parent6ce8dae1d5a201156a83201de6c49cdcc4c8df3e (diff)
downloadbusybox-73561cc75ac31e63bcab4b4ebfaf738e4ca225e6.zip
busybox-73561cc75ac31e63bcab4b4ebfaf738e4ca225e6.tar.gz
- pull from busybox_scratch: r15829:15850
Various fixes, cleanups and shrinkage: saves 952 Bytes: text data bss dec hex filename 1087742 15853 790632 1894227 1ce753 ../busybox/busybox.old 1086790 15853 790632 1893275 1ce39b busybox via: # scripts/bloat-o-meter ../busybox/busybox_unstripped.old busybox_unstripped function old new delta ipcrm_main 756 822 +66 getval - 61 +61 maybe_set_utc - 40 +40 udhcpc_main 2896 2912 +16 md5_hash_block 428 437 +9 opt 8 16 +8 qgravechar 106 110 +4 make_bitmap 292 295 +3 inflate_unzip 2056 2059 +3 add_partition 1412 1414 +2 __parsespent 156 158 +2 qrealloc 41 42 +1 format - 1 +1 catv_main 313 314 +1 watch_main 293 292 -1 varunset 81 80 -1 part 1 - -1 check_if_skip 837 836 -1 start_stop_daemon_main 840 837 -3 create_lost_and_found 175 172 -3 supress_non_delimited_lines 4 - -4 static.l 4 - -4 static.c 5 1 -4 bsd_sum_file 237 233 -4 eval2 338 332 -6 arithmetic_common 166 158 -8 cmpfunc 22 5 -17 cksum_main 294 275 -19 cmp_main 465 439 -26 dd_main 1535 1508 -27 rmmod_main 376 333 -43 cut_file 727 644 -83 ipcs_main 3809 3721 -88 cut_main 722 614 -108 date_main 1443 1263 -180 remove_ids 222 - -222 ------------------------------------------------------------------------------ (add/remove: 3/4 grow/shrink: 11/18 up/down: 217/-853) Total: -636 bytes
Diffstat (limited to 'util-linux')
-rw-r--r--util-linux/ipcrm.c216
-rw-r--r--util-linux/ipcs.c584
2 files changed, 363 insertions, 437 deletions
diff --git a/util-linux/ipcrm.c b/util-linux/ipcrm.c
index 2e164b8..735a895 100644
--- a/util-linux/ipcrm.c
+++ b/util-linux/ipcrm.c
@@ -1,56 +1,22 @@
/* vi: set sw=4 ts=4: */
/*
- * ipcrm.c -- utility to allow removal of IPC objects and data structures.
+ * ipcrm.c - utility to allow removal of IPC objects and data structures.
*
* 01 Sept 2004 - Rodney Radford <rradford@mindspring.com>
* Adapted for busybox from util-linux-2.12a.
*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * --- Pre-busybox history from util-linux-2.12a ------------------------
- *
- * 1999-04-02 frank zago
- * - can now remove several id's in the same call
- *
- * 1999-02-22 Arkadiusz Mi˙kiewicz <misiek@pld.ORG.PL>
- * - added Native Language Support
- *
- * Original author - krishna balasubramanian 1993
+ * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
+#include "busybox.h"
-#include <sys/types.h>
+/* 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() */
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/msg.h>
#include <sys/sem.h>
-/* 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() */
-/* for getopt */
-#include <unistd.h>
-
-/* for tolower and isupper */
-#include <ctype.h>
-
-#include "busybox.h"
-
#if defined (__GNU_LIBRARY__) && !defined(_SEM_SEMUN_UNDEFINED)
/* union semun is defined by including <sys/sem.h> */
#else
@@ -63,164 +29,149 @@ union semun {
};
#endif
+#ifndef CONFIG_IPCRM_DROP_LEGACY
+
typedef enum type_id {
SHM,
SEM,
MSG
} type_id;
-static int
-remove_ids(type_id type, int argc, char **argv) {
+static int remove_ids(type_id type, int argc, char **argv)
+{
int id;
- int ret = 0; /* for gcc */
+ int ret = 0; /* silence gcc */
char *end;
int nb_errors = 0;
union semun arg;
arg.val = 0;
- while(argc) {
+ while (argc) {
id = strtoul(argv[0], &end, 10);
if (*end != 0) {
- bb_printf ("invalid id: %s\n", argv[0]);
- nb_errors ++;
+ bb_error_msg("invalid id: %s", argv[0]);
+ nb_errors++;
} else {
- switch(type) {
- case SEM:
- ret = semctl (id, 0, IPC_RMID, arg);
- break;
-
- case MSG:
- ret = msgctl (id, IPC_RMID, NULL);
- break;
-
- case SHM:
- ret = shmctl (id, IPC_RMID, NULL);
- break;
- }
+ if (type == SEM)
+ ret = semctl(id, 0, IPC_RMID, arg);
+ else if (type == MSG)
+ ret = msgctl(id, IPC_RMID, NULL);
+ else if (type == SHM)
+ ret = shmctl(id, IPC_RMID, NULL);
if (ret) {
- bb_printf ("cannot remove id %s (%s)\n",
- argv[0], strerror(errno));
- nb_errors ++;
+ bb_perror_msg("cannot remove id %s", argv[0]);
+ nb_errors++;
}
}
argc--;
argv++;
}
- return(nb_errors);
-}
-
-static int deprecated_main(int argc, char **argv)
-{
- if (argc < 3) {
- bb_show_usage();
- bb_fflush_stdout_and_exit(1);
- }
-
- if (!strcmp(argv[1], "shm")) {
- if (remove_ids(SHM, argc-2, &argv[2]))
- bb_fflush_stdout_and_exit(1);
- }
- else if (!strcmp(argv[1], "msg")) {
- if (remove_ids(MSG, argc-2, &argv[2]))
- bb_fflush_stdout_and_exit(1);
- }
- else if (!strcmp(argv[1], "sem")) {
- if (remove_ids(SEM, argc-2, &argv[2]))
- bb_fflush_stdout_and_exit(1);
- }
- else {
- bb_printf ("unknown resource type: %s\n", argv[1]);
- bb_show_usage();
- bb_fflush_stdout_and_exit(1);
- }
-
- bb_printf ("resource(s) deleted\n");
- return 0;
+ return (nb_errors);
}
+#endif /* #ifndef CONFIG_IPCRM_DROP_LEGACY */
int ipcrm_main(int argc, char **argv)
{
- int c;
- int error = 0;
- char *prog = argv[0];
+ int c;
+ int error = 0;
/* if the command is executed without parameters, do nothing */
if (argc == 1)
return 0;
-
+#ifndef CONFIG_IPCRM_DROP_LEGACY
/* check to see if the command is being invoked in the old way if so
- then run the old code */
- if (strcmp(argv[1], "shm") == 0 ||
- strcmp(argv[1], "msg") == 0 ||
- strcmp(argv[1], "sem") == 0)
- return deprecated_main(argc, argv);
+ then run the old code. Valid commands are msg, shm, sem. */
+ {
+ type_id what = 0; /* silence gcc */
+ char w;
+
+ if ((((w=argv[1][0]) == 'm' && argv[1][1] == 's' && argv[1][2] == 'g')
+ || (argv[1][0] == 's'
+ && ((w=argv[1][1]) == 'h' || w == 'e')
+ && argv[1][2] == 'm'))
+ && argv[1][3] == '\0') {
+
+ if (argc < 3)
+ bb_show_usage();
+
+ if (w == 'h')
+ what = SHM;
+ else if (w == 'm')
+ what = MSG;
+ else if (w == 'e')
+ what = SEM;
+
+ if (remove_ids(what, argc-2, &argv[2]))
+ bb_fflush_stdout_and_exit(1);
+ bb_printf("resource(s) deleted\n");
+ return 0;
+ }
+ }
+#endif /* #ifndef CONFIG_IPCRM_DROP_LEGACY */
/* process new syntax to conform with SYSV ipcrm */
while ((c = getopt(argc, argv, "q:m:s:Q:M:S:h?")) != -1) {
int result;
int id = 0;
- int iskey = isupper(c);
+ int iskey = (isupper)(c);
/* needed to delete semaphores */
union semun arg;
+
arg.val = 0;
- if ((c == '?') || (c == 'h'))
- {
+ if ((c == '?') || (c == 'h')) {
bb_show_usage();
- return 0;
}
/* we don't need case information any more */
c = tolower(c);
- /* make sure the option is in range */
+ /* make sure the option is in range: allowed are q, m, s */
if (c != 'q' && c != 'm' && c != 's') {
bb_show_usage();
- error++;
- return error;
}
if (iskey) {
/* keys are in hex or decimal */
key_t key = strtoul(optarg, NULL, 0);
+
if (key == IPC_PRIVATE) {
error++;
- bb_fprintf(stderr, "%s: illegal key (%s)\n",
- prog, optarg);
+ bb_error_msg("illegal key (%s)", optarg);
continue;
}
/* convert key to id */
id = ((c == 'q') ? msgget(key, 0) :
- (c == 'm') ? shmget(key, 0, 0) :
- semget(key, 0, 0));
+ (c == 'm') ? shmget(key, 0, 0) : semget(key, 0, 0));
if (id < 0) {
char *errmsg;
+ const char * const what = "key";
+
error++;
- switch(errno) {
+ switch (errno) {
case EACCES:
- errmsg = "permission denied for key";
+ errmsg = "permission denied for";
break;
case EIDRM:
- errmsg = "already removed key";
+ errmsg = "already removed";
break;
case ENOENT:
- errmsg = "invalid key";
+ errmsg = "invalid";
break;
default:
- errmsg = "unknown error in key";
+ errmsg = "unknown error in";
break;
}
- bb_fprintf(stderr, "%s: %s (%s)\n",
- prog, errmsg, optarg);
+ bb_error_msg("%s %s (%s)", errmsg, what, optarg);
continue;
}
} else {
@@ -229,37 +180,30 @@ int ipcrm_main(int argc, char **argv)
}
result = ((c == 'q') ? msgctl(id, IPC_RMID, NULL) :
- (c == 'm') ? shmctl(id, IPC_RMID, NULL) :
- semctl(id, 0, IPC_RMID, arg));
+ (c == 'm') ? shmctl(id, IPC_RMID, NULL) :
+ semctl(id, 0, IPC_RMID, arg));
- if (result < 0) {
+ if (result) {
char *errmsg;
+ const char * const what = iskey ? "key" : "id";
+
error++;
- switch(errno) {
+ switch (errno) {
case EACCES:
case EPERM:
- errmsg = iskey
- ? "permission denied for key"
- : "permission denied for id";
+ errmsg = "permission denied for";
break;
case EINVAL:
- errmsg = iskey
- ? "invalid key"
- : "invalid id";
+ errmsg = "invalid";
break;
case EIDRM:
- errmsg = iskey
- ? "already removed key"
- : "already removed id";
+ errmsg = "already removed";
break;
default:
- errmsg = iskey
- ? "unknown error in key"
- : "unknown error in id";
+ errmsg = "unknown error in";
break;
}
- bb_fprintf(stderr, "%s: %s (%s)\n",
- prog, errmsg, optarg);
+ bb_error_msg("%s %s (%s)", errmsg, what, optarg);
continue;
}
}
diff --git a/util-linux/ipcs.c b/util-linux/ipcs.c
index fbc75cb..c7c8376 100644
--- a/util-linux/ipcs.c
+++ b/util-linux/ipcs.c
@@ -8,9 +8,7 @@
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
-#include <stdio.h>
-#include <stdlib.h>
-#include <getopt.h>
+#include "busybox.h"
#include <errno.h>
#include <time.h>
#include <pwd.h>
@@ -25,15 +23,15 @@
#include <sys/msg.h>
#include <sys/shm.h>
-#include "busybox.h"
+
/*-------------------------------------------------------------------*/
/* SHM_DEST and SHM_LOCKED are defined in kernel headers,
but inside #ifdef __KERNEL__ ... #endif */
#ifndef SHM_DEST
/* shm_mode upper byte flags */
-#define SHM_DEST 01000 /* segment will be destroyed on last detach */
-#define SHM_LOCKED 02000 /* segment will not be swapped */
+#define SHM_DEST 01000 /* segment will be destroyed on last detach */
+#define SHM_LOCKED 02000 /* segment will not be swapped */
#endif
/* For older kernels the same holds for the defines below */
@@ -46,12 +44,12 @@
#define SHM_STAT 13
#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;
+ 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;
};
#endif
@@ -98,12 +96,14 @@ union semun {
#define TIME 4
#define PID 5
+static char format;
-static void print_perms (int id, struct ipc_perm *ipcp) {
+static void print_perms(int id, struct ipc_perm *ipcp)
+{
struct passwd *pw;
struct group *gr;
- bb_printf ("%-10d %-10o", id, ipcp->mode & 0777);
+ bb_printf("%-10d %-10o", id, ipcp->mode & 0777);
if ((pw = getpwuid(ipcp->cuid)))
bb_printf(" %-10s", pw->pw_name);
@@ -125,7 +125,7 @@ static void print_perms (int id, struct ipc_perm *ipcp) {
}
-static void do_shm (char format)
+static void do_shm(void)
{
int maxid, shmid, id;
struct shmid_ds shmseg;
@@ -134,127 +134,125 @@ static void do_shm (char format)
struct ipc_perm *ipcp = &shmseg.shm_perm;
struct passwd *pw;
- maxid = shmctl (0, SHM_INFO, (struct shmid_ds *) (void *) &shm_info);
+ maxid = shmctl(0, SHM_INFO, (struct shmid_ds *) (void *) &shm_info);
if (maxid < 0) {
- bb_printf ("kernel not configured for shared memory\n");
+ bb_printf("kernel not configured for shared memory\n");
return;
}
switch (format) {
case LIMITS:
- bb_printf ("------ Shared Memory Limits --------\n");
- if ((shmctl (0, IPC_INFO, (struct shmid_ds *) (void *) &shminfo)) < 0 )
+ bb_printf("------ Shared Memory Limits --------\n");
+ 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 */
- bb_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);
+ bb_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);
return;
case STATUS:
- bb_printf ("------ Shared Memory Status --------\n"
- "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);
+ bb_printf("------ Shared Memory Status --------\n"
+ "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:
- bb_printf ("------ Shared Memory Segment Creators/Owners --------\n"
- "%-10s %-10s %-10s %-10s %-10s %-10s\n",
- "shmid","perms","cuid","cgid","uid","gid");
+ bb_printf("------ Shared Memory Segment Creators/Owners --------\n"
+ "%-10s %-10s %-10s %-10s %-10s %-10s\n",
+ "shmid", "perms", "cuid", "cgid", "uid", "gid");
break;
case TIME:
- bb_printf ("------ Shared Memory Attach/Detach/Change Times --------\n"
- "%-10s %-10s %-20s %-20s %-20s\n",
- "shmid","owner","attached","detached","changed");
+ bb_printf("------ Shared Memory Attach/Detach/Change Times --------\n"
+ "%-10s %-10s %-20s %-20s %-20s\n",
+ "shmid", "owner", "attached", "detached", "changed");
break;
case PID:
- bb_printf ("------ Shared Memory Creator/Last-op --------\n"
- "%-10s %-10s %-10s %-10s\n",
- "shmid","owner","cpid","lpid");
+ bb_printf("------ Shared Memory Creator/Last-op --------\n"
+ "%-10s %-10s %-10s %-10s\n",
+ "shmid", "owner", "cpid", "lpid");
break;
default:
- bb_printf ("------ Shared Memory Segments --------\n"
- "%-10s %-10s %-10s %-10s %-10s %-10s %-12s\n",
- "key","shmid","owner","perms","bytes","nattch","status");
+ bb_printf("------ Shared Memory Segments --------\n"
+ "%-10s %-10s %-10s %-10s %-10s %-10s %-12s\n",
+ "key", "shmid", "owner", "perms", "bytes", "nattch",
+ "status");
break;
}
for (id = 0; id <= maxid; id++) {
- shmid = shmctl (id, SHM_STAT, &shmseg);
+ shmid = shmctl(id, SHM_STAT, &shmseg);
if (shmid < 0)
continue;
- if (format == CREATOR) {
- print_perms (shmid, ipcp);
+ if (format == CREATOR) {
+ print_perms(shmid, ipcp);
continue;
}
pw = getpwuid(ipcp->uid);
switch (format) {
case TIME:
if (pw)
- bb_printf ("%-10d %-10.10s", shmid, pw->pw_name);
+ bb_printf("%-10d %-10.10s", shmid, pw->pw_name);
else
- bb_printf ("%-10d %-10d", shmid, ipcp->uid);
+ bb_printf("%-10d %-10d", shmid, ipcp->uid);
/* ctime uses static buffer: use separate calls */
- bb_printf(" %-20.16s", shmseg.shm_atime
- ? ctime(&shmseg.shm_atime) + 4 : "Not set");
+ bb_printf(" %-20.16s", shmseg.shm_atime
+ ? ctime(&shmseg.shm_atime) + 4 : "Not set");
bb_printf(" %-20.16s", shmseg.shm_dtime
- ? ctime(&shmseg.shm_dtime) + 4 : "Not set");
+ ? ctime(&shmseg.shm_dtime) + 4 : "Not set");
bb_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)
- bb_printf ("%-10d %-10.10s", shmid, pw->pw_name);
+ bb_printf("%-10d %-10.10s", shmid, pw->pw_name);
else
- bb_printf ("%-10d %-10d", shmid, ipcp->uid);
- bb_printf (" %-10d %-10d\n",
- shmseg.shm_cpid, shmseg.shm_lpid);
+ bb_printf("%-10d %-10d", shmid, ipcp->uid);
+ bb_printf(" %-10d %-10d\n", shmseg.shm_cpid, shmseg.shm_lpid);
break;
default:
- bb_printf("0x%08x ",ipcp->KEY );
+ bb_printf("0x%08x ", ipcp->KEY);
if (pw)
- bb_printf ("%-10d %-10.10s", shmid, pw->pw_name);
+ bb_printf("%-10d %-10.10s", shmid, pw->pw_name);
else
- bb_printf ("%-10d %-10d", shmid, ipcp->uid);
- bb_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" : " ");
+ bb_printf("%-10d %-10d", shmid, ipcp->uid);
+ bb_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" : " ");
break;
}
}
- return;
}
-static void do_sem (char format)
+static void do_sem(void)
{
int maxid, semid, id;
struct semid_ds semary;
@@ -263,107 +261,104 @@ static void do_sem (char format)
struct passwd *pw;
union semun arg;
- arg.array = (ushort *) (void *) &seminfo;
- maxid = semctl (0, 0, SEM_INFO, arg);
+ arg.array = (ushort *) (void *) &seminfo;
+ maxid = semctl(0, 0, SEM_INFO, arg);
if (maxid < 0) {
- bb_printf ("kernel not configured for semaphores\n");
+ bb_printf("kernel not configured for semaphores\n");
return;
}
switch (format) {
case LIMITS:
- bb_printf ("------ Semaphore Limits --------\n");
- arg.array = (ushort *) (void *) &seminfo; /* damn union */
- if ((semctl (0, 0, IPC_INFO, arg)) < 0 )
+ bb_printf("------ Semaphore Limits --------\n");
+ arg.array = (ushort *) (void *) &seminfo; /* damn union */
+ if ((semctl(0, 0, IPC_INFO, arg)) < 0)
return;
- bb_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);
+ bb_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);
return;
case STATUS:
- bb_printf ("------ Semaphore Status --------\n"
- "used arrays = %d\n"
- "allocated semaphores = %d\n",
- seminfo.semusz,
- seminfo.semaem);
+ bb_printf("------ Semaphore Status --------\n"
+ "used arrays = %d\n"
+ "allocated semaphores = %d\n",
+ seminfo.semusz, seminfo.semaem);
return;
case CREATOR:
- bb_printf ("------ Semaphore Arrays Creators/Owners --------\n"
- "%-10s %-10s %-10s %-10s %-10s %-10s\n",
- "semid","perms","cuid","cgid","uid","gid");
+ bb_printf("------ Semaphore Arrays Creators/Owners --------\n"
+ "%-10s %-10s %-10s %-10s %-10s %-10s\n",
+ "semid", "perms", "cuid", "cgid", "uid", "gid");
break;
case TIME:
- bb_printf ("------ Shared Memory Operation/Change Times --------\n"
- "%-8s %-10s %-26.24s %-26.24s\n",
- "shmid","owner","last-op","last-changed");
+ bb_printf("------ Shared Memory Operation/Change Times --------\n"
+ "%-8s %-10s %-26.24s %-26.24s\n",
+ "shmid", "owner", "last-op", "last-changed");
break;
case PID:
break;
default:
- bb_printf ("------ Semaphore Arrays --------\n"
- "%-10s %-10s %-10s %-10s %-10s\n",
- "key","semid","owner","perms","nsems");
+ bb_printf("------ Semaphore Arrays --------\n"
+ "%-10s %-10s %-10s %-10s %-10s\n",
+ "key", "semid", "owner", "perms", "nsems");
break;
}
for (id = 0; id <= maxid; id++) {
arg.buf = (struct semid_ds *) &semary;
- semid = semctl (id, 0, SEM_STAT, arg);
+ semid = semctl(id, 0, SEM_STAT, arg);
if (semid < 0)
continue;
- if (format == CREATOR) {
- print_perms (semid, ipcp);
+ if (format == CREATOR) {
+ print_perms(semid, ipcp);
continue;
}
pw = getpwuid(ipcp->uid);
switch (format) {
case TIME:
if (pw)
- bb_printf ("%-8d %-10.10s", semid, pw->pw_name);
+ bb_printf("%-8d %-10.10s", semid, pw->pw_name);
else
- bb_printf ("%-8d %-10d", semid, ipcp->uid);
- bb_printf (" %-26.24s", semary.sem_otime
- ? ctime(&semary.sem_otime) : "Not set");
- bb_printf (" %-26.24s\n", semary.sem_ctime
- ? ctime(&semary.sem_ctime) : "Not set");
+ bb_printf("%-8d %-10d", semid, ipcp->uid);
+ /* ctime uses static buffer: use separate calls */
+ bb_printf(" %-26.24s", semary.sem_otime
+ ? ctime(&semary.sem_otime) : "Not set");
+ bb_printf(" %-26.24s\n", semary.sem_ctime
+ ? ctime(&semary.sem_ctime) : "Not set");
break;
case PID:
break;
default:
- bb_printf("0x%08x ", ipcp->KEY);
+ bb_printf("0x%08x ", ipcp->KEY);
if (pw)
- bb_printf ("%-10d %-10.9s", semid, pw->pw_name);
+ bb_printf("%-10d %-10.9s", semid, pw->pw_name);
else
- bb_printf ("%-10d %-9d", semid, ipcp->uid);
- bb_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);
+ bb_printf("%-10d %-9d", semid, ipcp->uid);
+ bb_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);
break;
}
}
}
-static void do_msg (char format)
+static void do_msg(void)
{
int maxid, msqid, id;
struct msqid_ds msgque;
@@ -371,178 +366,165 @@ static void do_msg (char format)
struct ipc_perm *ipcp = &msgque.msg_perm;
struct passwd *pw;
- maxid = msgctl (0, MSG_INFO, (struct msqid_ds *) (void *) &msginfo);
+ maxid = msgctl(0, MSG_INFO, (struct msqid_ds *) (void *) &msginfo);
if (maxid < 0) {
- bb_printf ("kernel not configured for message queues\n");
+ bb_printf("kernel not configured for message queues\n");
return;
}
switch (format) {
case LIMITS:
- if ((msgctl (0, IPC_INFO, (struct msqid_ds *) (void *) &msginfo)) < 0 )
+ if ((msgctl(0, IPC_INFO, (struct msqid_ds *) (void *) &msginfo)) < 0)
return;
- bb_printf ("------ Messages: Limits --------\n"
- "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);
+ bb_printf("------ Messages: Limits --------\n"
+ "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:
- bb_printf ("------ Messages: Status --------\n"
- "allocated queues = %d\n"
- "used headers = %d\n"
- "used space = %d bytes\n",
- msginfo.msgpool,
- msginfo.msgmap,
- msginfo.msgtql);
+ bb_printf("------ Messages: Status --------\n"
+ "allocated queues = %d\n"
+ "used headers = %d\n"
+ "used space = %d bytes\n",
+ msginfo.msgpool, msginfo.msgmap, msginfo.msgtql);
return;
case CREATOR:
- bb_printf ("------ Message Queues: Creators/Owners --------\n"
- "%-10s %-10s %-10s %-10s %-10s %-10s\n",
- "msqid","perms","cuid","cgid","uid","gid");
+ bb_printf("------ Message Queues: Creators/Owners --------\n"
+ "%-10s %-10s %-10s %-10s %-10s %-10s\n",
+ "msqid", "perms", "cuid", "cgid", "uid", "gid");
break;
case TIME:
- bb_printf ("------ Message Queues Send/Recv/Change Times --------\n"
- "%-8s %-10s %-20s %-20s %-20s\n",
- "msqid","owner","send","recv","change");
+ bb_printf("------ Message Queues Send/Recv/Change Times --------\n"
+ "%-8s %-10s %-20s %-20s %-20s\n",
+ "msqid", "owner", "send", "recv", "change");
break;
case PID:
- bb_printf ("------ Message Queues PIDs --------\n"
- "%-10s %-10s %-10s %-10s\n",
- "msqid","owner","lspid","lrpid");
+ bb_printf("------ Message Queues PIDs --------\n"
+ "%-10s %-10s %-10s %-10s\n",
+ "msqid", "owner", "lspid", "lrpid");
break;
default:
- bb_printf ("------ Message Queues --------\n"
- "%-10s %-10s %-10s %-10s %-12s %-12s\n",
- "key","msqid","owner","perms","used-bytes","messages");
+ bb_printf("------ Message Queues --------\n"
+ "%-10s %-10s %-10s %-10s %-12s %-12s\n",
+ "key", "msqid", "owner", "perms", "used-bytes", "messages");
break;
}
for (id = 0; id <= maxid; id++) {
- msqid = msgctl (id, MSG_STAT, &msgque);
+ msqid = msgctl(id, MSG_STAT, &msgque);
if (msqid < 0)
continue;
- if (format == CREATOR) {
- print_perms (msqid, ipcp);
+ if (format == CREATOR) {
+ print_perms(msqid, ipcp);
continue;
}
pw = getpwuid(ipcp->uid);
switch (format) {
case TIME:
if (pw)
- bb_printf ("%-8d %-10.10s", msqid, pw->pw_name);
+ bb_printf("%-8d %-10.10s", msqid, pw->pw_name);
else
- bb_printf ("%-8d %-10d", msqid, ipcp->uid);
- bb_printf (" %-20.16s", msgque.msg_stime
- ? ctime(&msgque.msg_stime) + 4 : "Not set");
- bb_printf (" %-20.16s", msgque.msg_rtime
- ? ctime(&msgque.msg_rtime) + 4 : "Not set");
- bb_printf (" %-20.16s\n", msgque.msg_ctime
- ? ctime(&msgque.msg_ctime) + 4 : "Not set");
+ bb_printf("%-8d %-10d", msqid, ipcp->uid);
+ bb_printf(" %-20.16s", msgque.msg_stime
+ ? ctime(&msgque.msg_stime) + 4 : "Not set");
+ bb_printf(" %-20.16s", msgque.msg_rtime
+ ? ctime(&msgque.msg_rtime) + 4 : "Not set");
+ bb_printf(" %-20.16s\n", msgque.msg_ctime
+ ? ctime(&msgque.msg_ctime) + 4 : "Not set");
break;
case PID:
if (pw)
- bb_printf ("%-8d %-10.10s", msqid, pw->pw_name);
+ bb_printf("%-8d %-10.10s", msqid, pw->pw_name);
else
- bb_printf ("%-8d %-10d", msqid, ipcp->uid);
- bb_printf (" %5d %5d\n",
- msgque.msg_lspid, msgque.msg_lrpid);
+ bb_printf("%-8d %-10d", msqid, ipcp->uid);
+ bb_printf(" %5d %5d\n", msgque.msg_lspid, msgque.msg_lrpid);
break;
default:
- bb_printf( "0x%08x ",ipcp->KEY );
+ bb_printf("0x%08x ", ipcp->KEY);
if (pw)
- bb_printf ("%-10d %-10.10s", msqid, pw->pw_name);
+ bb_printf("%-10d %-10.10s", msqid, pw->pw_name);
else
- bb_printf ("%-10d %-10d", msqid, ipcp->uid);
- bb_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);
+ bb_printf("%-10d %-10d", msqid, ipcp->uid);
+ bb_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);
break;
}
}
- return;
}
-static void print_shm (int shmid)
+static void print_shm(int shmid)
{
struct shmid_ds shmds;
struct ipc_perm *ipcp = &shmds.shm_perm;
- if (shmctl (shmid, IPC_STAT, &shmds) == -1) {
- perror ("shmctl ");
+ if (shmctl(shmid, IPC_STAT, &shmds) == -1) {
+ bb_perror_msg("shmctl");
return;
}
- bb_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"
- "att_time=%-26.24s\n"
- "det_time=%-26.24s\n"
- "change_time=%-26.24s\n"
- "\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,
- shmds.shm_atime ? ctime (&shmds.shm_atime) : "Not set",
- shmds.shm_dtime ? ctime (&shmds.shm_dtime) : "Not set",
- ctime (&shmds.shm_ctime));
- return;
+ bb_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);
+ bb_printf("att_time=%-26.24s\n",
+ shmds.shm_atime ? ctime(&shmds.shm_atime) : "Not set");
+ bb_printf("det_time=%-26.24s\n",
+ shmds.shm_dtime ? ctime(&shmds.shm_dtime) : "Not set");
+ bb_printf("change_time=%-26.24s\n\n", ctime(&shmds.shm_ctime));
}
-static void print_msg (int msqid)
+static void print_msg(int msqid)
{
struct msqid_ds buf;
struct ipc_perm *ipcp = &buf.msg_perm;
- if (msgctl (msqid, IPC_STAT, &buf) == -1) {
- perror ("msgctl ");
+ if (msgctl(msqid, IPC_STAT, &buf) == -1) {
+ bb_perror_msg("msgctl");
return;
}
- bb_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"
- "send_time=%-26.24s\n"
- "rcv_time=%-26.24s\n"
- "change_time=%-26.24s\n"
- "\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,
- buf.msg_stime ? ctime (&buf.msg_stime) : "Not set",
- buf.msg_rtime ? ctime (&buf.msg_rtime) : "Not set",
- buf.msg_ctime ? ctime (&buf.msg_ctime) : "Not set");
- return;
+ bb_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);
+
+ bb_printf("send_time=%-26.24s\n",
+ buf.msg_stime ? ctime(&buf.msg_stime) : "Not set");
+ bb_printf("rcv_time=%-26.24s\n",
+ buf.msg_rtime ? ctime(&buf.msg_rtime) : "Not set");
+ bb_printf("change_time=%-26.24s\n\n",
+ buf.msg_ctime ? ctime(&buf.msg_ctime) : "Not set");
}
-static void print_sem (int semid)
+static void print_sem(int semid)
{
struct semid_ds semds;
struct ipc_perm *ipcp = &semds.sem_perm;
@@ -550,66 +532,69 @@ static void print_sem (int semid)
unsigned int i;
arg.buf = &semds;
- if (semctl (semid, 0, IPC_STAT, arg) < 0) {
- perror ("semctl ");
+ if (semctl(semid, 0, IPC_STAT, arg)) {
+ bb_perror_msg("semctl");
return;
}
- bb_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"
- "ctime = %-26.24s\n"
- "%-10s %-10s %-10s %-10s %-10s\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",
- ctime (&semds.sem_ctime),
- "semnum","value","ncount","zcount","pid");
+ bb_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");
+ bb_printf("ctime = %-26.24s\n"
+ "%-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++) {
+ for (i = 0; i < semds.sem_nsems; i++) {
int val, ncnt, zcnt, pid;
- val = semctl (semid, i, GETVAL, arg);
- ncnt = semctl (semid, i, GETNCNT, arg);
- zcnt = semctl (semid, i, GETZCNT, arg);
- pid = semctl (semid, i, GETPID, arg);
+
+ val = semctl(semid, i, GETVAL, arg);
+ ncnt = semctl(semid, i, GETNCNT, arg);
+ zcnt = semctl(semid, i, GETZCNT, arg);
+ pid = semctl(semid, i, GETPID, arg);
if (val < 0 || ncnt < 0 || zcnt < 0 || pid < 0) {
- perror ("semctl ");
- bb_fflush_stdout_and_exit (1);
+ bb_perror_msg_and_die("semctl");
}
- bb_printf ("%-10d %-10d %-10d %-10d %-10d\n",
- i, val, ncnt, zcnt, pid);
+ bb_printf("%-10d %-10d %-10d %-10d %-10d\n", i, val, ncnt, zcnt, pid);
}
- bb_printf ("\n");
- return;
+ bb_printf("\n");
}
-int ipcs_main (int argc, char **argv) {
- int opt, msg = 0, sem = 0, shm = 0, id=0, print=0;
- char format = 0;
- char options[] = "atclupsmqi:ih?";
-
- while ((opt = getopt (argc, argv, options)) != -1) {
+int ipcs_main(int argc, char **argv)
+{
+ int opt, id = 0;
+ unsigned flags = 0;
+#define flag_print (1<<0)
+#define flag_msg (1<<1)
+#define flag_sem (1<<2)
+#define flag_shm (1<<3)
+ const char *const options = "atclupsmqi:ih?";
+
+ while ((opt = getopt(argc, argv, options)) != -1) {
switch (opt) {
case 'i':
- id = atoi (optarg);
- print = 1;
+ id = atoi(optarg);
+ flags |= flag_print;
break;
case 'a':
- msg = shm = sem = 1;
+ flags |= flag_msg | flag_sem | flag_shm;
break;
case 'q':
- msg = 1;
+ flags |= flag_msg;
break;
case 's':
- sem = 1;
+ flags |= flag_sem;
break;
case 'm':
- shm = 1;
+ flags |= flag_shm;
break;
case 't':
format = TIME;
@@ -629,43 +614,40 @@ int ipcs_main (int argc, char **argv) {
case 'h':
case '?':
bb_show_usage();
- bb_fflush_stdout_and_exit (0);
}
}
- if (print) {
- if (shm) {
- print_shm (id);
- bb_fflush_stdout_and_exit (0);
+ if (flags & flag_print) {
+ if (flags & flag_shm) {
+ print_shm(id);
+ bb_fflush_stdout_and_exit(0);
}
- if (sem) {
- print_sem (id);
- bb_fflush_stdout_and_exit (0);
+ if (flags & flag_sem) {
+ print_sem(id);
+ bb_fflush_stdout_and_exit(0);
}
- if (msg) {
- print_msg (id);
- bb_fflush_stdout_and_exit (0);
+ if (flags & flag_msg) {
+ print_msg(id);
+ bb_fflush_stdout_and_exit(0);
}
bb_show_usage();
- bb_fflush_stdout_and_exit (0);
}
- if ( !shm && !msg && !sem)
- msg = sem = shm = 1;
- bb_printf ("\n");
+ if (!(flags & (flag_shm | flag_msg | flag_sem)))
+ flags |= flag_msg | flag_shm | flag_sem;
+ bb_printf("\n");
- if (shm) {
- do_shm (format);
- bb_printf ("\n");
+ if (flags & flag_shm) {
+ do_shm();
+ bb_printf("\n");
}
- if (sem) {
- do_sem (format);
- bb_printf ("\n");
+ if (flags & flag_sem) {
+ do_sem();
+ bb_printf("\n");
}
- if (msg) {
- do_msg (format);
- bb_printf ("\n");
+ if (flags & flag_msg) {
+ do_msg();
+ bb_printf("\n");
}
- return 0;
+ return EXIT_SUCCESS;
}
-