2006-07-03 01:17:05 +05:30
|
|
|
/* vi: set sw=4 ts=4: */
|
2005-06-20 10:00:36 +05:30
|
|
|
/*
|
|
|
|
* ipcs.c -- provides information on allocated ipc resources.
|
|
|
|
*
|
|
|
|
* 01 Sept 2004 - Rodney Radford <rradford@mindspring.com>
|
|
|
|
* Adapted for busybox from util-linux-2.12a.
|
|
|
|
*
|
2010-08-16 23:44:46 +05:30
|
|
|
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
2005-06-20 10:00:36 +05:30
|
|
|
*/
|
2016-11-23 16:16:32 +05:30
|
|
|
//config:config IPCS
|
2017-07-19 01:31:24 +05:30
|
|
|
//config: bool "ipcs (11 kb)"
|
2016-11-23 16:16:32 +05:30
|
|
|
//config: default y
|
|
|
|
//config: select PLATFORM_LINUX
|
|
|
|
//config: help
|
2017-07-21 13:20:55 +05:30
|
|
|
//config: The ipcs utility is used to provide information on the currently
|
|
|
|
//config: allocated System V interprocess (IPC) objects in the system.
|
2016-11-23 16:16:32 +05:30
|
|
|
|
2017-08-09 22:54:19 +05:30
|
|
|
//applet:IF_IPCS(APPLET_NOEXEC(ipcs, ipcs, BB_DIR_USR_BIN, BB_SUID_DROP, ipcs))
|
2016-11-23 16:16:32 +05:30
|
|
|
|
|
|
|
//kbuild:lib-$(CONFIG_IPCS) += ipcs.o
|
2005-06-20 10:00:36 +05:30
|
|
|
|
|
|
|
/* X/OPEN tells us to use <sys/{types,ipc,sem}.h> for semctl() */
|
|
|
|
/* X/OPEN tells us to use <sys/{types,ipc,msg}.h> for msgctl() */
|
|
|
|
/* X/OPEN tells us to use <sys/{types,ipc,shm}.h> for shmctl() */
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/ipc.h>
|
|
|
|
#include <sys/sem.h>
|
|
|
|
#include <sys/msg.h>
|
|
|
|
#include <sys/shm.h>
|
|
|
|
|
2007-06-01 03:46:38 +05:30
|
|
|
#include "libbb.h"
|
2005-06-20 10:00:36 +05:30
|
|
|
|
|
|
|
/*-------------------------------------------------------------------*/
|
|
|
|
/* SHM_DEST and SHM_LOCKED are defined in kernel headers,
|
|
|
|
but inside #ifdef __KERNEL__ ... #endif */
|
|
|
|
#ifndef SHM_DEST
|
|
|
|
/* shm_mode upper byte flags */
|
2006-08-29 05:01:54 +05:30
|
|
|
#define SHM_DEST 01000 /* segment will be destroyed on last detach */
|
|
|
|
#define SHM_LOCKED 02000 /* segment will not be swapped */
|
2005-06-20 10:00:36 +05:30
|
|
|
#endif
|
|
|
|
|
|
|
|
/* For older kernels the same holds for the defines below */
|
|
|
|
#ifndef MSG_STAT
|
|
|
|
#define MSG_STAT 11
|
|
|
|
#define MSG_INFO 12
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef SHM_STAT
|
|
|
|
#define SHM_STAT 13
|
|
|
|
#define SHM_INFO 14
|
|
|
|
struct shm_info {
|
2006-08-29 05:01:54 +05:30
|
|
|
int used_ids;
|
2011-06-03 23:55:17 +05:30
|
|
|
unsigned long shm_tot; /* total allocated shm */
|
|
|
|
unsigned long shm_rss; /* total resident shm */
|
|
|
|
unsigned long shm_swp; /* total swapped shm */
|
|
|
|
unsigned long swap_attempts;
|
|
|
|
unsigned long swap_successes;
|
2005-06-20 10:00:36 +05:30
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef SEM_STAT
|
|
|
|
#define SEM_STAT 18
|
|
|
|
#define SEM_INFO 19
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Some versions of libc only define IPC_INFO when __USE_GNU is defined. */
|
|
|
|
#ifndef IPC_INFO
|
|
|
|
#define IPC_INFO 3
|
|
|
|
#endif
|
|
|
|
/*-------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
/* The last arg of semctl is a union semun, but where is it defined?
|
|
|
|
X/OPEN tells us to define it ourselves, but until recently
|
|
|
|
Linux include files would also define it. */
|
2007-04-10 21:12:06 +05:30
|
|
|
#if defined(__GNU_LIBRARY__) && !defined(_SEM_SEMUN_UNDEFINED)
|
2005-06-20 10:00:36 +05:30
|
|
|
/* union semun is defined by including <sys/sem.h> */
|
|
|
|
#else
|
|
|
|
/* according to X/OPEN we have to define it ourselves */
|
|
|
|
union semun {
|
|
|
|
int val;
|
|
|
|
struct semid_ds *buf;
|
2008-02-16 18:48:17 +05:30
|
|
|
unsigned short *array;
|
2005-06-20 10:00:36 +05:30
|
|
|
struct seminfo *__buf;
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* X/OPEN (Jan 1987) does not define fields key, seq in struct ipc_perm;
|
|
|
|
libc 4/5 does not mention struct ipc_term at all, but includes
|
|
|
|
<linux/ipc.h>, which defines a struct ipc_perm with such fields.
|
|
|
|
glibc-1.09 has no support for sysv ipc.
|
|
|
|
glibc 2 uses __key, __seq */
|
2007-04-10 21:12:06 +05:30
|
|
|
#if defined(__GNU_LIBRARY__) && __GNU_LIBRARY__ > 1
|
2005-06-20 10:00:36 +05:30
|
|
|
#define KEY __key
|
|
|
|
#else
|
|
|
|
#define KEY key
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define LIMITS 1
|
|
|
|
#define STATUS 2
|
|
|
|
#define CREATOR 3
|
|
|
|
#define TIME 4
|
|
|
|
#define PID 5
|
|
|
|
|
2006-08-29 05:01:54 +05:30
|
|
|
static void print_perms(int id, struct ipc_perm *ipcp)
|
|
|
|
{
|
2005-06-20 10:00:36 +05:30
|
|
|
struct passwd *pw;
|
|
|
|
struct group *gr;
|
|
|
|
|
2006-10-27 04:51:47 +05:30
|
|
|
printf("%-10d %-10o", id, ipcp->mode & 0777);
|
2005-06-20 10:00:36 +05:30
|
|
|
|
2007-09-27 15:47:53 +05:30
|
|
|
pw = getpwuid(ipcp->cuid);
|
|
|
|
if (pw) printf(" %-10s", pw->pw_name);
|
|
|
|
else printf(" %-10d", ipcp->cuid);
|
|
|
|
gr = getgrgid(ipcp->cgid);
|
|
|
|
if (gr) printf(" %-10s", gr->gr_name);
|
|
|
|
else printf(" %-10d", ipcp->cgid);
|
|
|
|
|
|
|
|
pw = getpwuid(ipcp->uid);
|
|
|
|
if (pw) printf(" %-10s", pw->pw_name);
|
|
|
|
else printf(" %-10d", ipcp->uid);
|
|
|
|
gr = getgrgid(ipcp->gid);
|
|
|
|
if (gr) printf(" %-10s\n", gr->gr_name);
|
|
|
|
else printf(" %-10d\n", ipcp->gid);
|
2005-06-20 10:00:36 +05:30
|
|
|
}
|
|
|
|
|
2018-03-08 17:40:23 +05:30
|
|
|
static NOINLINE void do_shm(int format)
|
2005-06-20 10:00:36 +05:30
|
|
|
{
|
|
|
|
int maxid, shmid, id;
|
|
|
|
struct shmid_ds shmseg;
|
|
|
|
struct shm_info shm_info;
|
|
|
|
struct shminfo shminfo;
|
|
|
|
struct ipc_perm *ipcp = &shmseg.shm_perm;
|
|
|
|
struct passwd *pw;
|
|
|
|
|
2006-08-29 05:01:54 +05:30
|
|
|
maxid = shmctl(0, SHM_INFO, (struct shmid_ds *) (void *) &shm_info);
|
2005-06-20 10:00:36 +05:30
|
|
|
if (maxid < 0) {
|
2006-10-27 04:51:47 +05:30
|
|
|
printf("kernel not configured for %s\n", "shared memory");
|
2005-06-20 10:00:36 +05:30
|
|
|
return;
|
|
|
|
}
|
2006-01-25 05:38:53 +05:30
|
|
|
|
2005-06-20 10:00:36 +05:30
|
|
|
switch (format) {
|
|
|
|
case LIMITS:
|
2006-10-27 04:51:47 +05:30
|
|
|
printf("------ Shared Memory %s --------\n", "Limits");
|
2006-08-29 05:01:54 +05:30
|
|
|
if ((shmctl(0, IPC_INFO, (struct shmid_ds *) (void *) &shminfo)) < 0)
|
2005-06-20 10:00:36 +05:30
|
|
|
return;
|
|
|
|
/* glibc 2.1.3 and all earlier libc's have ints as fields
|
2013-01-14 20:27:44 +05:30
|
|
|
* of struct shminfo; glibc 2.1.91 has unsigned long; ach */
|
2006-10-27 04:51:47 +05:30
|
|
|
printf("max number of segments = %lu\n"
|
2013-01-14 06:04:48 +05:30
|
|
|
"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);
|
2005-06-20 10:00:36 +05:30
|
|
|
return;
|
|
|
|
|
|
|
|
case STATUS:
|
2006-10-27 04:51:47 +05:30
|
|
|
printf("------ Shared Memory %s --------\n", "Status");
|
2013-01-14 06:04:48 +05:30
|
|
|
printf("segments allocated %d\n"
|
2013-11-29 21:15:45 +05:30
|
|
|
"pages allocated %lu\n"
|
|
|
|
"pages resident %lu\n"
|
|
|
|
"pages swapped %lu\n"
|
|
|
|
"Swap performance: %lu attempts\t%lu successes\n",
|
2013-01-14 06:04:48 +05:30
|
|
|
shm_info.used_ids,
|
|
|
|
shm_info.shm_tot,
|
|
|
|
shm_info.shm_rss,
|
|
|
|
shm_info.shm_swp,
|
|
|
|
shm_info.swap_attempts, shm_info.swap_successes);
|
2005-06-20 10:00:36 +05:30
|
|
|
return;
|
|
|
|
|
|
|
|
case CREATOR:
|
2006-10-27 04:51:47 +05:30
|
|
|
printf("------ Shared Memory %s --------\n", "Segment Creators/Owners");
|
2013-01-14 06:04:48 +05:30
|
|
|
printf("%-10s %-10s %-10s %-10s %-10s %-10s\n",
|
|
|
|
"shmid", "perms", "cuid", "cgid", "uid", "gid");
|
2005-06-20 10:00:36 +05:30
|
|
|
break;
|
|
|
|
|
|
|
|
case TIME:
|
2006-10-27 04:51:47 +05:30
|
|
|
printf("------ Shared Memory %s --------\n", "Attach/Detach/Change Times");
|
2013-01-14 06:04:48 +05:30
|
|
|
printf("%-10s %-10s %-20s %-20s %-20s\n",
|
|
|
|
"shmid", "owner", "attached", "detached", "changed");
|
2005-06-20 10:00:36 +05:30
|
|
|
break;
|
|
|
|
|
|
|
|
case PID:
|
2006-10-27 04:51:47 +05:30
|
|
|
printf("------ Shared Memory %s --------\n", "Creator/Last-op");
|
2013-01-14 06:04:48 +05:30
|
|
|
printf("%-10s %-10s %-10s %-10s\n",
|
|
|
|
"shmid", "owner", "cpid", "lpid");
|
2005-06-20 10:00:36 +05:30
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2006-10-27 04:51:47 +05:30
|
|
|
printf("------ Shared Memory %s --------\n", "Segments");
|
2013-01-14 06:04:48 +05:30
|
|
|
printf("%-10s %-10s %-10s %-10s %-10s %-10s %-12s\n",
|
|
|
|
"key", "shmid", "owner", "perms", "bytes", "nattch",
|
|
|
|
"status");
|
2005-06-20 10:00:36 +05:30
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (id = 0; id <= maxid; id++) {
|
2006-08-29 05:01:54 +05:30
|
|
|
shmid = shmctl(id, SHM_STAT, &shmseg);
|
2006-01-25 05:38:53 +05:30
|
|
|
if (shmid < 0)
|
2005-06-20 10:00:36 +05:30
|
|
|
continue;
|
2006-08-29 05:01:54 +05:30
|
|
|
if (format == CREATOR) {
|
|
|
|
print_perms(shmid, ipcp);
|
2005-06-20 10:00:36 +05:30
|
|
|
continue;
|
|
|
|
}
|
|
|
|
pw = getpwuid(ipcp->uid);
|
|
|
|
switch (format) {
|
2006-01-25 05:38:53 +05:30
|
|
|
case TIME:
|
2005-06-20 10:00:36 +05:30
|
|
|
if (pw)
|
2006-10-27 04:51:47 +05:30
|
|
|
printf("%-10d %-10.10s", shmid, pw->pw_name);
|
2005-06-20 10:00:36 +05:30
|
|
|
else
|
2006-10-27 04:51:47 +05:30
|
|
|
printf("%-10d %-10d", shmid, ipcp->uid);
|
2005-06-20 10:00:36 +05:30
|
|
|
/* ctime uses static buffer: use separate calls */
|
2006-10-27 04:51:47 +05:30
|
|
|
printf(" %-20.16s", shmseg.shm_atime
|
2013-01-14 06:04:48 +05:30
|
|
|
? ctime(&shmseg.shm_atime) + 4 : "Not set");
|
2006-10-27 04:51:47 +05:30
|
|
|
printf(" %-20.16s", shmseg.shm_dtime
|
2013-01-14 06:04:48 +05:30
|
|
|
? ctime(&shmseg.shm_dtime) + 4 : "Not set");
|
2006-10-27 04:51:47 +05:30
|
|
|
printf(" %-20.16s\n", shmseg.shm_ctime
|
2013-01-14 06:04:48 +05:30
|
|
|
? ctime(&shmseg.shm_ctime) + 4 : "Not set");
|
2005-06-20 10:00:36 +05:30
|
|
|
break;
|
|
|
|
case PID:
|
|
|
|
if (pw)
|
2006-10-27 04:51:47 +05:30
|
|
|
printf("%-10d %-10.10s", shmid, pw->pw_name);
|
2005-06-20 10:00:36 +05:30
|
|
|
else
|
2006-10-27 04:51:47 +05:30
|
|
|
printf("%-10d %-10d", shmid, ipcp->uid);
|
|
|
|
printf(" %-10d %-10d\n", shmseg.shm_cpid, shmseg.shm_lpid);
|
2005-06-20 10:00:36 +05:30
|
|
|
break;
|
2006-01-25 05:38:53 +05:30
|
|
|
|
2005-06-20 10:00:36 +05:30
|
|
|
default:
|
2006-10-27 04:51:47 +05:30
|
|
|
printf("0x%08x ", ipcp->KEY);
|
2005-06-20 10:00:36 +05:30
|
|
|
if (pw)
|
2006-10-27 04:51:47 +05:30
|
|
|
printf("%-10d %-10.10s", shmid, pw->pw_name);
|
2005-06-20 10:00:36 +05:30
|
|
|
else
|
2006-10-27 04:51:47 +05:30
|
|
|
printf("%-10d %-10d", shmid, ipcp->uid);
|
|
|
|
printf(" %-10o %-10lu %-10ld %-6s %-6s\n", ipcp->mode & 0777,
|
2013-01-14 06:04:48 +05:30
|
|
|
/*
|
|
|
|
* 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" : " ");
|
2005-06-20 10:00:36 +05:30
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-08 17:40:23 +05:30
|
|
|
static NOINLINE void do_sem(int format)
|
2005-06-20 10:00:36 +05:30
|
|
|
{
|
|
|
|
int maxid, semid, id;
|
|
|
|
struct semid_ds semary;
|
|
|
|
struct seminfo seminfo;
|
|
|
|
struct ipc_perm *ipcp = &semary.sem_perm;
|
|
|
|
struct passwd *pw;
|
|
|
|
union semun arg;
|
|
|
|
|
2011-06-03 23:55:17 +05:30
|
|
|
arg.array = (unsigned short *) (void *) &seminfo;
|
2006-08-29 05:01:54 +05:30
|
|
|
maxid = semctl(0, 0, SEM_INFO, arg);
|
2005-06-20 10:00:36 +05:30
|
|
|
if (maxid < 0) {
|
2006-10-27 04:51:47 +05:30
|
|
|
printf("kernel not configured for %s\n", "semaphores");
|
2005-06-20 10:00:36 +05:30
|
|
|
return;
|
|
|
|
}
|
2006-01-25 05:38:53 +05:30
|
|
|
|
2005-06-20 10:00:36 +05:30
|
|
|
switch (format) {
|
|
|
|
case LIMITS:
|
2006-10-27 04:51:47 +05:30
|
|
|
printf("------ Semaphore %s --------\n", "Limits");
|
2011-06-03 23:55:17 +05:30
|
|
|
arg.array = (unsigned short *) (void *) &seminfo; /* damn union */
|
2006-08-29 05:01:54 +05:30
|
|
|
if ((semctl(0, 0, IPC_INFO, arg)) < 0)
|
2005-06-20 10:00:36 +05:30
|
|
|
return;
|
2006-10-27 04:51:47 +05:30
|
|
|
printf("max number of arrays = %d\n"
|
2013-01-14 06:04:48 +05:30
|
|
|
"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);
|
2005-06-20 10:00:36 +05:30
|
|
|
return;
|
|
|
|
|
|
|
|
case STATUS:
|
2006-10-27 04:51:47 +05:30
|
|
|
printf("------ Semaphore %s --------\n", "Status");
|
2013-01-14 06:04:48 +05:30
|
|
|
printf("used arrays = %d\n"
|
|
|
|
"allocated semaphores = %d\n",
|
|
|
|
seminfo.semusz, seminfo.semaem);
|
2005-06-20 10:00:36 +05:30
|
|
|
return;
|
|
|
|
|
|
|
|
case CREATOR:
|
2006-10-27 04:51:47 +05:30
|
|
|
printf("------ Semaphore %s --------\n", "Arrays Creators/Owners");
|
2013-01-14 06:04:48 +05:30
|
|
|
printf("%-10s %-10s %-10s %-10s %-10s %-10s\n",
|
|
|
|
"semid", "perms", "cuid", "cgid", "uid", "gid");
|
2005-06-20 10:00:36 +05:30
|
|
|
break;
|
|
|
|
|
|
|
|
case TIME:
|
2006-10-27 04:51:47 +05:30
|
|
|
printf("------ Shared Memory %s --------\n", "Operation/Change Times");
|
2013-01-14 06:04:48 +05:30
|
|
|
printf("%-8s %-10s %-26.24s %-26.24s\n",
|
|
|
|
"shmid", "owner", "last-op", "last-changed");
|
2005-06-20 10:00:36 +05:30
|
|
|
break;
|
|
|
|
|
|
|
|
case PID:
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2006-10-27 04:51:47 +05:30
|
|
|
printf("------ Semaphore %s --------\n", "Arrays");
|
2013-01-14 06:04:48 +05:30
|
|
|
printf("%-10s %-10s %-10s %-10s %-10s\n",
|
|
|
|
"key", "semid", "owner", "perms", "nsems");
|
2005-06-20 10:00:36 +05:30
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (id = 0; id <= maxid; id++) {
|
|
|
|
arg.buf = (struct semid_ds *) &semary;
|
2006-08-29 05:01:54 +05:30
|
|
|
semid = semctl(id, 0, SEM_STAT, arg);
|
2005-06-20 10:00:36 +05:30
|
|
|
if (semid < 0)
|
|
|
|
continue;
|
2006-08-29 05:01:54 +05:30
|
|
|
if (format == CREATOR) {
|
|
|
|
print_perms(semid, ipcp);
|
2005-06-20 10:00:36 +05:30
|
|
|
continue;
|
|
|
|
}
|
|
|
|
pw = getpwuid(ipcp->uid);
|
|
|
|
switch (format) {
|
2006-01-25 05:38:53 +05:30
|
|
|
case TIME:
|
2005-06-20 10:00:36 +05:30
|
|
|
if (pw)
|
2006-10-27 04:51:47 +05:30
|
|
|
printf("%-8d %-10.10s", semid, pw->pw_name);
|
2005-06-20 10:00:36 +05:30
|
|
|
else
|
2006-10-27 04:51:47 +05:30
|
|
|
printf("%-8d %-10d", semid, ipcp->uid);
|
2006-08-29 05:01:54 +05:30
|
|
|
/* ctime uses static buffer: use separate calls */
|
2006-10-27 04:51:47 +05:30
|
|
|
printf(" %-26.24s", semary.sem_otime
|
2013-01-14 06:04:48 +05:30
|
|
|
? ctime(&semary.sem_otime) : "Not set");
|
2006-10-27 04:51:47 +05:30
|
|
|
printf(" %-26.24s\n", semary.sem_ctime
|
2013-01-14 06:04:48 +05:30
|
|
|
? ctime(&semary.sem_ctime) : "Not set");
|
2005-06-20 10:00:36 +05:30
|
|
|
break;
|
|
|
|
case PID:
|
|
|
|
break;
|
2006-01-25 05:38:53 +05:30
|
|
|
|
2005-06-20 10:00:36 +05:30
|
|
|
default:
|
2006-10-27 04:51:47 +05:30
|
|
|
printf("0x%08x ", ipcp->KEY);
|
2005-06-20 10:00:36 +05:30
|
|
|
if (pw)
|
2006-10-27 04:51:47 +05:30
|
|
|
printf("%-10d %-10.9s", semid, pw->pw_name);
|
2005-06-20 10:00:36 +05:30
|
|
|
else
|
2006-10-27 04:51:47 +05:30
|
|
|
printf("%-10d %-9d", semid, ipcp->uid);
|
|
|
|
printf(" %-10o %-10ld\n", ipcp->mode & 0777,
|
2013-01-14 06:04:48 +05:30
|
|
|
/*
|
|
|
|
* 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);
|
2005-06-20 10:00:36 +05:30
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-08 17:40:23 +05:30
|
|
|
static NOINLINE void do_msg(int format)
|
2005-06-20 10:00:36 +05:30
|
|
|
{
|
|
|
|
int maxid, msqid, id;
|
|
|
|
struct msqid_ds msgque;
|
|
|
|
struct msginfo msginfo;
|
|
|
|
struct ipc_perm *ipcp = &msgque.msg_perm;
|
|
|
|
struct passwd *pw;
|
|
|
|
|
2006-08-29 05:01:54 +05:30
|
|
|
maxid = msgctl(0, MSG_INFO, (struct msqid_ds *) (void *) &msginfo);
|
2005-06-20 10:00:36 +05:30
|
|
|
if (maxid < 0) {
|
2006-10-27 04:51:47 +05:30
|
|
|
printf("kernel not configured for %s\n", "message queues");
|
2005-06-20 10:00:36 +05:30
|
|
|
return;
|
|
|
|
}
|
2006-01-25 05:38:53 +05:30
|
|
|
|
2005-06-20 10:00:36 +05:30
|
|
|
switch (format) {
|
|
|
|
case LIMITS:
|
2006-08-29 05:01:54 +05:30
|
|
|
if ((msgctl(0, IPC_INFO, (struct msqid_ds *) (void *) &msginfo)) < 0)
|
2005-06-20 10:00:36 +05:30
|
|
|
return;
|
2006-10-27 04:51:47 +05:30
|
|
|
printf("------ Message%s --------\n", "s: Limits");
|
2013-01-14 06:04:48 +05:30
|
|
|
printf("max queues system wide = %d\n"
|
|
|
|
"max size of message (bytes) = %d\n"
|
|
|
|
"default max size of queue (bytes) = %d\n",
|
|
|
|
msginfo.msgmni, msginfo.msgmax, msginfo.msgmnb);
|
2005-06-20 10:00:36 +05:30
|
|
|
return;
|
|
|
|
|
|
|
|
case STATUS:
|
2006-10-27 04:51:47 +05:30
|
|
|
printf("------ Message%s --------\n", "s: Status");
|
2013-01-14 06:04:48 +05:30
|
|
|
printf("allocated queues = %d\n"
|
|
|
|
"used headers = %d\n"
|
|
|
|
"used space = %d bytes\n",
|
|
|
|
msginfo.msgpool, msginfo.msgmap, msginfo.msgtql);
|
2005-06-20 10:00:36 +05:30
|
|
|
return;
|
|
|
|
|
|
|
|
case CREATOR:
|
2006-10-27 04:51:47 +05:30
|
|
|
printf("------ Message%s --------\n", " Queues: Creators/Owners");
|
2013-01-14 06:04:48 +05:30
|
|
|
printf("%-10s %-10s %-10s %-10s %-10s %-10s\n",
|
|
|
|
"msqid", "perms", "cuid", "cgid", "uid", "gid");
|
2005-06-20 10:00:36 +05:30
|
|
|
break;
|
|
|
|
|
|
|
|
case TIME:
|
2006-10-27 04:51:47 +05:30
|
|
|
printf("------ Message%s --------\n", " Queues Send/Recv/Change Times");
|
2013-01-14 06:04:48 +05:30
|
|
|
printf("%-8s %-10s %-20s %-20s %-20s\n",
|
|
|
|
"msqid", "owner", "send", "recv", "change");
|
2005-06-20 10:00:36 +05:30
|
|
|
break;
|
|
|
|
|
|
|
|
case PID:
|
2006-10-27 04:51:47 +05:30
|
|
|
printf("------ Message%s --------\n", " Queues PIDs");
|
2013-01-14 06:04:48 +05:30
|
|
|
printf("%-10s %-10s %-10s %-10s\n",
|
|
|
|
"msqid", "owner", "lspid", "lrpid");
|
2005-06-20 10:00:36 +05:30
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2006-10-27 04:51:47 +05:30
|
|
|
printf("------ Message%s --------\n", " Queues");
|
2013-01-14 06:04:48 +05:30
|
|
|
printf("%-10s %-10s %-10s %-10s %-12s %-12s\n",
|
|
|
|
"key", "msqid", "owner", "perms", "used-bytes", "messages");
|
2005-06-20 10:00:36 +05:30
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (id = 0; id <= maxid; id++) {
|
2006-08-29 05:01:54 +05:30
|
|
|
msqid = msgctl(id, MSG_STAT, &msgque);
|
2005-06-20 10:00:36 +05:30
|
|
|
if (msqid < 0)
|
|
|
|
continue;
|
2006-08-29 05:01:54 +05:30
|
|
|
if (format == CREATOR) {
|
|
|
|
print_perms(msqid, ipcp);
|
2005-06-20 10:00:36 +05:30
|
|
|
continue;
|
|
|
|
}
|
|
|
|
pw = getpwuid(ipcp->uid);
|
|
|
|
switch (format) {
|
|
|
|
case TIME:
|
|
|
|
if (pw)
|
2006-10-27 04:51:47 +05:30
|
|
|
printf("%-8d %-10.10s", msqid, pw->pw_name);
|
2005-06-20 10:00:36 +05:30
|
|
|
else
|
2006-10-27 04:51:47 +05:30
|
|
|
printf("%-8d %-10d", msqid, ipcp->uid);
|
|
|
|
printf(" %-20.16s", msgque.msg_stime
|
2013-01-14 06:04:48 +05:30
|
|
|
? ctime(&msgque.msg_stime) + 4 : "Not set");
|
2006-10-27 04:51:47 +05:30
|
|
|
printf(" %-20.16s", msgque.msg_rtime
|
2013-01-14 06:04:48 +05:30
|
|
|
? ctime(&msgque.msg_rtime) + 4 : "Not set");
|
2006-10-27 04:51:47 +05:30
|
|
|
printf(" %-20.16s\n", msgque.msg_ctime
|
2013-01-14 06:04:48 +05:30
|
|
|
? ctime(&msgque.msg_ctime) + 4 : "Not set");
|
2005-06-20 10:00:36 +05:30
|
|
|
break;
|
|
|
|
case PID:
|
|
|
|
if (pw)
|
2006-10-27 04:51:47 +05:30
|
|
|
printf("%-8d %-10.10s", msqid, pw->pw_name);
|
2005-06-20 10:00:36 +05:30
|
|
|
else
|
2006-10-27 04:51:47 +05:30
|
|
|
printf("%-8d %-10d", msqid, ipcp->uid);
|
|
|
|
printf(" %5d %5d\n", msgque.msg_lspid, msgque.msg_lrpid);
|
2005-06-20 10:00:36 +05:30
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2006-10-27 04:51:47 +05:30
|
|
|
printf("0x%08x ", ipcp->KEY);
|
2005-06-20 10:00:36 +05:30
|
|
|
if (pw)
|
2006-10-27 04:51:47 +05:30
|
|
|
printf("%-10d %-10.10s", msqid, pw->pw_name);
|
2005-06-20 10:00:36 +05:30
|
|
|
else
|
2006-10-27 04:51:47 +05:30
|
|
|
printf("%-10d %-10d", msqid, ipcp->uid);
|
|
|
|
printf(" %-10o %-12ld %-12ld\n", ipcp->mode & 0777,
|
2013-01-14 06:04:48 +05:30
|
|
|
/*
|
|
|
|
* 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);
|
2005-06-20 10:00:36 +05:30
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-29 05:01:54 +05:30
|
|
|
static void print_shm(int shmid)
|
2005-06-20 10:00:36 +05:30
|
|
|
{
|
|
|
|
struct shmid_ds shmds;
|
|
|
|
struct ipc_perm *ipcp = &shmds.shm_perm;
|
|
|
|
|
2006-08-29 05:01:54 +05:30
|
|
|
if (shmctl(shmid, IPC_STAT, &shmds) == -1) {
|
libbb: reduce the overhead of single parameter bb_error_msg() calls
Back in 2007, commit 0c97c9d43707 ("'simple' error message functions by
Loic Grenie") introduced bb_simple_perror_msg() to allow for a lower
overhead call to bb_perror_msg() when only a string was being printed
with no parameters. This saves space for some CPU architectures because
it avoids the overhead of a call to a variadic function. However there
has never been a simple version of bb_error_msg(), and since 2007 many
new calls to bb_perror_msg() have been added that only take a single
parameter and so could have been using bb_simple_perror_message().
This changeset introduces 'simple' versions of bb_info_msg(),
bb_error_msg(), bb_error_msg_and_die(), bb_herror_msg() and
bb_herror_msg_and_die(), and replaces all calls that only take a
single parameter, or use something like ("%s", arg), with calls to the
corresponding 'simple' version.
Since it is likely that single parameter calls to the variadic functions
may be accidentally reintroduced in the future a new debugging config
option WARN_SIMPLE_MSG has been introduced. This uses some macro magic
which will cause any such calls to generate a warning, but this is
turned off by default to avoid use of the unpleasant macros in normal
circumstances.
This is a large changeset due to the number of calls that have been
replaced. The only files that contain changes other than simple
substitution of function calls are libbb.h, libbb/herror_msg.c,
libbb/verror_msg.c and libbb/xfuncs_printf.c. In miscutils/devfsd.c,
networking/udhcp/common.h and util-linux/mdev.c additonal macros have
been added for logging so that single parameter and multiple parameter
logging variants exist.
The amount of space saved varies considerably by architecture, and was
found to be as follows (for 'defconfig' using GCC 7.4):
Arm: -92 bytes
MIPS: -52 bytes
PPC: -1836 bytes
x86_64: -938 bytes
Note that for the MIPS architecture only an exception had to be made
disabling the 'simple' calls for 'udhcp' (in networking/udhcp/common.h)
because it made these files larger on MIPS.
Signed-off-by: James Byrne <james.byrne@origamienergy.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-07-02 15:05:03 +05:30
|
|
|
bb_simple_perror_msg("shmctl");
|
2005-06-20 10:00:36 +05:30
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-10-27 04:51:47 +05:30
|
|
|
printf("\nShared memory Segment shmid=%d\n"
|
2013-01-14 06:04:48 +05:30
|
|
|
"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);
|
2006-10-27 04:51:47 +05:30
|
|
|
printf("att_time=%-26.24s\n",
|
2013-01-14 06:04:48 +05:30
|
|
|
shmds.shm_atime ? ctime(&shmds.shm_atime) : "Not set");
|
2006-10-27 04:51:47 +05:30
|
|
|
printf("det_time=%-26.24s\n",
|
2013-01-14 06:04:48 +05:30
|
|
|
shmds.shm_dtime ? ctime(&shmds.shm_dtime) : "Not set");
|
2006-10-27 04:51:47 +05:30
|
|
|
printf("change_time=%-26.24s\n\n", ctime(&shmds.shm_ctime));
|
2005-06-20 10:00:36 +05:30
|
|
|
}
|
|
|
|
|
2006-08-29 05:01:54 +05:30
|
|
|
static void print_msg(int msqid)
|
2005-06-20 10:00:36 +05:30
|
|
|
{
|
|
|
|
struct msqid_ds buf;
|
|
|
|
struct ipc_perm *ipcp = &buf.msg_perm;
|
|
|
|
|
2006-08-29 05:01:54 +05:30
|
|
|
if (msgctl(msqid, IPC_STAT, &buf) == -1) {
|
libbb: reduce the overhead of single parameter bb_error_msg() calls
Back in 2007, commit 0c97c9d43707 ("'simple' error message functions by
Loic Grenie") introduced bb_simple_perror_msg() to allow for a lower
overhead call to bb_perror_msg() when only a string was being printed
with no parameters. This saves space for some CPU architectures because
it avoids the overhead of a call to a variadic function. However there
has never been a simple version of bb_error_msg(), and since 2007 many
new calls to bb_perror_msg() have been added that only take a single
parameter and so could have been using bb_simple_perror_message().
This changeset introduces 'simple' versions of bb_info_msg(),
bb_error_msg(), bb_error_msg_and_die(), bb_herror_msg() and
bb_herror_msg_and_die(), and replaces all calls that only take a
single parameter, or use something like ("%s", arg), with calls to the
corresponding 'simple' version.
Since it is likely that single parameter calls to the variadic functions
may be accidentally reintroduced in the future a new debugging config
option WARN_SIMPLE_MSG has been introduced. This uses some macro magic
which will cause any such calls to generate a warning, but this is
turned off by default to avoid use of the unpleasant macros in normal
circumstances.
This is a large changeset due to the number of calls that have been
replaced. The only files that contain changes other than simple
substitution of function calls are libbb.h, libbb/herror_msg.c,
libbb/verror_msg.c and libbb/xfuncs_printf.c. In miscutils/devfsd.c,
networking/udhcp/common.h and util-linux/mdev.c additonal macros have
been added for logging so that single parameter and multiple parameter
logging variants exist.
The amount of space saved varies considerably by architecture, and was
found to be as follows (for 'defconfig' using GCC 7.4):
Arm: -92 bytes
MIPS: -52 bytes
PPC: -1836 bytes
x86_64: -938 bytes
Note that for the MIPS architecture only an exception had to be made
disabling the 'simple' calls for 'udhcp' (in networking/udhcp/common.h)
because it made these files larger on MIPS.
Signed-off-by: James Byrne <james.byrne@origamienergy.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-07-02 15:05:03 +05:30
|
|
|
bb_simple_perror_msg("msgctl");
|
2005-06-20 10:00:36 +05:30
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-10-27 04:51:47 +05:30
|
|
|
printf("\nMessage Queue msqid=%d\n"
|
2013-01-14 06:04:48 +05:30
|
|
|
"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);
|
2006-08-29 05:01:54 +05:30
|
|
|
|
2006-10-27 04:51:47 +05:30
|
|
|
printf("send_time=%-26.24s\n",
|
2013-01-14 06:04:48 +05:30
|
|
|
buf.msg_stime ? ctime(&buf.msg_stime) : "Not set");
|
2006-10-27 04:51:47 +05:30
|
|
|
printf("rcv_time=%-26.24s\n",
|
2013-01-14 06:04:48 +05:30
|
|
|
buf.msg_rtime ? ctime(&buf.msg_rtime) : "Not set");
|
2006-10-27 04:51:47 +05:30
|
|
|
printf("change_time=%-26.24s\n\n",
|
2013-01-14 06:04:48 +05:30
|
|
|
buf.msg_ctime ? ctime(&buf.msg_ctime) : "Not set");
|
2005-06-20 10:00:36 +05:30
|
|
|
}
|
|
|
|
|
2006-08-29 05:01:54 +05:30
|
|
|
static void print_sem(int semid)
|
2005-06-20 10:00:36 +05:30
|
|
|
{
|
|
|
|
struct semid_ds semds;
|
|
|
|
struct ipc_perm *ipcp = &semds.sem_perm;
|
|
|
|
union semun arg;
|
2006-04-03 16:55:48 +05:30
|
|
|
unsigned int i;
|
2005-06-20 10:00:36 +05:30
|
|
|
|
|
|
|
arg.buf = &semds;
|
2006-08-29 05:01:54 +05:30
|
|
|
if (semctl(semid, 0, IPC_STAT, arg)) {
|
libbb: reduce the overhead of single parameter bb_error_msg() calls
Back in 2007, commit 0c97c9d43707 ("'simple' error message functions by
Loic Grenie") introduced bb_simple_perror_msg() to allow for a lower
overhead call to bb_perror_msg() when only a string was being printed
with no parameters. This saves space for some CPU architectures because
it avoids the overhead of a call to a variadic function. However there
has never been a simple version of bb_error_msg(), and since 2007 many
new calls to bb_perror_msg() have been added that only take a single
parameter and so could have been using bb_simple_perror_message().
This changeset introduces 'simple' versions of bb_info_msg(),
bb_error_msg(), bb_error_msg_and_die(), bb_herror_msg() and
bb_herror_msg_and_die(), and replaces all calls that only take a
single parameter, or use something like ("%s", arg), with calls to the
corresponding 'simple' version.
Since it is likely that single parameter calls to the variadic functions
may be accidentally reintroduced in the future a new debugging config
option WARN_SIMPLE_MSG has been introduced. This uses some macro magic
which will cause any such calls to generate a warning, but this is
turned off by default to avoid use of the unpleasant macros in normal
circumstances.
This is a large changeset due to the number of calls that have been
replaced. The only files that contain changes other than simple
substitution of function calls are libbb.h, libbb/herror_msg.c,
libbb/verror_msg.c and libbb/xfuncs_printf.c. In miscutils/devfsd.c,
networking/udhcp/common.h and util-linux/mdev.c additonal macros have
been added for logging so that single parameter and multiple parameter
logging variants exist.
The amount of space saved varies considerably by architecture, and was
found to be as follows (for 'defconfig' using GCC 7.4):
Arm: -92 bytes
MIPS: -52 bytes
PPC: -1836 bytes
x86_64: -938 bytes
Note that for the MIPS architecture only an exception had to be made
disabling the 'simple' calls for 'udhcp' (in networking/udhcp/common.h)
because it made these files larger on MIPS.
Signed-off-by: James Byrne <james.byrne@origamienergy.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-07-02 15:05:03 +05:30
|
|
|
bb_simple_perror_msg("semctl");
|
2005-06-20 10:00:36 +05:30
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-10-27 04:51:47 +05:30
|
|
|
printf("\nSemaphore Array semid=%d\n"
|
2013-01-14 06:04:48 +05:30
|
|
|
"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");
|
2006-10-27 04:51:47 +05:30
|
|
|
printf("ctime = %-26.24s\n"
|
2013-01-14 06:04:48 +05:30
|
|
|
"%-10s %-10s %-10s %-10s %-10s\n",
|
|
|
|
ctime(&semds.sem_ctime),
|
|
|
|
"semnum", "value", "ncount", "zcount", "pid");
|
2005-06-20 10:00:36 +05:30
|
|
|
|
|
|
|
arg.val = 0;
|
2006-08-29 05:01:54 +05:30
|
|
|
for (i = 0; i < semds.sem_nsems; i++) {
|
2005-06-20 10:00:36 +05:30
|
|
|
int val, ncnt, zcnt, pid;
|
2006-08-29 05:01:54 +05:30
|
|
|
|
|
|
|
val = semctl(semid, i, GETVAL, arg);
|
|
|
|
ncnt = semctl(semid, i, GETNCNT, arg);
|
|
|
|
zcnt = semctl(semid, i, GETZCNT, arg);
|
|
|
|
pid = semctl(semid, i, GETPID, arg);
|
2005-06-20 10:00:36 +05:30
|
|
|
if (val < 0 || ncnt < 0 || zcnt < 0 || pid < 0) {
|
libbb: reduce the overhead of single parameter bb_error_msg() calls
Back in 2007, commit 0c97c9d43707 ("'simple' error message functions by
Loic Grenie") introduced bb_simple_perror_msg() to allow for a lower
overhead call to bb_perror_msg() when only a string was being printed
with no parameters. This saves space for some CPU architectures because
it avoids the overhead of a call to a variadic function. However there
has never been a simple version of bb_error_msg(), and since 2007 many
new calls to bb_perror_msg() have been added that only take a single
parameter and so could have been using bb_simple_perror_message().
This changeset introduces 'simple' versions of bb_info_msg(),
bb_error_msg(), bb_error_msg_and_die(), bb_herror_msg() and
bb_herror_msg_and_die(), and replaces all calls that only take a
single parameter, or use something like ("%s", arg), with calls to the
corresponding 'simple' version.
Since it is likely that single parameter calls to the variadic functions
may be accidentally reintroduced in the future a new debugging config
option WARN_SIMPLE_MSG has been introduced. This uses some macro magic
which will cause any such calls to generate a warning, but this is
turned off by default to avoid use of the unpleasant macros in normal
circumstances.
This is a large changeset due to the number of calls that have been
replaced. The only files that contain changes other than simple
substitution of function calls are libbb.h, libbb/herror_msg.c,
libbb/verror_msg.c and libbb/xfuncs_printf.c. In miscutils/devfsd.c,
networking/udhcp/common.h and util-linux/mdev.c additonal macros have
been added for logging so that single parameter and multiple parameter
logging variants exist.
The amount of space saved varies considerably by architecture, and was
found to be as follows (for 'defconfig' using GCC 7.4):
Arm: -92 bytes
MIPS: -52 bytes
PPC: -1836 bytes
x86_64: -938 bytes
Note that for the MIPS architecture only an exception had to be made
disabling the 'simple' calls for 'udhcp' (in networking/udhcp/common.h)
because it made these files larger on MIPS.
Signed-off-by: James Byrne <james.byrne@origamienergy.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-07-02 15:05:03 +05:30
|
|
|
bb_simple_perror_msg_and_die("semctl");
|
2005-06-20 10:00:36 +05:30
|
|
|
}
|
2013-11-29 21:15:45 +05:30
|
|
|
printf("%-10u %-10d %-10d %-10d %-10d\n", i, val, ncnt, zcnt, pid);
|
2005-06-20 10:00:36 +05:30
|
|
|
}
|
2007-09-27 15:50:47 +05:30
|
|
|
bb_putchar('\n');
|
2005-06-20 10:00:36 +05:30
|
|
|
}
|
2006-04-03 16:55:48 +05:30
|
|
|
|
2017-08-09 22:54:19 +05:30
|
|
|
//usage:#define ipcs_trivial_usage
|
2018-03-08 17:40:23 +05:30
|
|
|
//usage: "[[-smq] -i SHMID] | [[-asmq] [-tcplu]]"
|
2017-08-09 22:54:19 +05:30
|
|
|
//usage:#define ipcs_full_usage "\n\n"
|
2018-03-08 17:53:06 +05:30
|
|
|
//usage: " -i ID Show specific resource"
|
2017-08-09 22:54:19 +05:30
|
|
|
//usage: "\nResource specification:"
|
|
|
|
//usage: "\n -m Shared memory segments"
|
|
|
|
//usage: "\n -q Message queues"
|
|
|
|
//usage: "\n -s Semaphore arrays"
|
|
|
|
//usage: "\n -a All (default)"
|
|
|
|
//usage: "\nOutput format:"
|
|
|
|
//usage: "\n -t Time"
|
|
|
|
//usage: "\n -c Creator"
|
|
|
|
//usage: "\n -p Pid"
|
|
|
|
//usage: "\n -l Limits"
|
|
|
|
//usage: "\n -u Summary"
|
|
|
|
|
2007-10-11 15:35:36 +05:30
|
|
|
int ipcs_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
2008-07-05 14:48:54 +05:30
|
|
|
int ipcs_main(int argc UNUSED_PARAM, char **argv)
|
2006-08-29 05:01:54 +05:30
|
|
|
{
|
2018-03-08 17:40:23 +05:30
|
|
|
int format = 0;
|
2006-10-04 02:30:06 +05:30
|
|
|
unsigned opt;
|
2006-09-19 23:10:31 +05:30
|
|
|
char *opt_i;
|
2006-08-29 05:01:54 +05:30
|
|
|
|
2007-08-18 21:02:12 +05:30
|
|
|
opt = getopt32(argv, "i:aqsmtcplu", &opt_i);
|
2018-03-08 17:53:06 +05:30
|
|
|
#define flag_msg (1<<2)
|
|
|
|
#define flag_sem (1<<3)
|
|
|
|
#define flag_shm (1<<4)
|
|
|
|
if (opt & (1<<5)) format = TIME; // -t
|
|
|
|
if (opt & (1<<6)) format = CREATOR; // -c
|
|
|
|
if (opt & (1<<7)) format = PID; // -p
|
|
|
|
if (opt & (1<<8)) format = LIMITS; // -l
|
|
|
|
if (opt & (1<<9)) format = STATUS; // -u
|
|
|
|
|
|
|
|
if (opt & (1<<0)) { // -i
|
2018-03-08 17:40:23 +05:30
|
|
|
int id;
|
|
|
|
|
|
|
|
id = xatoi(opt_i);
|
2018-03-08 17:53:06 +05:30
|
|
|
if (opt & flag_shm) {
|
2006-08-29 05:01:54 +05:30
|
|
|
print_shm(id);
|
2008-05-19 14:59:47 +05:30
|
|
|
fflush_stdout_and_exit(EXIT_SUCCESS);
|
2006-04-03 16:55:48 +05:30
|
|
|
}
|
2018-03-08 17:53:06 +05:30
|
|
|
if (opt & flag_sem) {
|
2006-08-29 05:01:54 +05:30
|
|
|
print_sem(id);
|
2008-05-19 14:59:47 +05:30
|
|
|
fflush_stdout_and_exit(EXIT_SUCCESS);
|
2006-04-03 16:55:48 +05:30
|
|
|
}
|
2018-03-08 17:53:06 +05:30
|
|
|
if (opt & flag_msg) {
|
2006-08-29 05:01:54 +05:30
|
|
|
print_msg(id);
|
2008-05-19 14:59:47 +05:30
|
|
|
fflush_stdout_and_exit(EXIT_SUCCESS);
|
2006-04-03 16:55:48 +05:30
|
|
|
}
|
|
|
|
bb_show_usage();
|
|
|
|
}
|
|
|
|
|
2018-03-08 17:53:06 +05:30
|
|
|
if ((opt & (1<<1)) // -a
|
|
|
|
|| !(opt & (flag_msg | flag_sem | flag_shm)) // none of -q,-s,-m == all
|
|
|
|
) {
|
|
|
|
opt |= flag_msg | flag_sem | flag_shm;
|
|
|
|
}
|
|
|
|
|
2007-09-27 15:50:47 +05:30
|
|
|
bb_putchar('\n');
|
2006-04-03 16:55:48 +05:30
|
|
|
|
2018-03-08 17:53:06 +05:30
|
|
|
if (opt & flag_msg) {
|
2018-03-08 17:40:23 +05:30
|
|
|
do_msg(format);
|
2017-08-09 22:57:01 +05:30
|
|
|
bb_putchar('\n');
|
|
|
|
}
|
2018-03-08 17:53:06 +05:30
|
|
|
if (opt & flag_shm) {
|
2018-03-08 17:40:23 +05:30
|
|
|
do_shm(format);
|
2007-09-27 15:50:47 +05:30
|
|
|
bb_putchar('\n');
|
2006-04-03 16:55:48 +05:30
|
|
|
}
|
2018-03-08 17:53:06 +05:30
|
|
|
if (opt & flag_sem) {
|
2018-03-08 17:40:23 +05:30
|
|
|
do_sem(format);
|
2007-09-27 15:50:47 +05:30
|
|
|
bb_putchar('\n');
|
2006-04-03 16:55:48 +05:30
|
|
|
}
|
2008-05-19 14:59:47 +05:30
|
|
|
fflush_stdout_and_exit(EXIT_SUCCESS);
|
2006-04-03 16:55:48 +05:30
|
|
|
}
|