ipcs.c 17 KB

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