ipcs.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * ipcs.c -- provides information on allocated ipc resources.
  4. *
  5. * 01 Sept 2004 - Rodney Radford <rradford@mindspring.com>
  6. * Adapted for busybox from util-linux-2.12a.
  7. *
  8. * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
  9. */
  10. #include "busybox.h"
  11. #include <errno.h>
  12. #include <time.h>
  13. #include <pwd.h>
  14. #include <grp.h>
  15. /* X/OPEN tells us to use <sys/{types,ipc,sem}.h> for semctl() */
  16. /* X/OPEN tells us to use <sys/{types,ipc,msg}.h> for msgctl() */
  17. /* X/OPEN tells us to use <sys/{types,ipc,shm}.h> for shmctl() */
  18. #include <sys/types.h>
  19. #include <sys/ipc.h>
  20. #include <sys/sem.h>
  21. #include <sys/msg.h>
  22. #include <sys/shm.h>
  23. /*-------------------------------------------------------------------*/
  24. /* SHM_DEST and SHM_LOCKED are defined in kernel headers,
  25. but inside #ifdef __KERNEL__ ... #endif */
  26. #ifndef SHM_DEST
  27. /* shm_mode upper byte flags */
  28. #define SHM_DEST 01000 /* segment will be destroyed on last detach */
  29. #define SHM_LOCKED 02000 /* segment will not be swapped */
  30. #endif
  31. /* For older kernels the same holds for the defines below */
  32. #ifndef MSG_STAT
  33. #define MSG_STAT 11
  34. #define MSG_INFO 12
  35. #endif
  36. #ifndef SHM_STAT
  37. #define SHM_STAT 13
  38. #define SHM_INFO 14
  39. struct shm_info {
  40. int used_ids;
  41. ulong shm_tot; /* total allocated shm */
  42. ulong shm_rss; /* total resident shm */
  43. ulong shm_swp; /* total swapped shm */
  44. ulong swap_attempts;
  45. ulong swap_successes;
  46. };
  47. #endif
  48. #ifndef SEM_STAT
  49. #define SEM_STAT 18
  50. #define SEM_INFO 19
  51. #endif
  52. /* Some versions of libc only define IPC_INFO when __USE_GNU is defined. */
  53. #ifndef IPC_INFO
  54. #define IPC_INFO 3
  55. #endif
  56. /*-------------------------------------------------------------------*/
  57. /* The last arg of semctl is a union semun, but where is it defined?
  58. X/OPEN tells us to define it ourselves, but until recently
  59. Linux include files would also define it. */
  60. #if defined (__GNU_LIBRARY__) && !defined(_SEM_SEMUN_UNDEFINED)
  61. /* union semun is defined by including <sys/sem.h> */
  62. #else
  63. /* according to X/OPEN we have to define it ourselves */
  64. union semun {
  65. int val;
  66. struct semid_ds *buf;
  67. unsigned short int *array;
  68. struct seminfo *__buf;
  69. };
  70. #endif
  71. /* X/OPEN (Jan 1987) does not define fields key, seq in struct ipc_perm;
  72. libc 4/5 does not mention struct ipc_term at all, but includes
  73. <linux/ipc.h>, which defines a struct ipc_perm with such fields.
  74. glibc-1.09 has no support for sysv ipc.
  75. glibc 2 uses __key, __seq */
  76. #if defined (__GNU_LIBRARY__) && __GNU_LIBRARY__ > 1
  77. #define KEY __key
  78. #else
  79. #define KEY key
  80. #endif
  81. #define LIMITS 1
  82. #define STATUS 2
  83. #define CREATOR 3
  84. #define TIME 4
  85. #define PID 5
  86. static char format;
  87. static void print_perms(int id, struct ipc_perm *ipcp)
  88. {
  89. struct passwd *pw;
  90. struct group *gr;
  91. printf("%-10d %-10o", id, ipcp->mode & 0777);
  92. if ((pw = getpwuid(ipcp->cuid)))
  93. printf(" %-10s", pw->pw_name);
  94. else
  95. printf(" %-10d", ipcp->cuid);
  96. if ((gr = getgrgid(ipcp->cgid)))
  97. printf(" %-10s", gr->gr_name);
  98. else
  99. printf(" %-10d", ipcp->cgid);
  100. if ((pw = getpwuid(ipcp->uid)))
  101. printf(" %-10s", pw->pw_name);
  102. else
  103. printf(" %-10d", ipcp->uid);
  104. if ((gr = getgrgid(ipcp->gid)))
  105. printf(" %-10s\n", gr->gr_name);
  106. else
  107. printf(" %-10d\n", ipcp->gid);
  108. }
  109. static void do_shm(void)
  110. {
  111. int maxid, shmid, id;
  112. struct shmid_ds shmseg;
  113. struct shm_info shm_info;
  114. struct shminfo shminfo;
  115. struct ipc_perm *ipcp = &shmseg.shm_perm;
  116. struct passwd *pw;
  117. maxid = shmctl(0, SHM_INFO, (struct shmid_ds *) (void *) &shm_info);
  118. if (maxid < 0) {
  119. printf("kernel not configured for %s\n", "shared memory");
  120. return;
  121. }
  122. switch (format) {
  123. case LIMITS:
  124. printf("------ Shared Memory %s --------\n", "Limits");
  125. if ((shmctl(0, IPC_INFO, (struct shmid_ds *) (void *) &shminfo)) < 0)
  126. return;
  127. /* glibc 2.1.3 and all earlier libc's have ints as fields
  128. of struct shminfo; glibc 2.1.91 has unsigned long; ach */
  129. printf("max number of segments = %lu\n"
  130. "max seg size (kbytes) = %lu\n"
  131. "max total shared memory (pages) = %lu\n"
  132. "min seg size (bytes) = %lu\n",
  133. (unsigned long) shminfo.shmmni,
  134. (unsigned long) (shminfo.shmmax >> 10),
  135. (unsigned long) shminfo.shmall,
  136. (unsigned long) shminfo.shmmin);
  137. return;
  138. case STATUS:
  139. printf("------ Shared Memory %s --------\n", "Status");
  140. printf( "segments allocated %d\n"
  141. "pages allocated %ld\n"
  142. "pages resident %ld\n"
  143. "pages swapped %ld\n"
  144. "Swap performance: %ld attempts\t%ld successes\n",
  145. shm_info.used_ids,
  146. shm_info.shm_tot,
  147. shm_info.shm_rss,
  148. shm_info.shm_swp,
  149. shm_info.swap_attempts, shm_info.swap_successes);
  150. return;
  151. case CREATOR:
  152. printf("------ Shared Memory %s --------\n", "Segment Creators/Owners");
  153. printf( "%-10s %-10s %-10s %-10s %-10s %-10s\n",
  154. "shmid", "perms", "cuid", "cgid", "uid", "gid");
  155. break;
  156. case TIME:
  157. printf("------ Shared Memory %s --------\n", "Attach/Detach/Change Times");
  158. printf( "%-10s %-10s %-20s %-20s %-20s\n",
  159. "shmid", "owner", "attached", "detached", "changed");
  160. break;
  161. case PID:
  162. printf("------ Shared Memory %s --------\n", "Creator/Last-op");
  163. printf( "%-10s %-10s %-10s %-10s\n",
  164. "shmid", "owner", "cpid", "lpid");
  165. break;
  166. default:
  167. printf("------ Shared Memory %s --------\n", "Segments");
  168. printf( "%-10s %-10s %-10s %-10s %-10s %-10s %-12s\n",
  169. "key", "shmid", "owner", "perms", "bytes", "nattch",
  170. "status");
  171. break;
  172. }
  173. for (id = 0; id <= maxid; id++) {
  174. shmid = shmctl(id, SHM_STAT, &shmseg);
  175. if (shmid < 0)
  176. continue;
  177. if (format == CREATOR) {
  178. print_perms(shmid, ipcp);
  179. continue;
  180. }
  181. pw = getpwuid(ipcp->uid);
  182. switch (format) {
  183. case TIME:
  184. if (pw)
  185. printf("%-10d %-10.10s", shmid, pw->pw_name);
  186. else
  187. printf("%-10d %-10d", shmid, ipcp->uid);
  188. /* ctime uses static buffer: use separate calls */
  189. printf(" %-20.16s", shmseg.shm_atime
  190. ? ctime(&shmseg.shm_atime) + 4 : "Not set");
  191. printf(" %-20.16s", shmseg.shm_dtime
  192. ? ctime(&shmseg.shm_dtime) + 4 : "Not set");
  193. printf(" %-20.16s\n", shmseg.shm_ctime
  194. ? ctime(&shmseg.shm_ctime) + 4 : "Not set");
  195. break;
  196. case PID:
  197. if (pw)
  198. printf("%-10d %-10.10s", shmid, pw->pw_name);
  199. else
  200. printf("%-10d %-10d", shmid, ipcp->uid);
  201. printf(" %-10d %-10d\n", shmseg.shm_cpid, shmseg.shm_lpid);
  202. break;
  203. default:
  204. printf("0x%08x ", ipcp->KEY);
  205. if (pw)
  206. printf("%-10d %-10.10s", shmid, pw->pw_name);
  207. else
  208. printf("%-10d %-10d", shmid, ipcp->uid);
  209. printf(" %-10o %-10lu %-10ld %-6s %-6s\n", ipcp->mode & 0777,
  210. /*
  211. * earlier: int, Austin has size_t
  212. */
  213. (unsigned long) shmseg.shm_segsz,
  214. /*
  215. * glibc-2.1.3 and earlier has unsigned short;
  216. * Austin has shmatt_t
  217. */
  218. (long) shmseg.shm_nattch,
  219. ipcp->mode & SHM_DEST ? "dest" : " ",
  220. ipcp->mode & SHM_LOCKED ? "locked" : " ");
  221. break;
  222. }
  223. }
  224. }
  225. static void do_sem(void)
  226. {
  227. int maxid, semid, id;
  228. struct semid_ds semary;
  229. struct seminfo seminfo;
  230. struct ipc_perm *ipcp = &semary.sem_perm;
  231. struct passwd *pw;
  232. union semun arg;
  233. arg.array = (ushort *) (void *) &seminfo;
  234. maxid = semctl(0, 0, SEM_INFO, arg);
  235. if (maxid < 0) {
  236. printf("kernel not configured for %s\n", "semaphores");
  237. return;
  238. }
  239. switch (format) {
  240. case LIMITS:
  241. printf("------ Semaphore %s --------\n", "Limits");
  242. arg.array = (ushort *) (void *) &seminfo; /* damn union */
  243. if ((semctl(0, 0, IPC_INFO, arg)) < 0)
  244. return;
  245. printf("max number of arrays = %d\n"
  246. "max semaphores per array = %d\n"
  247. "max semaphores system wide = %d\n"
  248. "max ops per semop call = %d\n"
  249. "semaphore max value = %d\n",
  250. seminfo.semmni,
  251. seminfo.semmsl,
  252. seminfo.semmns, seminfo.semopm, seminfo.semvmx);
  253. return;
  254. case STATUS:
  255. printf("------ Semaphore %s --------\n", "Status");
  256. printf( "used arrays = %d\n"
  257. "allocated semaphores = %d\n",
  258. seminfo.semusz, seminfo.semaem);
  259. return;
  260. case CREATOR:
  261. printf("------ Semaphore %s --------\n", "Arrays Creators/Owners");
  262. printf( "%-10s %-10s %-10s %-10s %-10s %-10s\n",
  263. "semid", "perms", "cuid", "cgid", "uid", "gid");
  264. break;
  265. case TIME:
  266. printf("------ Shared Memory %s --------\n", "Operation/Change Times");
  267. printf( "%-8s %-10s %-26.24s %-26.24s\n",
  268. "shmid", "owner", "last-op", "last-changed");
  269. break;
  270. case PID:
  271. break;
  272. default:
  273. printf("------ Semaphore %s --------\n", "Arrays");
  274. printf( "%-10s %-10s %-10s %-10s %-10s\n",
  275. "key", "semid", "owner", "perms", "nsems");
  276. break;
  277. }
  278. for (id = 0; id <= maxid; id++) {
  279. arg.buf = (struct semid_ds *) &semary;
  280. semid = semctl(id, 0, SEM_STAT, arg);
  281. if (semid < 0)
  282. continue;
  283. if (format == CREATOR) {
  284. print_perms(semid, ipcp);
  285. continue;
  286. }
  287. pw = getpwuid(ipcp->uid);
  288. switch (format) {
  289. case TIME:
  290. if (pw)
  291. printf("%-8d %-10.10s", semid, pw->pw_name);
  292. else
  293. printf("%-8d %-10d", semid, ipcp->uid);
  294. /* ctime uses static buffer: use separate calls */
  295. printf(" %-26.24s", semary.sem_otime
  296. ? ctime(&semary.sem_otime) : "Not set");
  297. printf(" %-26.24s\n", semary.sem_ctime
  298. ? ctime(&semary.sem_ctime) : "Not set");
  299. break;
  300. case PID:
  301. break;
  302. default:
  303. printf("0x%08x ", ipcp->KEY);
  304. if (pw)
  305. printf("%-10d %-10.9s", semid, pw->pw_name);
  306. else
  307. printf("%-10d %-9d", semid, ipcp->uid);
  308. printf(" %-10o %-10ld\n", ipcp->mode & 0777,
  309. /*
  310. * glibc-2.1.3 and earlier has unsigned short;
  311. * glibc-2.1.91 has variation between
  312. * unsigned short and unsigned long
  313. * Austin prescribes unsigned short.
  314. */
  315. (long) semary.sem_nsems);
  316. break;
  317. }
  318. }
  319. }
  320. static void do_msg(void)
  321. {
  322. int maxid, msqid, id;
  323. struct msqid_ds msgque;
  324. struct msginfo msginfo;
  325. struct ipc_perm *ipcp = &msgque.msg_perm;
  326. struct passwd *pw;
  327. maxid = msgctl(0, MSG_INFO, (struct msqid_ds *) (void *) &msginfo);
  328. if (maxid < 0) {
  329. printf("kernel not configured for %s\n", "message queues");
  330. return;
  331. }
  332. switch (format) {
  333. case LIMITS:
  334. if ((msgctl(0, IPC_INFO, (struct msqid_ds *) (void *) &msginfo)) < 0)
  335. return;
  336. printf("------ Message%s --------\n", "s: Limits");
  337. printf( "max queues system wide = %d\n"
  338. "max size of message (bytes) = %d\n"
  339. "default max size of queue (bytes) = %d\n",
  340. msginfo.msgmni, msginfo.msgmax, msginfo.msgmnb);
  341. return;
  342. case STATUS:
  343. printf("------ Message%s --------\n", "s: Status");
  344. printf( "allocated queues = %d\n"
  345. "used headers = %d\n"
  346. "used space = %d bytes\n",
  347. msginfo.msgpool, msginfo.msgmap, msginfo.msgtql);
  348. return;
  349. case CREATOR:
  350. printf("------ Message%s --------\n", " Queues: Creators/Owners");
  351. printf( "%-10s %-10s %-10s %-10s %-10s %-10s\n",
  352. "msqid", "perms", "cuid", "cgid", "uid", "gid");
  353. break;
  354. case TIME:
  355. printf("------ Message%s --------\n", " Queues Send/Recv/Change Times");
  356. printf( "%-8s %-10s %-20s %-20s %-20s\n",
  357. "msqid", "owner", "send", "recv", "change");
  358. break;
  359. case PID:
  360. printf("------ Message%s --------\n", " Queues PIDs");
  361. printf( "%-10s %-10s %-10s %-10s\n",
  362. "msqid", "owner", "lspid", "lrpid");
  363. break;
  364. default:
  365. printf("------ Message%s --------\n", " Queues");
  366. printf( "%-10s %-10s %-10s %-10s %-12s %-12s\n",
  367. "key", "msqid", "owner", "perms", "used-bytes", "messages");
  368. break;
  369. }
  370. for (id = 0; id <= maxid; id++) {
  371. msqid = msgctl(id, MSG_STAT, &msgque);
  372. if (msqid < 0)
  373. continue;
  374. if (format == CREATOR) {
  375. print_perms(msqid, ipcp);
  376. continue;
  377. }
  378. pw = getpwuid(ipcp->uid);
  379. switch (format) {
  380. case TIME:
  381. if (pw)
  382. printf("%-8d %-10.10s", msqid, pw->pw_name);
  383. else
  384. printf("%-8d %-10d", msqid, ipcp->uid);
  385. printf(" %-20.16s", msgque.msg_stime
  386. ? ctime(&msgque.msg_stime) + 4 : "Not set");
  387. printf(" %-20.16s", msgque.msg_rtime
  388. ? ctime(&msgque.msg_rtime) + 4 : "Not set");
  389. printf(" %-20.16s\n", msgque.msg_ctime
  390. ? ctime(&msgque.msg_ctime) + 4 : "Not set");
  391. break;
  392. case PID:
  393. if (pw)
  394. printf("%-8d %-10.10s", msqid, pw->pw_name);
  395. else
  396. printf("%-8d %-10d", msqid, ipcp->uid);
  397. printf(" %5d %5d\n", msgque.msg_lspid, msgque.msg_lrpid);
  398. break;
  399. default:
  400. printf("0x%08x ", ipcp->KEY);
  401. if (pw)
  402. printf("%-10d %-10.10s", msqid, pw->pw_name);
  403. else
  404. printf("%-10d %-10d", msqid, ipcp->uid);
  405. printf(" %-10o %-12ld %-12ld\n", ipcp->mode & 0777,
  406. /*
  407. * glibc-2.1.3 and earlier has unsigned short;
  408. * glibc-2.1.91 has variation between
  409. * unsigned short, unsigned long
  410. * Austin has msgqnum_t
  411. */
  412. (long) msgque.msg_cbytes, (long) msgque.msg_qnum);
  413. break;
  414. }
  415. }
  416. }
  417. static void print_shm(int shmid)
  418. {
  419. struct shmid_ds shmds;
  420. struct ipc_perm *ipcp = &shmds.shm_perm;
  421. if (shmctl(shmid, IPC_STAT, &shmds) == -1) {
  422. bb_perror_msg("shmctl");
  423. return;
  424. }
  425. printf("\nShared memory Segment shmid=%d\n"
  426. "uid=%d\tgid=%d\tcuid=%d\tcgid=%d\n"
  427. "mode=%#o\taccess_perms=%#o\n"
  428. "bytes=%ld\tlpid=%d\tcpid=%d\tnattch=%ld\n",
  429. shmid,
  430. ipcp->uid, ipcp->gid, ipcp->cuid, ipcp->cgid,
  431. ipcp->mode, ipcp->mode & 0777,
  432. (long) shmds.shm_segsz, shmds.shm_lpid, shmds.shm_cpid,
  433. (long) shmds.shm_nattch);
  434. printf("att_time=%-26.24s\n",
  435. shmds.shm_atime ? ctime(&shmds.shm_atime) : "Not set");
  436. printf("det_time=%-26.24s\n",
  437. shmds.shm_dtime ? ctime(&shmds.shm_dtime) : "Not set");
  438. printf("change_time=%-26.24s\n\n", ctime(&shmds.shm_ctime));
  439. }
  440. static void print_msg(int msqid)
  441. {
  442. struct msqid_ds buf;
  443. struct ipc_perm *ipcp = &buf.msg_perm;
  444. if (msgctl(msqid, IPC_STAT, &buf) == -1) {
  445. bb_perror_msg("msgctl");
  446. return;
  447. }
  448. printf("\nMessage Queue msqid=%d\n"
  449. "uid=%d\tgid=%d\tcuid=%d\tcgid=%d\tmode=%#o\n"
  450. "cbytes=%ld\tqbytes=%ld\tqnum=%ld\tlspid=%d\tlrpid=%d\n",
  451. msqid, ipcp->uid, ipcp->gid, ipcp->cuid, ipcp->cgid, ipcp->mode,
  452. /*
  453. * glibc-2.1.3 and earlier has unsigned short;
  454. * glibc-2.1.91 has variation between
  455. * unsigned short, unsigned long
  456. * Austin has msgqnum_t (for msg_qbytes)
  457. */
  458. (long) buf.msg_cbytes, (long) buf.msg_qbytes,
  459. (long) buf.msg_qnum, buf.msg_lspid, buf.msg_lrpid);
  460. printf("send_time=%-26.24s\n",
  461. buf.msg_stime ? ctime(&buf.msg_stime) : "Not set");
  462. printf("rcv_time=%-26.24s\n",
  463. buf.msg_rtime ? ctime(&buf.msg_rtime) : "Not set");
  464. printf("change_time=%-26.24s\n\n",
  465. buf.msg_ctime ? ctime(&buf.msg_ctime) : "Not set");
  466. }
  467. static void print_sem(int semid)
  468. {
  469. struct semid_ds semds;
  470. struct ipc_perm *ipcp = &semds.sem_perm;
  471. union semun arg;
  472. unsigned int i;
  473. arg.buf = &semds;
  474. if (semctl(semid, 0, IPC_STAT, arg)) {
  475. bb_perror_msg("semctl");
  476. return;
  477. }
  478. printf("\nSemaphore Array semid=%d\n"
  479. "uid=%d\t gid=%d\t cuid=%d\t cgid=%d\n"
  480. "mode=%#o, access_perms=%#o\n"
  481. "nsems = %ld\n"
  482. "otime = %-26.24s\n",
  483. semid,
  484. ipcp->uid, ipcp->gid, ipcp->cuid, ipcp->cgid,
  485. ipcp->mode, ipcp->mode & 0777,
  486. (long) semds.sem_nsems,
  487. semds.sem_otime ? ctime(&semds.sem_otime) : "Not set");
  488. printf("ctime = %-26.24s\n"
  489. "%-10s %-10s %-10s %-10s %-10s\n",
  490. ctime(&semds.sem_ctime),
  491. "semnum", "value", "ncount", "zcount", "pid");
  492. arg.val = 0;
  493. for (i = 0; i < semds.sem_nsems; i++) {
  494. int val, ncnt, zcnt, pid;
  495. val = semctl(semid, i, GETVAL, arg);
  496. ncnt = semctl(semid, i, GETNCNT, arg);
  497. zcnt = semctl(semid, i, GETZCNT, arg);
  498. pid = semctl(semid, i, GETPID, arg);
  499. if (val < 0 || ncnt < 0 || zcnt < 0 || pid < 0) {
  500. bb_perror_msg_and_die("semctl");
  501. }
  502. printf("%-10d %-10d %-10d %-10d %-10d\n", i, val, ncnt, zcnt, pid);
  503. }
  504. puts("");
  505. }
  506. int ipcs_main(int argc, char **argv)
  507. {
  508. int id = 0;
  509. unsigned flags = 0;
  510. unsigned opt;
  511. char *opt_i;
  512. #define flag_print (1<<0)
  513. #define flag_msg (1<<1)
  514. #define flag_sem (1<<2)
  515. #define flag_shm (1<<3)
  516. opt = getopt32(argc, argv, "i:aqsmtcplu", &opt_i);
  517. if (opt & 0x1) { // -i
  518. id = xatoi(opt_i);
  519. flags |= flag_print;
  520. }
  521. if (opt & 0x2) flags |= flag_msg | flag_sem | flag_shm; // -a
  522. if (opt & 0x4) flags |= flag_msg; // -q
  523. if (opt & 0x8) flags |= flag_sem; // -s
  524. if (opt & 0x10) flags |= flag_shm; // -m
  525. if (opt & 0x20) format = TIME; // -t
  526. if (opt & 0x40) format = CREATOR; // -c
  527. if (opt & 0x80) format = PID; // -p
  528. if (opt & 0x100) format = LIMITS; // -l
  529. if (opt & 0x200) format = STATUS; // -u
  530. if (flags & flag_print) {
  531. if (flags & flag_shm) {
  532. print_shm(id);
  533. fflush_stdout_and_exit(0);
  534. }
  535. if (flags & flag_sem) {
  536. print_sem(id);
  537. fflush_stdout_and_exit(0);
  538. }
  539. if (flags & flag_msg) {
  540. print_msg(id);
  541. fflush_stdout_and_exit(0);
  542. }
  543. bb_show_usage();
  544. }
  545. if (!(flags & (flag_shm | flag_msg | flag_sem)))
  546. flags |= flag_msg | flag_shm | flag_sem;
  547. puts("");
  548. if (flags & flag_shm) {
  549. do_shm();
  550. puts("");
  551. }
  552. if (flags & flag_sem) {
  553. do_sem();
  554. puts("");
  555. }
  556. if (flags & flag_msg) {
  557. do_msg();
  558. puts("");
  559. }
  560. fflush_stdout_and_exit(0);
  561. }