diff options
author | Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> | 2006-04-03 11:25:48 +0000 |
---|---|---|
committer | Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> | 2006-04-03 11:25:48 +0000 |
commit | a38330c36640d729704cb0c50c86d2165b1405c2 (patch) | |
tree | 2d58ffb7429c5c5ab1d2373060236cfbbedb77a1 | |
parent | 6153629097cdbf463ed50181df5113438662a425 (diff) | |
download | busybox-w32-a38330c36640d729704cb0c50c86d2165b1405c2.tar.gz busybox-w32-a38330c36640d729704cb0c50c86d2165b1405c2.tar.bz2 busybox-w32-a38330c36640d729704cb0c50c86d2165b1405c2.zip |
- do away with useless fwd-decls, redundant bb_printf calls, silence warning
about comparing signed and unsigned and make stuff static.
text data bss dec hex filename
6944 0 0 6944 1b20 util-linux/ipcs.o.oorig
6509 0 0 6509 196d util-linux/ipcs.o
TODO: bb_getopt_ulflags, and further simplifications
-rw-r--r-- | util-linux/ipcs.c | 424 |
1 files changed, 204 insertions, 220 deletions
diff --git a/util-linux/ipcs.c b/util-linux/ipcs.c index f1463a8e3..6efe3d2b6 100644 --- a/util-linux/ipcs.c +++ b/util-linux/ipcs.c | |||
@@ -4,38 +4,7 @@ | |||
4 | * 01 Sept 2004 - Rodney Radford <rradford@mindspring.com> | 4 | * 01 Sept 2004 - Rodney Radford <rradford@mindspring.com> |
5 | * Adapted for busybox from util-linux-2.12a. | 5 | * Adapted for busybox from util-linux-2.12a. |
6 | * | 6 | * |
7 | * This program is free software; you can redistribute it and/or modify | 7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
8 | * it under the terms of the GNU General Public License as published by | ||
9 | * the Free Software Foundation; either version 2 of the License, or | ||
10 | * (at your option) any later version. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
15 | * General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
20 | * | ||
21 | * --- Pre-busybox history from util-linux-2.12a ------------------------ | ||
22 | * | ||
23 | * 1999-02-22 Arkadiusz Mi˙kiewicz <misiek@pld.ORG.PL> | ||
24 | * - added Native Language Support | ||
25 | * | ||
26 | * Patched to display the key field -- hy@picksys.com 12/18/96 | ||
27 | * | ||
28 | * Patch from arnolds@ifns.de (Heinz-Ado Arnolds) applied Mon Jul 1 | ||
29 | * 19:30:41 1996 by janl@math.uio.no to add code missing in case PID: | ||
30 | * clauses. | ||
31 | * | ||
32 | * Patches from Mike Jagdis (jaggy@purplet.demon.co.uk) applied | ||
33 | * Wed Feb 8 12:12:21 1995 by faith@cs.unc.edu to print numeric uids | ||
34 | * if no passwd file entry. | ||
35 | * | ||
36 | * Modified Sat Oct 9 10:55:28 1993 for 0.99.13 | ||
37 | * Original author unknown, may be "krishna balasub@cis.ohio-state.edu" | ||
38 | * | ||
39 | */ | 8 | */ |
40 | 9 | ||
41 | #include <stdio.h> | 10 | #include <stdio.h> |
@@ -128,97 +97,8 @@ union semun { | |||
128 | #define TIME 4 | 97 | #define TIME 4 |
129 | #define PID 5 | 98 | #define PID 5 |
130 | 99 | ||
131 | static void do_shm (char format); | ||
132 | static void do_sem (char format); | ||
133 | static void do_msg (char format); | ||
134 | static void print_shm (int id); | ||
135 | static void print_msg (int id); | ||
136 | static void print_sem (int id); | ||
137 | |||
138 | int ipcs_main (int argc, char **argv) { | ||
139 | int opt, msg = 0, sem = 0, shm = 0, id=0, print=0; | ||
140 | char format = 0; | ||
141 | char options[] = "atclupsmqi:ih?"; | ||
142 | |||
143 | while ((opt = getopt (argc, argv, options)) != -1) { | ||
144 | switch (opt) { | ||
145 | case 'i': | ||
146 | id = atoi (optarg); | ||
147 | print = 1; | ||
148 | break; | ||
149 | case 'a': | ||
150 | msg = shm = sem = 1; | ||
151 | break; | ||
152 | case 'q': | ||
153 | msg = 1; | ||
154 | break; | ||
155 | case 's': | ||
156 | sem = 1; | ||
157 | break; | ||
158 | case 'm': | ||
159 | shm = 1; | ||
160 | break; | ||
161 | case 't': | ||
162 | format = TIME; | ||
163 | break; | ||
164 | case 'c': | ||
165 | format = CREATOR; | ||
166 | break; | ||
167 | case 'p': | ||
168 | format = PID; | ||
169 | break; | ||
170 | case 'l': | ||
171 | format = LIMITS; | ||
172 | break; | ||
173 | case 'u': | ||
174 | format = STATUS; | ||
175 | break; | ||
176 | case 'h': | ||
177 | case '?': | ||
178 | bb_show_usage(); | ||
179 | bb_fflush_stdout_and_exit (0); | ||
180 | } | ||
181 | } | ||
182 | |||
183 | if (print) { | ||
184 | if (shm) { | ||
185 | print_shm (id); | ||
186 | bb_fflush_stdout_and_exit (0); | ||
187 | } | ||
188 | if (sem) { | ||
189 | print_sem (id); | ||
190 | bb_fflush_stdout_and_exit (0); | ||
191 | } | ||
192 | if (msg) { | ||
193 | print_msg (id); | ||
194 | bb_fflush_stdout_and_exit (0); | ||
195 | } | ||
196 | bb_show_usage(); | ||
197 | bb_fflush_stdout_and_exit (0); | ||
198 | } | ||
199 | |||
200 | if ( !shm && !msg && !sem) | ||
201 | msg = sem = shm = 1; | ||
202 | bb_printf ("\n"); | ||
203 | 100 | ||
204 | if (shm) { | 101 | static void print_perms (int id, struct ipc_perm *ipcp) { |
205 | do_shm (format); | ||
206 | bb_printf ("\n"); | ||
207 | } | ||
208 | if (sem) { | ||
209 | do_sem (format); | ||
210 | bb_printf ("\n"); | ||
211 | } | ||
212 | if (msg) { | ||
213 | do_msg (format); | ||
214 | bb_printf ("\n"); | ||
215 | } | ||
216 | return 0; | ||
217 | } | ||
218 | |||
219 | |||
220 | static void | ||
221 | print_perms (int id, struct ipc_perm *ipcp) { | ||
222 | struct passwd *pw; | 102 | struct passwd *pw; |
223 | struct group *gr; | 103 | struct group *gr; |
224 | 104 | ||
@@ -244,7 +124,7 @@ print_perms (int id, struct ipc_perm *ipcp) { | |||
244 | } | 124 | } |
245 | 125 | ||
246 | 126 | ||
247 | void do_shm (char format) | 127 | static void do_shm (char format) |
248 | { | 128 | { |
249 | int maxid, shmid, id; | 129 | int maxid, shmid, id; |
250 | struct shmid_ds shmseg; | 130 | struct shmid_ds shmseg; |
@@ -266,47 +146,51 @@ void do_shm (char format) | |||
266 | return; | 146 | return; |
267 | /* glibc 2.1.3 and all earlier libc's have ints as fields | 147 | /* glibc 2.1.3 and all earlier libc's have ints as fields |
268 | of struct shminfo; glibc 2.1.91 has unsigned long; ach */ | 148 | of struct shminfo; glibc 2.1.91 has unsigned long; ach */ |
269 | bb_printf ("max number of segments = %lu\n", | 149 | bb_printf ("max number of segments = %lu\n" |
270 | (unsigned long) shminfo.shmmni); | 150 | "max seg size (kbytes) = %lu\n" |
271 | bb_printf ("max seg size (kbytes) = %lu\n", | 151 | "max total shared memory (pages) = %lu\n" |
272 | (unsigned long) (shminfo.shmmax >> 10)); | 152 | "min seg size (bytes) = %lu\n", |
273 | bb_printf ("max total shared memory (pages) = %lu\n", | 153 | (unsigned long) shminfo.shmmni, |
274 | (unsigned long) shminfo.shmall); | 154 | (unsigned long) (shminfo.shmmax >> 10), |
275 | bb_printf ("min seg size (bytes) = %lu\n", | 155 | (unsigned long) shminfo.shmall, |
276 | (unsigned long) shminfo.shmmin); | 156 | (unsigned long) shminfo.shmmin); |
277 | return; | 157 | return; |
278 | 158 | ||
279 | case STATUS: | 159 | case STATUS: |
280 | bb_printf ("------ Shared Memory Status --------\n"); | 160 | bb_printf ("------ Shared Memory Status --------\n" |
281 | bb_printf ("segments allocated %d\n", shm_info.used_ids); | 161 | "segments allocated %d\n" |
282 | bb_printf ("pages allocated %ld\n", shm_info.shm_tot); | 162 | "pages allocated %ld\n" |
283 | bb_printf ("pages resident %ld\n", shm_info.shm_rss); | 163 | "pages resident %ld\n" |
284 | bb_printf ("pages swapped %ld\n", shm_info.shm_swp); | 164 | "pages swapped %ld\n" |
285 | bb_printf ("Swap performance: %ld attempts\t %ld successes\n", | 165 | "Swap performance: %ld attempts\t %ld successes\n", |
166 | shm_info.used_ids, | ||
167 | shm_info.shm_tot, | ||
168 | shm_info.shm_rss, | ||
169 | shm_info.shm_swp, | ||
286 | shm_info.swap_attempts, shm_info.swap_successes); | 170 | shm_info.swap_attempts, shm_info.swap_successes); |
287 | return; | 171 | return; |
288 | 172 | ||
289 | case CREATOR: | 173 | case CREATOR: |
290 | bb_printf ("------ Shared Memory Segment Creators/Owners --------\n"); | 174 | bb_printf ("------ Shared Memory Segment Creators/Owners --------\n" |
291 | bb_printf ("%-10s %-10s %-10s %-10s %-10s %-10s\n", | 175 | "%-10s %-10s %-10s %-10s %-10s %-10s\n", |
292 | "shmid","perms","cuid","cgid","uid","gid"); | 176 | "shmid","perms","cuid","cgid","uid","gid"); |
293 | break; | 177 | break; |
294 | 178 | ||
295 | case TIME: | 179 | case TIME: |
296 | bb_printf ("------ Shared Memory Attach/Detach/Change Times --------\n"); | 180 | bb_printf ("------ Shared Memory Attach/Detach/Change Times --------\n" |
297 | bb_printf ("%-10s %-10s %-20s %-20s %-20s\n", | 181 | "%-10s %-10s %-20s %-20s %-20s\n", |
298 | "shmid","owner","attached","detached","changed"); | 182 | "shmid","owner","attached","detached","changed"); |
299 | break; | 183 | break; |
300 | 184 | ||
301 | case PID: | 185 | case PID: |
302 | bb_printf ("------ Shared Memory Creator/Last-op --------\n"); | 186 | bb_printf ("------ Shared Memory Creator/Last-op --------\n" |
303 | bb_printf ("%-10s %-10s %-10s %-10s\n", | 187 | "%-10s %-10s %-10s %-10s\n", |
304 | "shmid","owner","cpid","lpid"); | 188 | "shmid","owner","cpid","lpid"); |
305 | break; | 189 | break; |
306 | 190 | ||
307 | default: | 191 | default: |
308 | bb_printf ("------ Shared Memory Segments --------\n"); | 192 | bb_printf ("------ Shared Memory Segments --------\n" |
309 | bb_printf ("%-10s %-10s %-10s %-10s %-10s %-10s %-12s\n", | 193 | "%-10s %-10s %-10s %-10s %-10s %-10s %-12s\n", |
310 | "key","shmid","owner","perms","bytes","nattch","status"); | 194 | "key","shmid","owner","perms","bytes","nattch","status"); |
311 | break; | 195 | break; |
312 | } | 196 | } |
@@ -369,7 +253,7 @@ void do_shm (char format) | |||
369 | } | 253 | } |
370 | 254 | ||
371 | 255 | ||
372 | void do_sem (char format) | 256 | static void do_sem (char format) |
373 | { | 257 | { |
374 | int maxid, semid, id; | 258 | int maxid, semid, id; |
375 | struct semid_ds semary; | 259 | struct semid_ds semary; |
@@ -391,28 +275,35 @@ void do_sem (char format) | |||
391 | arg.array = (ushort *) (void *) &seminfo; /* damn union */ | 275 | arg.array = (ushort *) (void *) &seminfo; /* damn union */ |
392 | if ((semctl (0, 0, IPC_INFO, arg)) < 0 ) | 276 | if ((semctl (0, 0, IPC_INFO, arg)) < 0 ) |
393 | return; | 277 | return; |
394 | bb_printf ("max number of arrays = %d\n", seminfo.semmni); | 278 | bb_printf ("max number of arrays = %d\n" |
395 | bb_printf ("max semaphores per array = %d\n", seminfo.semmsl); | 279 | "max semaphores per array = %d\n" |
396 | bb_printf ("max semaphores system wide = %d\n", seminfo.semmns); | 280 | "max semaphores system wide = %d\n" |
397 | bb_printf ("max ops per semop call = %d\n", seminfo.semopm); | 281 | "max ops per semop call = %d\n" |
398 | bb_printf ("semaphore max value = %d\n", seminfo.semvmx); | 282 | "semaphore max value = %d\n", |
283 | seminfo.semmni, | ||
284 | seminfo.semmsl, | ||
285 | seminfo.semmns, | ||
286 | seminfo.semopm, | ||
287 | seminfo.semvmx); | ||
399 | return; | 288 | return; |
400 | 289 | ||
401 | case STATUS: | 290 | case STATUS: |
402 | bb_printf ("------ Semaphore Status --------\n"); | 291 | bb_printf ("------ Semaphore Status --------\n" |
403 | bb_printf ("used arrays = %d\n", seminfo.semusz); | 292 | "used arrays = %d\n" |
404 | bb_printf ("allocated semaphores = %d\n", seminfo.semaem); | 293 | "allocated semaphores = %d\n", |
294 | seminfo.semusz, | ||
295 | seminfo.semaem); | ||
405 | return; | 296 | return; |
406 | 297 | ||
407 | case CREATOR: | 298 | case CREATOR: |
408 | bb_printf ("------ Semaphore Arrays Creators/Owners --------\n"); | 299 | bb_printf ("------ Semaphore Arrays Creators/Owners --------\n" |
409 | bb_printf ("%-10s %-10s %-10s %-10s %-10s %-10s\n", | 300 | "%-10s %-10s %-10s %-10s %-10s %-10s\n", |
410 | "semid","perms","cuid","cgid","uid","gid"); | 301 | "semid","perms","cuid","cgid","uid","gid"); |
411 | break; | 302 | break; |
412 | 303 | ||
413 | case TIME: | 304 | case TIME: |
414 | bb_printf ("------ Shared Memory Operation/Change Times --------\n"); | 305 | bb_printf ("------ Shared Memory Operation/Change Times --------\n" |
415 | bb_printf ("%-8s %-10s %-26.24s %-26.24s\n", | 306 | "%-8s %-10s %-26.24s %-26.24s\n", |
416 | "shmid","owner","last-op","last-changed"); | 307 | "shmid","owner","last-op","last-changed"); |
417 | break; | 308 | break; |
418 | 309 | ||
@@ -420,8 +311,8 @@ void do_sem (char format) | |||
420 | break; | 311 | break; |
421 | 312 | ||
422 | default: | 313 | default: |
423 | bb_printf ("------ Semaphore Arrays --------\n"); | 314 | bb_printf ("------ Semaphore Arrays --------\n" |
424 | bb_printf ("%-10s %-10s %-10s %-10s %-10s\n", | 315 | "%-10s %-10s %-10s %-10s %-10s\n", |
425 | "key","semid","owner","perms","nsems"); | 316 | "key","semid","owner","perms","nsems"); |
426 | break; | 317 | break; |
427 | } | 318 | } |
@@ -471,7 +362,7 @@ void do_sem (char format) | |||
471 | } | 362 | } |
472 | 363 | ||
473 | 364 | ||
474 | void do_msg (char format) | 365 | static void do_msg (char format) |
475 | { | 366 | { |
476 | int maxid, msqid, id; | 367 | int maxid, msqid, id; |
477 | struct msqid_ds msgque; | 368 | struct msqid_ds msgque; |
@@ -489,41 +380,47 @@ void do_msg (char format) | |||
489 | case LIMITS: | 380 | case LIMITS: |
490 | if ((msgctl (0, IPC_INFO, (struct msqid_ds *) (void *) &msginfo)) < 0 ) | 381 | if ((msgctl (0, IPC_INFO, (struct msqid_ds *) (void *) &msginfo)) < 0 ) |
491 | return; | 382 | return; |
492 | bb_printf ("------ Messages: Limits --------\n"); | 383 | bb_printf ("------ Messages: Limits --------\n" |
493 | bb_printf ("max queues system wide = %d\n", msginfo.msgmni); | 384 | "max queues system wide = %d\n" |
494 | bb_printf ("max size of message (bytes) = %d\n", msginfo.msgmax); | 385 | "max size of message (bytes) = %d\n" |
495 | bb_printf ("default max size of queue (bytes) = %d\n", msginfo.msgmnb); | 386 | "default max size of queue (bytes) = %d\n", |
387 | msginfo.msgmni, | ||
388 | msginfo.msgmax, | ||
389 | msginfo.msgmnb); | ||
496 | return; | 390 | return; |
497 | 391 | ||
498 | case STATUS: | 392 | case STATUS: |
499 | bb_printf ("------ Messages: Status --------\n"); | 393 | bb_printf ("------ Messages: Status --------\n" |
500 | bb_printf ("allocated queues = %d\n", msginfo.msgpool); | 394 | "allocated queues = %d\n" |
501 | bb_printf ("used headers = %d\n", msginfo.msgmap); | 395 | "used headers = %d\n" |
502 | bb_printf ("used space = %d bytes\n", msginfo.msgtql); | 396 | "used space = %d bytes\n", |
397 | msginfo.msgpool, | ||
398 | msginfo.msgmap, | ||
399 | msginfo.msgtql); | ||
503 | return; | 400 | return; |
504 | 401 | ||
505 | case CREATOR: | 402 | case CREATOR: |
506 | bb_printf ("------ Message Queues: Creators/Owners --------\n"); | 403 | bb_printf ("------ Message Queues: Creators/Owners --------\n" |
507 | bb_printf ("%-10s %-10s %-10s %-10s %-10s %-10s\n", | 404 | "%-10s %-10s %-10s %-10s %-10s %-10s\n", |
508 | "msqid","perms","cuid","cgid","uid","gid"); | 405 | "msqid","perms","cuid","cgid","uid","gid"); |
509 | break; | 406 | break; |
510 | 407 | ||
511 | case TIME: | 408 | case TIME: |
512 | bb_printf ("------ Message Queues Send/Recv/Change Times --------\n"); | 409 | bb_printf ("------ Message Queues Send/Recv/Change Times --------\n" |
513 | bb_printf ("%-8s %-10s %-20s %-20s %-20s\n", | 410 | "%-8s %-10s %-20s %-20s %-20s\n", |
514 | "msqid","owner","send","recv","change"); | 411 | "msqid","owner","send","recv","change"); |
515 | break; | 412 | break; |
516 | 413 | ||
517 | case PID: | 414 | case PID: |
518 | bb_printf ("------ Message Queues PIDs --------\n"); | 415 | bb_printf ("------ Message Queues PIDs --------\n" |
519 | bb_printf ("%-10s %-10s %-10s %-10s\n", | 416 | "%-10s %-10s %-10s %-10s\n", |
520 | "msqid","owner","lspid","lrpid"); | 417 | "msqid","owner","lspid","lrpid"); |
521 | break; | 418 | break; |
522 | 419 | ||
523 | default: | 420 | default: |
524 | bb_printf ("------ Message Queues --------\n"); | 421 | bb_printf ("------ Message Queues --------\n" |
525 | bb_printf ("%-10s %-10s %-10s %-10s %-12s %-12s\n", | 422 | "%-10s %-10s %-10s %-10s %-12s %-12s\n", |
526 | "key", "msqid", "owner", "perms","used-bytes", "messages"); | 423 | "key","msqid","owner","perms","used-bytes","messages"); |
527 | break; | 424 | break; |
528 | } | 425 | } |
529 | 426 | ||
@@ -581,7 +478,7 @@ void do_msg (char format) | |||
581 | } | 478 | } |
582 | 479 | ||
583 | 480 | ||
584 | void print_shm (int shmid) | 481 | static void print_shm (int shmid) |
585 | { | 482 | { |
586 | struct shmid_ds shmds; | 483 | struct shmid_ds shmds; |
587 | struct ipc_perm *ipcp = &shmds.shm_perm; | 484 | struct ipc_perm *ipcp = &shmds.shm_perm; |
@@ -591,25 +488,27 @@ void print_shm (int shmid) | |||
591 | return; | 488 | return; |
592 | } | 489 | } |
593 | 490 | ||
594 | bb_printf ("\nShared memory Segment shmid=%d\n", shmid); | 491 | bb_printf ("\nShared memory Segment shmid=%d\n" |
595 | bb_printf ("uid=%d\tgid=%d\tcuid=%d\tcgid=%d\n", | 492 | "uid=%d\tgid=%d\tcuid=%d\tcgid=%d\n" |
596 | ipcp->uid, ipcp->gid, ipcp->cuid, ipcp->cgid); | 493 | "mode=%#o\taccess_perms=%#o\n" |
597 | bb_printf ("mode=%#o\taccess_perms=%#o\n", | 494 | "bytes=%ld\tlpid=%d\tcpid=%d\tnattch=%ld\n" |
598 | ipcp->mode, ipcp->mode & 0777); | 495 | "att_time=%-26.24s\n" |
599 | bb_printf ("bytes=%ld\tlpid=%d\tcpid=%d\tnattch=%ld\n", | 496 | "det_time=%-26.24s\n" |
497 | "change_time=%-26.24s\n" | ||
498 | "\n", | ||
499 | shmid, | ||
500 | ipcp->uid, ipcp->gid, ipcp->cuid, ipcp->cgid, | ||
501 | ipcp->mode, ipcp->mode & 0777, | ||
600 | (long) shmds.shm_segsz, shmds.shm_lpid, shmds.shm_cpid, | 502 | (long) shmds.shm_segsz, shmds.shm_lpid, shmds.shm_cpid, |
601 | (long) shmds.shm_nattch); | 503 | (long) shmds.shm_nattch, |
602 | bb_printf ("att_time=%-26.24s\n", | 504 | shmds.shm_atime ? ctime (&shmds.shm_atime) : "Not set", |
603 | shmds.shm_atime ? ctime (&shmds.shm_atime) : "Not set"); | 505 | shmds.shm_dtime ? ctime (&shmds.shm_dtime) : "Not set", |
604 | bb_printf ("det_time=%-26.24s\n", | 506 | ctime (&shmds.shm_ctime)); |
605 | shmds.shm_dtime ? ctime (&shmds.shm_dtime) : "Not set"); | ||
606 | bb_printf ("change_time=%-26.24s\n", ctime (&shmds.shm_ctime)); | ||
607 | bb_printf ("\n"); | ||
608 | return; | 507 | return; |
609 | } | 508 | } |
610 | 509 | ||
611 | 510 | ||
612 | void print_msg (int msqid) | 511 | static void print_msg (int msqid) |
613 | { | 512 | { |
614 | struct msqid_ds buf; | 513 | struct msqid_ds buf; |
615 | struct ipc_perm *ipcp = &buf.msg_perm; | 514 | struct ipc_perm *ipcp = &buf.msg_perm; |
@@ -619,10 +518,15 @@ void print_msg (int msqid) | |||
619 | return; | 518 | return; |
620 | } | 519 | } |
621 | 520 | ||
622 | bb_printf ("\nMessage Queue msqid=%d\n", msqid); | 521 | bb_printf ("\nMessage Queue msqid=%d\n" |
623 | bb_printf ("uid=%d\tgid=%d\tcuid=%d\tcgid=%d\tmode=%#o\n", | 522 | "uid=%d\tgid=%d\tcuid=%d\tcgid=%d\tmode=%#o\n" |
624 | ipcp->uid, ipcp->gid, ipcp->cuid, ipcp->cgid, ipcp->mode); | 523 | "cbytes=%ld\tqbytes=%ld\tqnum=%ld\tlspid=%d\tlrpid=%d\n" |
625 | bb_printf ("cbytes=%ld\tqbytes=%ld\tqnum=%ld\tlspid=%d\tlrpid=%d\n", | 524 | "send_time=%-26.24s\n" |
525 | "rcv_time=%-26.24s\n" | ||
526 | "change_time=%-26.24s\n" | ||
527 | "\n", | ||
528 | msqid, | ||
529 | ipcp->uid, ipcp->gid, ipcp->cuid, ipcp->cgid, ipcp->mode, | ||
626 | /* | 530 | /* |
627 | * glibc-2.1.3 and earlier has unsigned short; | 531 | * glibc-2.1.3 and earlier has unsigned short; |
628 | * glibc-2.1.91 has variation between | 532 | * glibc-2.1.91 has variation between |
@@ -630,23 +534,19 @@ void print_msg (int msqid) | |||
630 | * Austin has msgqnum_t (for msg_qbytes) | 534 | * Austin has msgqnum_t (for msg_qbytes) |
631 | */ | 535 | */ |
632 | (long) buf.msg_cbytes, (long) buf.msg_qbytes, | 536 | (long) buf.msg_cbytes, (long) buf.msg_qbytes, |
633 | (long) buf.msg_qnum, buf.msg_lspid, buf.msg_lrpid); | 537 | (long) buf.msg_qnum, buf.msg_lspid, buf.msg_lrpid, |
634 | bb_printf ("send_time=%-26.24s\n", | 538 | buf.msg_stime ? ctime (&buf.msg_stime) : "Not set", |
635 | buf.msg_stime ? ctime (&buf.msg_stime) : "Not set"); | 539 | buf.msg_rtime ? ctime (&buf.msg_rtime) : "Not set", |
636 | bb_printf ("rcv_time=%-26.24s\n", | ||
637 | buf.msg_rtime ? ctime (&buf.msg_rtime) : "Not set"); | ||
638 | bb_printf ("change_time=%-26.24s\n", | ||
639 | buf.msg_ctime ? ctime (&buf.msg_ctime) : "Not set"); | 540 | buf.msg_ctime ? ctime (&buf.msg_ctime) : "Not set"); |
640 | bb_printf ("\n"); | ||
641 | return; | 541 | return; |
642 | } | 542 | } |
643 | 543 | ||
644 | void print_sem (int semid) | 544 | static void print_sem (int semid) |
645 | { | 545 | { |
646 | struct semid_ds semds; | 546 | struct semid_ds semds; |
647 | struct ipc_perm *ipcp = &semds.sem_perm; | 547 | struct ipc_perm *ipcp = &semds.sem_perm; |
648 | union semun arg; | 548 | union semun arg; |
649 | int i; | 549 | unsigned int i; |
650 | 550 | ||
651 | arg.buf = &semds; | 551 | arg.buf = &semds; |
652 | if (semctl (semid, 0, IPC_STAT, arg) < 0) { | 552 | if (semctl (semid, 0, IPC_STAT, arg) < 0) { |
@@ -654,21 +554,23 @@ void print_sem (int semid) | |||
654 | return; | 554 | return; |
655 | } | 555 | } |
656 | 556 | ||
657 | bb_printf ("\nSemaphore Array semid=%d\n", semid); | 557 | bb_printf ("\nSemaphore Array semid=%d\n" |
658 | bb_printf ("uid=%d\t gid=%d\t cuid=%d\t cgid=%d\n", | 558 | "uid=%d\t gid=%d\t cuid=%d\t cgid=%d\n" |
659 | ipcp->uid, ipcp->gid, ipcp->cuid, ipcp->cgid); | 559 | "mode=%#o, access_perms=%#o\n" |
660 | bb_printf ("mode=%#o, access_perms=%#o\n", | 560 | "nsems = %ld\n" |
661 | ipcp->mode, ipcp->mode & 0777); | 561 | "otime = %-26.24s\n" |
662 | bb_printf ("nsems = %ld\n", (long) semds.sem_nsems); | 562 | "ctime = %-26.24s\n" |
663 | bb_printf ("otime = %-26.24s\n", | 563 | "%-10s %-10s %-10s %-10s %-10s\n", |
664 | semds.sem_otime ? ctime (&semds.sem_otime) : "Not set"); | 564 | semid, |
665 | bb_printf ("ctime = %-26.24s\n", ctime (&semds.sem_ctime)); | 565 | ipcp->uid, ipcp->gid, ipcp->cuid, ipcp->cgid, |
666 | 566 | ipcp->mode, ipcp->mode & 0777, | |
667 | bb_printf ("%-10s %-10s %-10s %-10s %-10s\n", | 567 | (long) semds.sem_nsems, |
568 | semds.sem_otime ? ctime (&semds.sem_otime) : "Not set", | ||
569 | ctime (&semds.sem_ctime), | ||
668 | "semnum","value","ncount","zcount","pid"); | 570 | "semnum","value","ncount","zcount","pid"); |
669 | 571 | ||
670 | arg.val = 0; | 572 | arg.val = 0; |
671 | for (i=0; i< semds.sem_nsems; i++) { | 573 | for (i=0; i < semds.sem_nsems; i++) { |
672 | int val, ncnt, zcnt, pid; | 574 | int val, ncnt, zcnt, pid; |
673 | val = semctl (semid, i, GETVAL, arg); | 575 | val = semctl (semid, i, GETVAL, arg); |
674 | ncnt = semctl (semid, i, GETNCNT, arg); | 576 | ncnt = semctl (semid, i, GETNCNT, arg); |
@@ -684,3 +586,85 @@ void print_sem (int semid) | |||
684 | bb_printf ("\n"); | 586 | bb_printf ("\n"); |
685 | return; | 587 | return; |
686 | } | 588 | } |
589 | |||
590 | int ipcs_main (int argc, char **argv) { | ||
591 | int opt, msg = 0, sem = 0, shm = 0, id=0, print=0; | ||
592 | char format = 0; | ||
593 | char options[] = "atclupsmqi:ih?"; | ||
594 | |||
595 | while ((opt = getopt (argc, argv, options)) != -1) { | ||
596 | switch (opt) { | ||
597 | case 'i': | ||
598 | id = atoi (optarg); | ||
599 | print = 1; | ||
600 | break; | ||
601 | case 'a': | ||
602 | msg = shm = sem = 1; | ||
603 | break; | ||
604 | case 'q': | ||
605 | msg = 1; | ||
606 | break; | ||
607 | case 's': | ||
608 | sem = 1; | ||
609 | break; | ||
610 | case 'm': | ||
611 | shm = 1; | ||
612 | break; | ||
613 | case 't': | ||
614 | format = TIME; | ||
615 | break; | ||
616 | case 'c': | ||
617 | format = CREATOR; | ||
618 | break; | ||
619 | case 'p': | ||
620 | format = PID; | ||
621 | break; | ||
622 | case 'l': | ||
623 | format = LIMITS; | ||
624 | break; | ||
625 | case 'u': | ||
626 | format = STATUS; | ||
627 | break; | ||
628 | case 'h': | ||
629 | case '?': | ||
630 | bb_show_usage(); | ||
631 | bb_fflush_stdout_and_exit (0); | ||
632 | } | ||
633 | } | ||
634 | |||
635 | if (print) { | ||
636 | if (shm) { | ||
637 | print_shm (id); | ||
638 | bb_fflush_stdout_and_exit (0); | ||
639 | } | ||
640 | if (sem) { | ||
641 | print_sem (id); | ||
642 | bb_fflush_stdout_and_exit (0); | ||
643 | } | ||
644 | if (msg) { | ||
645 | print_msg (id); | ||
646 | bb_fflush_stdout_and_exit (0); | ||
647 | } | ||
648 | bb_show_usage(); | ||
649 | bb_fflush_stdout_and_exit (0); | ||
650 | } | ||
651 | |||
652 | if ( !shm && !msg && !sem) | ||
653 | msg = sem = shm = 1; | ||
654 | bb_printf ("\n"); | ||
655 | |||
656 | if (shm) { | ||
657 | do_shm (format); | ||
658 | bb_printf ("\n"); | ||
659 | } | ||
660 | if (sem) { | ||
661 | do_sem (format); | ||
662 | bb_printf ("\n"); | ||
663 | } | ||
664 | if (msg) { | ||
665 | do_msg (format); | ||
666 | bb_printf ("\n"); | ||
667 | } | ||
668 | return 0; | ||
669 | } | ||
670 | |||