]> git.ipfire.org Git - thirdparty/util-linux.git/blob - sys-utils/ipcs.c
sys-utils: verify writing to streams was successful
[thirdparty/util-linux.git] / sys-utils / ipcs.c
1 /* Original author unknown, may be "krishna balasub@cis.ohio-state.edu" */
2 /*
3 * Modified Sat Oct 9 10:55:28 1993 for 0.99.13
4 *
5 * Patches from Mike Jagdis (jaggy@purplet.demon.co.uk) applied Wed Feb 8
6 * 12:12:21 1995 by faith@cs.unc.edu to print numeric uids if no passwd file
7 * entry.
8 *
9 * Patch from arnolds@ifns.de (Heinz-Ado Arnolds) applied Mon Jul 1 19:30:41
10 * 1996 by janl@math.uio.no to add code missing in case PID: clauses.
11 *
12 * Patched to display the key field -- hy@picksys.com 12/18/96
13 *
14 * 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@pld.ORG.PL>
15 * - added Native Language Support
16 */
17
18 #include <errno.h>
19 #include <features.h>
20 #include <getopt.h>
21 #include <grp.h>
22 #include <pwd.h>
23 #include <stddef.h>
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <sys/ipc.h>
27 #include <sys/msg.h>
28 #include <sys/sem.h>
29 #include <sys/shm.h>
30 #include <sys/types.h>
31 #include <time.h>
32 #include <unistd.h>
33
34 #include "c.h"
35 #include "nls.h"
36 #include "closestream.h"
37
38 /*
39 * SHM_DEST and SHM_LOCKED are defined in kernel headers, but inside
40 * #ifdef __KERNEL__ ... #endif
41 */
42 #ifndef SHM_DEST
43 /* shm_mode upper byte flags */
44 # define SHM_DEST 01000 /* segment will be destroyed on last detach */
45 # define SHM_LOCKED 02000 /* segment will not be swapped */
46 #endif
47
48 /* For older kernels the same holds for the defines below */
49 #ifndef MSG_STAT
50 # define MSG_STAT 11
51 # define MSG_INFO 12
52 #endif
53
54 #ifndef SHM_STAT
55 # define SHM_STAT 13
56 # define SHM_INFO 14
57 struct shm_info {
58 int used_ids;
59 ulong shm_tot; /* total allocated shm */
60 ulong shm_rss; /* total resident shm */
61 ulong shm_swp; /* total swapped shm */
62 ulong swap_attempts;
63 ulong swap_successes;
64 };
65 #endif
66
67 #ifndef SEM_STAT
68 # define SEM_STAT 18
69 # define SEM_INFO 19
70 #endif
71
72 /* Some versions of libc only define IPC_INFO when __USE_GNU is defined. */
73 #ifndef IPC_INFO
74 # define IPC_INFO 3
75 #endif
76
77 /*
78 * The last arg of semctl is a union semun, but where is it defined? X/OPEN
79 * tells us to define it ourselves, but until recently Linux include files
80 * would also define it.
81 */
82 #ifndef HAVE_UNION_SEMUN
83 /* according to X/OPEN we have to define it ourselves */
84 union semun {
85 int val;
86 struct semid_ds *buf;
87 unsigned short int *array;
88 struct seminfo *__buf;
89 };
90 #endif
91
92 /*
93 * X/OPEN (Jan 1987) does not define fields key, seq in struct ipc_perm;
94 * glibc-1.09 has no support for sysv ipc.
95 * glibc 2 uses __key, __seq
96 */
97 #if defined (__GLIBC__) && __GLIBC__ >= 2
98 # define KEY __key
99 #else
100 # define KEY key
101 #endif
102
103 #define LIMITS 1
104 #define STATUS 2
105 #define CREATOR 3
106 #define TIME 4
107 #define PID 5
108
109 void do_shm (char format);
110 void do_sem (char format);
111 void do_msg (char format);
112 void print_shm (int id);
113 void print_msg (int id);
114 void print_sem (int id);
115
116 static void __attribute__ ((__noreturn__)) usage(FILE * out)
117 {
118 fprintf(out, USAGE_HEADER);
119 fprintf(out, " %s [resource ...] [output-format]\n", program_invocation_short_name);
120 fprintf(out, " %s [resource] -i <id>\n", program_invocation_short_name);
121 fprintf(out, USAGE_OPTIONS);
122 fputs(_(" -i, --id <id> print details on resource identified by id\n"), out);
123 fprintf(out, USAGE_HELP);
124 fprintf(out, USAGE_VERSION);
125 fputs(_("\n"), out);
126 fputs(_("Resource options:\n"), out);
127 fputs(_(" -m, --shmems shared memory segments\n"), out);
128 fputs(_(" -q, --queues message queues\n"), out);
129 fputs(_(" -s, --semaphores semaphores\n"), out);
130 fputs(_(" -a, --all all (default)\n"), out);
131 fputs(_("\n"), out);
132 fputs(_("Output format:\n"), out);
133 fputs(_(" -t, --time show attach, detach and change times\n"), out);
134 fputs(_(" -p, --pid show creator and last operations PIDs\n"), out);
135 fputs(_(" -c, --creator show creator and owner\n"), out);
136 fputs(_(" -l, --limits show resource limits\n"), out);
137 fputs(_(" -u, --summary show status summary\n"), out);
138 fprintf(out, USAGE_MAN_TAIL("ipcs(1)"));
139 exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
140 }
141
142 int main (int argc, char **argv)
143 {
144 int opt, msg = 0, sem = 0, shm = 0, id=0, print=0;
145 char format = 0;
146 static const struct option longopts[] = {
147 {"id", required_argument, NULL, 'i'},
148 {"shmems", no_argument, NULL, 'm'},
149 {"queues", no_argument, NULL, 'q'},
150 {"semaphores", no_argument, NULL, 's'},
151 {"all", no_argument, NULL, 'a'},
152 {"time", no_argument, NULL, 't'},
153 {"pid", no_argument, NULL, 'p'},
154 {"creator", no_argument, NULL, 'c'},
155 {"limits", no_argument, NULL, 'l'},
156 {"summary", no_argument, NULL, 'u'},
157 {"version", no_argument, NULL, 'V'},
158 {"help", no_argument, NULL, 'h'},
159 {NULL, 0, NULL, 0}
160 };
161 char options[] = "i:mqsatpcluVh";
162
163 setlocale(LC_ALL, "");
164 bindtextdomain(PACKAGE, LOCALEDIR);
165 textdomain(PACKAGE);
166 atexit(close_stdout);
167
168 while ((opt = getopt_long(argc, argv, options, longopts, NULL)) != -1) {
169 switch (opt) {
170 case 'i':
171 id = atoi (optarg);
172 print = 1;
173 break;
174 case 'a':
175 msg = shm = sem = 1;
176 break;
177 case 'q':
178 msg = 1;
179 break;
180 case 's':
181 sem = 1;
182 break;
183 case 'm':
184 shm = 1;
185 break;
186 case 't':
187 format = TIME;
188 break;
189 case 'c':
190 format = CREATOR;
191 break;
192 case 'p':
193 format = PID;
194 break;
195 case 'l':
196 format = LIMITS;
197 break;
198 case 'u':
199 format = STATUS;
200 break;
201 case 'h':
202 usage(stdout);
203 case 'V':
204 printf(UTIL_LINUX_VERSION);
205 return EXIT_SUCCESS;
206 default:
207 usage(stderr);
208 }
209 }
210
211 if (print) {
212 if (shm)
213 print_shm (id);
214 if (sem)
215 print_sem (id);
216 if (msg)
217 print_msg (id);
218 if (!shm && !sem && !msg )
219 usage (stderr);
220 } else {
221 if ( !shm && !msg && !sem)
222 msg = sem = shm = 1;
223 printf ("\n");
224
225 if (shm) {
226 do_shm (format);
227 printf ("\n");
228 }
229 if (sem) {
230 do_sem (format);
231 printf ("\n");
232 }
233 if (msg) {
234 do_msg (format);
235 printf ("\n");
236 }
237 }
238 return EXIT_SUCCESS;
239 }
240
241 static void print_perms (int id, struct ipc_perm *ipcp)
242 {
243 struct passwd *pw;
244 struct group *gr;
245
246 printf ("%-10d %-10o", id, ipcp->mode & 0777);
247
248 if ((pw = getpwuid(ipcp->cuid)))
249 printf(" %-10s", pw->pw_name);
250 else
251 printf(" %-10u", ipcp->cuid);
252 if ((gr = getgrgid(ipcp->cgid)))
253 printf(" %-10s", gr->gr_name);
254 else
255 printf(" %-10u", ipcp->cgid);
256
257 if ((pw = getpwuid(ipcp->uid)))
258 printf(" %-10s", pw->pw_name);
259 else
260 printf(" %-10u", ipcp->uid);
261 if ((gr = getgrgid(ipcp->gid)))
262 printf(" %-10s\n", gr->gr_name);
263 else
264 printf(" %-10u\n", ipcp->gid);
265 }
266
267 void do_shm (char format)
268 {
269 int maxid, shmid, id;
270 struct shmid_ds shmseg;
271 struct shm_info shm_info;
272 struct shminfo shminfo;
273 struct ipc_perm *ipcp = &shmseg.shm_perm;
274 struct passwd *pw;
275
276 maxid = shmctl (0, SHM_INFO, (struct shmid_ds *) (void *) &shm_info);
277 if (maxid < 0) {
278 printf (_("kernel not configured for shared memory\n"));
279 return;
280 }
281
282 switch (format) {
283 case LIMITS:
284 printf (_("------ Shared Memory Limits --------\n"));
285 if ((shmctl (0, IPC_INFO, (struct shmid_ds *) (void *) &shminfo)) < 0 )
286 return;
287 /*
288 * glibc 2.1.3 and all earlier libc's have ints as fields of
289 * struct shminfo; glibc 2.1.91 has unsigned long; ach
290 */
291 printf (_("max number of segments = %lu\n"),
292 (unsigned long) shminfo.shmmni);
293 printf (_("max seg size (kbytes) = %lu\n"),
294 (unsigned long) (shminfo.shmmax >> 10));
295 printf (_("max total shared memory (kbytes) = %llu\n"),
296 getpagesize() / 1024 * (unsigned long long) shminfo.shmall);
297 printf (_("min seg size (bytes) = %lu\n"),
298 (unsigned long) shminfo.shmmin);
299 return;
300
301 case STATUS:
302 printf (_("------ Shared Memory Status --------\n"));
303 /*
304 * TRANSLATORS: This output format is mantained for backward
305 * compatibility as ipcs is used in scripts. For consistency
306 * with the rest, the translated form can follow this model:
307 *
308 * "segments allocated = %d\n"
309 * "pages allocated = %ld\n"
310 * "pages resident = %ld\n"
311 * "pages swapped = %ld\n"
312 * "swap performance = %ld attempts, %ld successes\n"
313 */
314 printf (_("segments allocated %d\n"
315 "pages allocated %ld\n"
316 "pages resident %ld\n"
317 "pages swapped %ld\n"
318 "Swap performance: %ld attempts\t %ld successes\n"),
319 shm_info.used_ids,
320 shm_info.shm_tot,
321 shm_info.shm_rss,
322 shm_info.shm_swp,
323 shm_info.swap_attempts, shm_info.swap_successes);
324 return;
325
326 case CREATOR:
327 printf (_("------ Shared Memory Segment Creators/Owners --------\n"));
328 printf ("%-10s %-10s %-10s %-10s %-10s %-10s\n",
329 _("shmid"),_("perms"),_("cuid"),_("cgid"),_("uid"),_("gid"));
330 break;
331
332 case TIME:
333 printf (_("------ Shared Memory Attach/Detach/Change Times --------\n"));
334 printf ("%-10s %-10s %-20s %-20s %-20s\n",
335 _("shmid"),_("owner"),_("attached"),_("detached"),
336 _("changed"));
337 break;
338
339 case PID:
340 printf (_("------ Shared Memory Creator/Last-op PIDs --------\n"));
341 printf ("%-10s %-10s %-10s %-10s\n",
342 _("shmid"),_("owner"),_("cpid"),_("lpid"));
343 break;
344
345 default:
346 printf (_("------ Shared Memory Segments --------\n"));
347 printf ("%-10s %-10s %-10s %-10s %-10s %-10s %-12s\n",
348 _("key"),_("shmid"),_("owner"),_("perms"),_("bytes"),
349 _("nattch"),_("status"));
350 break;
351 }
352
353 for (id = 0; id <= maxid; id++) {
354 shmid = shmctl (id, SHM_STAT, &shmseg);
355 if (shmid < 0)
356 continue;
357 if (format == CREATOR) {
358 print_perms (shmid, ipcp);
359 continue;
360 }
361 pw = getpwuid(ipcp->uid);
362 switch (format) {
363 case TIME:
364 if (pw)
365 printf ("%-10d %-10.10s", shmid, pw->pw_name);
366 else
367 printf ("%-10d %-10u", shmid, ipcp->uid);
368 /* ctime uses static buffer: use separate calls */
369 printf(" %-20.16s", shmseg.shm_atime
370 ? ctime(&shmseg.shm_atime) + 4 : _("Not set"));
371 printf(" %-20.16s", shmseg.shm_dtime
372 ? ctime(&shmseg.shm_dtime) + 4 : _("Not set"));
373 printf(" %-20.16s\n", shmseg.shm_ctime
374 ? ctime(&shmseg.shm_ctime) + 4 : _("Not set"));
375 break;
376 case PID:
377 if (pw)
378 printf ("%-10d %-10.10s", shmid, pw->pw_name);
379 else
380 printf ("%-10d %-10u", shmid, ipcp->uid);
381 printf (" %-10d %-10d\n",
382 shmseg.shm_cpid, shmseg.shm_lpid);
383 break;
384
385 default:
386 printf("0x%08x ",ipcp->KEY );
387 if (pw)
388 printf ("%-10d %-10.10s", shmid, pw->pw_name);
389 else
390 printf ("%-10d %-10u", shmid, ipcp->uid);
391 printf (" %-10o %-10lu %-10ld %-6s %-6s\n",
392 ipcp->mode & 0777,
393 /*
394 * earlier: int, Austin has size_t
395 */
396 (unsigned long) shmseg.shm_segsz,
397 /*
398 * glibc-2.1.3 and earlier has unsigned short;
399 * Austin has shmatt_t
400 */
401 (long) shmseg.shm_nattch,
402 ipcp->mode & SHM_DEST ? _("dest") : " ",
403 ipcp->mode & SHM_LOCKED ? _("locked") : " ");
404 break;
405 }
406 }
407 return;
408 }
409
410 void do_sem (char format)
411 {
412 int maxid, semid, id;
413 struct semid_ds semary;
414 struct seminfo seminfo;
415 struct ipc_perm *ipcp = &semary.sem_perm;
416 struct passwd *pw;
417 union semun arg;
418
419 arg.array = (ushort *) (void *) &seminfo;
420 maxid = semctl (0, 0, SEM_INFO, arg);
421 if (maxid < 0) {
422 printf (_("kernel not configured for semaphores\n"));
423 return;
424 }
425
426 switch (format) {
427 case LIMITS:
428 printf (_("------ Semaphore Limits --------\n"));
429 arg.array = (ushort *) (void *) &seminfo; /* damn union */
430 if ((semctl (0, 0, IPC_INFO, arg)) < 0 )
431 return;
432 printf (_("max number of arrays = %d\n"), seminfo.semmni);
433 printf (_("max semaphores per array = %d\n"), seminfo.semmsl);
434 printf (_("max semaphores system wide = %d\n"), seminfo.semmns);
435 printf (_("max ops per semop call = %d\n"), seminfo.semopm);
436 printf (_("semaphore max value = %d\n"), seminfo.semvmx);
437 return;
438
439 case STATUS:
440 printf (_("------ Semaphore Status --------\n"));
441 printf (_("used arrays = %d\n"), seminfo.semusz);
442 printf (_("allocated semaphores = %d\n"), seminfo.semaem);
443 return;
444
445 case CREATOR:
446 printf (_("------ Semaphore Arrays Creators/Owners --------\n"));
447 printf ("%-10s %-10s %-10s %-10s %-10s %-10s\n",
448 _("semid"),_("perms"),_("cuid"),_("cgid"),_("uid"),_("gid"));
449 break;
450
451 case TIME:
452 printf (_("------ Semaphore Operation/Change Times --------\n"));
453 printf ("%-8s %-10s %-26.24s %-26.24s\n",
454 _("semid"),_("owner"),_("last-op"),_("last-changed"));
455 break;
456
457 case PID:
458 break;
459
460 default:
461 printf (_("------ Semaphore Arrays --------\n"));
462 printf ("%-10s %-10s %-10s %-10s %-10s\n",
463 _("key"),_("semid"),_("owner"),_("perms"),_("nsems"));
464 break;
465 }
466
467 for (id = 0; id <= maxid; id++) {
468 arg.buf = (struct semid_ds *) &semary;
469 semid = semctl (id, 0, SEM_STAT, arg);
470 if (semid < 0)
471 continue;
472 if (format == CREATOR) {
473 print_perms (semid, ipcp);
474 continue;
475 }
476 pw = getpwuid(ipcp->uid);
477 switch (format) {
478 case TIME:
479 if (pw)
480 printf ("%-8d %-10.10s", semid, pw->pw_name);
481 else
482 printf ("%-8d %-10u", semid, ipcp->uid);
483 printf (" %-26.24s", semary.sem_otime
484 ? ctime(&semary.sem_otime) : _("Not set"));
485 printf (" %-26.24s\n", semary.sem_ctime
486 ? ctime(&semary.sem_ctime) : _("Not set"));
487 break;
488 case PID:
489 break;
490
491 default:
492 printf("0x%08x ", ipcp->KEY);
493 if (pw)
494 printf ("%-10d %-10.10s", semid, pw->pw_name);
495 else
496 printf ("%-10d %-10u", semid, ipcp->uid);
497 printf (" %-10o %-10ld\n",
498 ipcp->mode & 0777,
499 /*
500 * glibc-2.1.3 and earlier has unsigned
501 * short. glibc-2.1.91 has variation between
502 * unsigned short and unsigned long. Austin
503 * prescribes unsigned short.
504 */
505 (long) semary.sem_nsems);
506 break;
507 }
508 }
509 }
510
511 void do_msg (char format)
512 {
513 int maxid, msqid, id;
514 struct msqid_ds msgque;
515 struct msginfo msginfo;
516 struct ipc_perm *ipcp = &msgque.msg_perm;
517 struct passwd *pw;
518
519 maxid = msgctl (0, MSG_INFO, (struct msqid_ds *) (void *) &msginfo);
520 if (maxid < 0) {
521 printf (_("kernel not configured for message queues\n"));
522 return;
523 }
524
525 switch (format) {
526 case LIMITS:
527 if ((msgctl (0, IPC_INFO, (struct msqid_ds *) (void *) &msginfo)) < 0 )
528 return;
529 printf (_("------ Messages Limits --------\n"));
530 printf (_("max queues system wide = %d\n"), msginfo.msgmni);
531 printf (_("max size of message (bytes) = %d\n"), msginfo.msgmax);
532 printf (_("default max size of queue (bytes) = %d\n"), msginfo.msgmnb);
533 return;
534
535 case STATUS:
536 printf (_("------ Messages Status --------\n"));
537 printf (_("allocated queues = %d\n"), msginfo.msgpool);
538 printf (_("used headers = %d\n"), msginfo.msgmap);
539 printf (_("used space = %d bytes\n"), msginfo.msgtql);
540 return;
541
542 case CREATOR:
543 printf (_("------ Message Queues Creators/Owners --------\n"));
544 printf ("%-10s %-10s %-10s %-10s %-10s %-10s\n",
545 _("msqid"),_("perms"),_("cuid"),_("cgid"),_("uid"),_("gid"));
546 break;
547
548 case TIME:
549 printf (_("------ Message Queues Send/Recv/Change Times --------\n"));
550 printf ("%-8s %-10s %-20s %-20s %-20s\n",
551 _("msqid"),_("owner"),_("send"),_("recv"),_("change"));
552 break;
553
554 case PID:
555 printf (_("------ Message Queues PIDs --------\n"));
556 printf ("%-10s %-10s %-10s %-10s\n",
557 _("msqid"),_("owner"),_("lspid"),_("lrpid"));
558 break;
559
560 default:
561 printf (_("------ Message Queues --------\n"));
562 printf ("%-10s %-10s %-10s %-10s %-12s %-12s\n",
563 _("key"), _("msqid"), _("owner"), _("perms"),
564 _("used-bytes"), _("messages"));
565 break;
566 }
567
568 for (id = 0; id <= maxid; id++) {
569 msqid = msgctl (id, MSG_STAT, &msgque);
570 if (msqid < 0)
571 continue;
572 if (format == CREATOR) {
573 print_perms (msqid, ipcp);
574 continue;
575 }
576 pw = getpwuid(ipcp->uid);
577 switch (format) {
578 case TIME:
579 if (pw)
580 printf ("%-8d %-10.10s", msqid, pw->pw_name);
581 else
582 printf ("%-8d %-10u", msqid, ipcp->uid);
583 printf (" %-20.16s", msgque.msg_stime
584 ? ctime(&msgque.msg_stime) + 4 : _("Not set"));
585 printf (" %-20.16s", msgque.msg_rtime
586 ? ctime(&msgque.msg_rtime) + 4 : _("Not set"));
587 printf (" %-20.16s\n", msgque.msg_ctime
588 ? ctime(&msgque.msg_ctime) + 4 : _("Not set"));
589 break;
590 case PID:
591 if (pw)
592 printf ("%-8d %-10.10s", msqid, pw->pw_name);
593 else
594 printf ("%-8d %-10u", msqid, ipcp->uid);
595 printf (" %5d %5d\n",
596 msgque.msg_lspid, msgque.msg_lrpid);
597 break;
598
599 default:
600 printf( "0x%08x ",ipcp->KEY );
601 if (pw)
602 printf ("%-10d %-10.10s", msqid, pw->pw_name);
603 else
604 printf ("%-10d %-10u", msqid, ipcp->uid);
605 printf (" %-10o %-12ld %-12ld\n",
606 ipcp->mode & 0777,
607 /*
608 * glibc-2.1.3 and earlier has unsigned
609 * short. glibc-2.1.91 has variation between
610 * unsigned short, unsigned long. Austin has
611 * msgqnum_t
612 */
613 (long) msgque.msg_cbytes,
614 (long) msgque.msg_qnum);
615 break;
616 }
617 }
618 return;
619 }
620
621 void print_shm (int shmid)
622 {
623 struct shmid_ds shmds;
624 struct ipc_perm *ipcp = &shmds.shm_perm;
625
626 if (shmctl (shmid, IPC_STAT, &shmds) == -1)
627 err(EXIT_FAILURE, _("shmctl failed"));
628
629 printf (_("\nShared memory Segment shmid=%d\n"), shmid);
630 printf (_("uid=%u\tgid=%u\tcuid=%u\tcgid=%u\n"),
631 ipcp->uid, ipcp->gid, ipcp->cuid, ipcp->cgid);
632 printf (_("mode=%#o\taccess_perms=%#o\n"),
633 ipcp->mode, ipcp->mode & 0777);
634 printf (_("bytes=%lu\tlpid=%d\tcpid=%d\tnattch=%ld\n"),
635 (unsigned long) shmds.shm_segsz, shmds.shm_lpid, shmds.shm_cpid,
636 (long) shmds.shm_nattch);
637 printf (_("att_time=%-26.24s\n"),
638 shmds.shm_atime ? ctime (&shmds.shm_atime) : _("Not set"));
639 printf (_("det_time=%-26.24s\n"),
640 shmds.shm_dtime ? ctime (&shmds.shm_dtime) : _("Not set"));
641 printf (_("change_time=%-26.24s\n"), ctime (&shmds.shm_ctime));
642 printf ("\n");
643 return;
644 }
645
646
647 void print_msg (int msqid)
648 {
649 struct msqid_ds buf;
650 struct ipc_perm *ipcp = &buf.msg_perm;
651
652 if (msgctl (msqid, IPC_STAT, &buf) == -1)
653 err(EXIT_FAILURE, _("msgctl failed"));
654
655 printf (_("\nMessage Queue msqid=%d\n"), msqid);
656 printf (_("uid=%u\tgid=%u\tcuid=%u\tcgid=%u\tmode=%#o\n"),
657 ipcp->uid, ipcp->gid, ipcp->cuid, ipcp->cgid, ipcp->mode);
658 printf (_("cbytes=%ld\tqbytes=%ld\tqnum=%ld\tlspid=%d\tlrpid=%d\n"),
659 /*
660 * glibc-2.1.3 and earlier has unsigned short. glibc-2.1.91
661 * has variation between unsigned short, unsigned long.
662 * Austin has msgqnum_t (for msg_qbytes)
663 */
664 (long) buf.msg_cbytes, (long) buf.msg_qbytes,
665 (long) buf.msg_qnum, buf.msg_lspid, buf.msg_lrpid);
666 printf (_("send_time=%-26.24s\n"),
667 buf.msg_stime ? ctime (&buf.msg_stime) : _("Not set"));
668 printf (_("rcv_time=%-26.24s\n"),
669 buf.msg_rtime ? ctime (&buf.msg_rtime) : _("Not set"));
670 printf (_("change_time=%-26.24s\n"),
671 buf.msg_ctime ? ctime (&buf.msg_ctime) : _("Not set"));
672 printf ("\n");
673 return;
674 }
675
676 void print_sem (int semid)
677 {
678 struct semid_ds semds;
679 struct ipc_perm *ipcp = &semds.sem_perm;
680 union semun arg;
681 size_t i;
682
683 arg.buf = &semds;
684 if (semctl (semid, 0, IPC_STAT, arg) < 0)
685 err(EXIT_FAILURE, _("semctl failed"));
686
687 printf (_("\nSemaphore Array semid=%d\n"), semid);
688 printf (_("uid=%u\t gid=%u\t cuid=%u\t cgid=%u\n"),
689 ipcp->uid, ipcp->gid, ipcp->cuid, ipcp->cgid);
690 printf (_("mode=%#o, access_perms=%#o\n"),
691 ipcp->mode, ipcp->mode & 0777);
692 printf (_("nsems = %ld\n"), (long) semds.sem_nsems);
693 printf (_("otime = %-26.24s\n"),
694 semds.sem_otime ? ctime (&semds.sem_otime) : _("Not set"));
695 printf (_("ctime = %-26.24s\n"), ctime (&semds.sem_ctime));
696
697 printf ("%-10s %-10s %-10s %-10s %-10s\n",
698 _("semnum"),_("value"),_("ncount"),_("zcount"),_("pid"));
699 arg.val = 0;
700 for (i=0; i< semds.sem_nsems; i++) {
701 int val, ncnt, zcnt, pid;
702 val = semctl (semid, i, GETVAL, arg);
703 ncnt = semctl (semid, i, GETNCNT, arg);
704 zcnt = semctl (semid, i, GETZCNT, arg);
705 pid = semctl (semid, i, GETPID, arg);
706 if (val < 0 || ncnt < 0 || zcnt < 0 || pid < 0)
707 err(EXIT_FAILURE, _("semctl failed"));
708
709 printf ("%-10zd %-10d %-10d %-10d %-10d\n",
710 i, val, ncnt, zcnt, pid);
711 }
712 printf ("\n");
713 return;
714 }