]> git.ipfire.org Git - thirdparty/util-linux.git/blob - sys-utils/ipcs.c
misc: cosmetics, remove argument from usage(FILE*)
[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 <getopt.h>
20
21 #include "c.h"
22 #include "nls.h"
23 #include "closestream.h"
24
25 #include "ipcutils.h"
26
27 enum output_formats {
28 NOTSPECIFIED,
29 LIMITS,
30 STATUS,
31 CREATOR,
32 TIME,
33 PID
34 };
35 enum {
36 OPT_HUMAN = CHAR_MAX + 1
37 };
38
39 static void do_shm (char format, int unit);
40 static void print_shm (int id, int unit);
41 static void do_sem (char format);
42 static void print_sem (int id);
43 static void do_msg (char format, int unit);
44 static void print_msg (int id, int unit);
45
46 /* we read time as int64_t from /proc, so cast... */
47 #define xctime(_x) ctime((time_t *) (_x))
48
49 static void __attribute__((__noreturn__)) usage(void)
50 {
51 FILE *out = stdout;
52 fputs(USAGE_HEADER, out);
53 fprintf(out, _(" %1$s [resource-option...] [output-option]\n"
54 " %1$s -m|-q|-s -i <id>\n"), program_invocation_short_name);
55
56 fputs(USAGE_SEPARATOR, out);
57 fputs(_("Show information on IPC facilities.\n"), out);
58
59 fputs(USAGE_OPTIONS, out);
60 fputs(_(" -i, --id <id> print details on resource identified by <id>\n"), out);
61 fputs(USAGE_HELP, out);
62 fputs(USAGE_VERSION, out);
63
64 fputs(USAGE_SEPARATOR, out);
65 fputs(_("Resource options:\n"), out);
66 fputs(_(" -m, --shmems shared memory segments\n"), out);
67 fputs(_(" -q, --queues message queues\n"), out);
68 fputs(_(" -s, --semaphores semaphores\n"), out);
69 fputs(_(" -a, --all all (default)\n"), out);
70
71 fputs(USAGE_SEPARATOR, out);
72 fputs(_("Output options:\n"), out);
73 fputs(_(" -t, --time show attach, detach and change times\n"), out);
74 fputs(_(" -p, --pid show PIDs of creator and last operator\n"), out);
75 fputs(_(" -c, --creator show creator and owner\n"), out);
76 fputs(_(" -l, --limits show resource limits\n"), out);
77 fputs(_(" -u, --summary show status summary\n"), out);
78 fputs(_(" --human show sizes in human-readable format\n"), out);
79 fputs(_(" -b, --bytes show sizes in bytes\n"), out);
80 fprintf(out, USAGE_MAN_TAIL("ipcs(1)"));
81
82 exit(EXIT_SUCCESS);
83 }
84
85 int main (int argc, char **argv)
86 {
87 int opt, msg = 0, shm = 0, sem = 0, id = 0, specific = 0;
88 char format = NOTSPECIFIED;
89 int unit = IPC_UNIT_DEFAULT;
90 static const struct option longopts[] = {
91 {"id", required_argument, NULL, 'i'},
92 {"queues", no_argument, NULL, 'q'},
93 {"shmems", no_argument, NULL, 'm'},
94 {"semaphores", no_argument, NULL, 's'},
95 {"all", no_argument, NULL, 'a'},
96 {"time", no_argument, NULL, 't'},
97 {"pid", no_argument, NULL, 'p'},
98 {"creator", no_argument, NULL, 'c'},
99 {"limits", no_argument, NULL, 'l'},
100 {"summary", no_argument, NULL, 'u'},
101 {"human", no_argument, NULL, OPT_HUMAN},
102 {"bytes", no_argument, NULL, 'b'},
103 {"version", no_argument, NULL, 'V'},
104 {"help", no_argument, NULL, 'h'},
105 {NULL, 0, NULL, 0}
106 };
107 char options[] = "i:qmsatpclubVh";
108
109 setlocale(LC_ALL, "");
110 bindtextdomain(PACKAGE, LOCALEDIR);
111 textdomain(PACKAGE);
112 atexit(close_stdout);
113
114 while ((opt = getopt_long(argc, argv, options, longopts, NULL)) != -1) {
115 switch (opt) {
116 case 'i':
117 id = atoi (optarg);
118 specific = 1;
119 break;
120 case 'a':
121 msg = shm = sem = 1;
122 break;
123 case 'q':
124 msg = 1;
125 break;
126 case 'm':
127 shm = 1;
128 break;
129 case 's':
130 sem = 1;
131 break;
132 case 't':
133 format = TIME;
134 break;
135 case 'c':
136 format = CREATOR;
137 break;
138 case 'p':
139 format = PID;
140 break;
141 case 'l':
142 format = LIMITS;
143 break;
144 case 'u':
145 format = STATUS;
146 break;
147 case OPT_HUMAN:
148 unit = IPC_UNIT_HUMAN;
149 break;
150 case 'b':
151 unit = IPC_UNIT_BYTES;
152 break;
153 case 'h':
154 usage();
155 case 'V':
156 printf(UTIL_LINUX_VERSION);
157 return EXIT_SUCCESS;
158 default:
159 errtryhelp(EXIT_FAILURE);
160 }
161 }
162
163 if (specific && (msg + shm + sem != 1))
164 errx (EXIT_FAILURE,
165 _("when using an ID, a single resource must be specified"));
166 if (specific) {
167 if (msg)
168 print_msg (id, unit);
169 if (shm)
170 print_shm (id, unit);
171 if (sem)
172 print_sem (id);
173 } else {
174 if (!msg && !shm && !sem)
175 msg = shm = sem = 1;
176 printf ("\n");
177 if (msg) {
178 do_msg (format, unit);
179 printf ("\n");
180 }
181 if (shm) {
182 do_shm (format, unit);
183 printf ("\n");
184 }
185 if (sem) {
186 do_sem (format);
187 printf ("\n");
188 }
189 }
190 return EXIT_SUCCESS;
191 }
192
193 static void do_shm (char format, int unit)
194 {
195 struct passwd *pw;
196 struct shm_data *shmds, *shmdsp;
197
198 switch (format) {
199 case LIMITS:
200 {
201 struct ipc_limits lim;
202 uint64_t tmp, pgsz = getpagesize();
203
204 if (ipc_shm_get_limits(&lim)) {
205 printf (_("unable to fetch shared memory limits\n"));
206 return;
207 }
208 printf (_("------ Shared Memory Limits --------\n"));
209 printf (_("max number of segments = %ju\n"), lim.shmmni);
210 ipc_print_size(unit == IPC_UNIT_DEFAULT ? IPC_UNIT_KB : unit,
211 _("max seg size"), lim.shmmax, "\n", 0);
212
213 tmp = (uint64_t) lim.shmall * pgsz;
214 /* overflow handling, at least we don't print ridiculous small values */
215 if (lim.shmall != 0 && tmp / lim.shmall != pgsz) {
216 tmp = UINT64_MAX - (UINT64_MAX % pgsz);
217 }
218 ipc_print_size(unit == IPC_UNIT_DEFAULT ? IPC_UNIT_KB : unit,
219 _("max total shared memory"), tmp, "\n", 0);
220 ipc_print_size(unit == IPC_UNIT_DEFAULT ? IPC_UNIT_BYTES : unit,
221 _("min seg size"), lim.shmmin, "\n", 0);
222 return;
223 }
224 case STATUS:
225 {
226 int maxid;
227 struct shmid_ds shmbuf;
228 struct shm_info *shm_info;
229
230 maxid = shmctl (0, SHM_INFO, &shmbuf);
231 shm_info = (struct shm_info *) &shmbuf;
232 if (maxid < 0) {
233 printf (_("kernel not configured for shared memory\n"));
234 return;
235 }
236
237 printf (_("------ Shared Memory Status --------\n"));
238 /*
239 * TRANSLATORS: This output format is maintained for backward
240 * compatibility as ipcs is used in scripts. For consistency
241 * with the rest, the translated form can follow this model:
242 *
243 * "segments allocated = %d\n"
244 * "pages allocated = %ld\n"
245 * "pages resident = %ld\n"
246 * "pages swapped = %ld\n"
247 * "swap performance = %ld attempts, %ld successes\n"
248 */
249 printf (_("segments allocated %d\n"
250 "pages allocated %ld\n"
251 "pages resident %ld\n"
252 "pages swapped %ld\n"
253 "Swap performance: %ld attempts\t %ld successes\n"),
254 shm_info->used_ids,
255 shm_info->shm_tot,
256 shm_info->shm_rss,
257 shm_info->shm_swp,
258 shm_info->swap_attempts, shm_info->swap_successes);
259 return;
260 }
261
262 /*
263 * Headers only
264 */
265 case CREATOR:
266 printf (_("------ Shared Memory Segment Creators/Owners --------\n"));
267 printf ("%-10s %-10s %-10s %-10s %-10s %-10s\n",
268 _("shmid"),_("perms"),_("cuid"),_("cgid"),_("uid"),_("gid"));
269 break;
270
271 case TIME:
272 printf (_("------ Shared Memory Attach/Detach/Change Times --------\n"));
273 printf ("%-10s %-10s %-20s %-20s %-20s\n",
274 _("shmid"),_("owner"),_("attached"),_("detached"),
275 _("changed"));
276 break;
277
278 case PID:
279 printf (_("------ Shared Memory Creator/Last-op PIDs --------\n"));
280 printf ("%-10s %-10s %-10s %-10s\n",
281 _("shmid"),_("owner"),_("cpid"),_("lpid"));
282 break;
283
284 default:
285 printf (_("------ Shared Memory Segments --------\n"));
286 printf ("%-10s %-10s %-10s %-10s %-10s %-10s %-12s\n",
287 _("key"),_("shmid"),_("owner"),_("perms"),
288 unit == IPC_UNIT_HUMAN ? _("size") : _("bytes"),
289 _("nattch"),_("status"));
290 break;
291 }
292
293 /*
294 * Print data
295 */
296 if (ipc_shm_get_info(-1, &shmds) < 1)
297 return;
298
299 for (shmdsp = shmds; shmdsp->next != NULL; shmdsp = shmdsp->next) {
300 if (format == CREATOR) {
301 ipc_print_perms(stdout, &shmdsp->shm_perm);
302 continue;
303 }
304 pw = getpwuid(shmdsp->shm_perm.uid);
305 switch (format) {
306 case TIME:
307 if (pw)
308 printf ("%-10d %-10.10s", shmdsp->shm_perm.id, pw->pw_name);
309 else
310 printf ("%-10d %-10u", shmdsp->shm_perm.id, shmdsp->shm_perm.uid);
311 /* ctime uses static buffer: use separate calls */
312 printf(" %-20.16s", shmdsp->shm_atim
313 ? xctime(&shmdsp->shm_atim) + 4 : _("Not set"));
314 printf(" %-20.16s", shmdsp->shm_dtim
315 ? xctime(&shmdsp->shm_dtim) + 4 : _("Not set"));
316 printf(" %-20.16s\n", shmdsp->shm_ctim
317 ? xctime(&shmdsp->shm_ctim) + 4 : _("Not set"));
318 break;
319 case PID:
320 if (pw)
321 printf ("%-10d %-10.10s", shmdsp->shm_perm.id, pw->pw_name);
322 else
323 printf ("%-10d %-10u", shmdsp->shm_perm.id, shmdsp->shm_perm.uid);
324 printf (" %-10u %-10u\n",
325 shmdsp->shm_cprid, shmdsp->shm_lprid);
326 break;
327
328 default:
329 printf("0x%08x ", shmdsp->shm_perm.key);
330 if (pw)
331 printf ("%-10d %-10.10s", shmdsp->shm_perm.id, pw->pw_name);
332 else
333 printf ("%-10d %-10u", shmdsp->shm_perm.id, shmdsp->shm_perm.uid);
334 printf (" %-10o ", shmdsp->shm_perm.mode & 0777);
335
336 if (unit == IPC_UNIT_HUMAN)
337 ipc_print_size(unit, NULL, shmdsp->shm_segsz, " ", 6);
338 else
339 ipc_print_size(unit, NULL, shmdsp->shm_segsz, NULL, -10);
340
341 printf (" %-10ju %-6s %-6s\n",
342 shmdsp->shm_nattch,
343 shmdsp->shm_perm.mode & SHM_DEST ? _("dest") : " ",
344 shmdsp->shm_perm.mode & SHM_LOCKED ? _("locked") : " ");
345 break;
346 }
347 }
348
349 ipc_shm_free_info(shmds);
350 return;
351 }
352
353 static void do_sem (char format)
354 {
355 struct passwd *pw;
356 struct sem_data *semds, *semdsp;
357
358 switch (format) {
359 case LIMITS:
360 {
361 struct ipc_limits lim;
362
363 if (ipc_sem_get_limits(&lim)) {
364 printf (_("unable to fetch semaphore limits\n"));
365 return;
366 }
367 printf (_("------ Semaphore Limits --------\n"));
368 printf (_("max number of arrays = %d\n"), lim.semmni);
369 printf (_("max semaphores per array = %d\n"), lim.semmsl);
370 printf (_("max semaphores system wide = %d\n"), lim.semmns);
371 printf (_("max ops per semop call = %d\n"), lim.semopm);
372 printf (_("semaphore max value = %u\n"), lim.semvmx);
373 return;
374 }
375 case STATUS:
376 {
377 struct seminfo seminfo;
378 union semun arg;
379 arg.array = (ushort *) (void *) &seminfo;
380 if (semctl (0, 0, SEM_INFO, arg) < 0) {
381 printf (_("kernel not configured for semaphores\n"));
382 return;
383 }
384 printf (_("------ Semaphore Status --------\n"));
385 printf (_("used arrays = %d\n"), seminfo.semusz);
386 printf (_("allocated semaphores = %d\n"), seminfo.semaem);
387 return;
388 }
389
390 case CREATOR:
391 printf (_("------ Semaphore Arrays Creators/Owners --------\n"));
392 printf ("%-10s %-10s %-10s %-10s %-10s %-10s\n",
393 _("semid"),_("perms"),_("cuid"),_("cgid"),_("uid"),_("gid"));
394 break;
395
396 case TIME:
397 printf (_("------ Semaphore Operation/Change Times --------\n"));
398 printf ("%-8s %-10s %-26.24s %-26.24s\n",
399 _("semid"),_("owner"),_("last-op"),_("last-changed"));
400 break;
401
402 case PID:
403 break;
404
405 default:
406 printf (_("------ Semaphore Arrays --------\n"));
407 printf ("%-10s %-10s %-10s %-10s %-10s\n",
408 _("key"),_("semid"),_("owner"),_("perms"),_("nsems"));
409 break;
410 }
411
412 /*
413 * Print data
414 */
415 if (ipc_sem_get_info(-1, &semds) < 1)
416 return;
417
418 for (semdsp = semds; semdsp->next != NULL; semdsp = semdsp->next) {
419 if (format == CREATOR) {
420 ipc_print_perms(stdout, &semdsp->sem_perm);
421 continue;
422 }
423 pw = getpwuid(semdsp->sem_perm.uid);
424 switch (format) {
425 case TIME:
426 if (pw)
427 printf ("%-8d %-10.10s", semdsp->sem_perm.id, pw->pw_name);
428 else
429 printf ("%-8d %-10u", semdsp->sem_perm.id, semdsp->sem_perm.uid);
430 printf (" %-26.24s", semdsp->sem_otime
431 ? xctime(&semdsp->sem_otime) : _("Not set"));
432 printf (" %-26.24s\n", semdsp->sem_ctime
433 ? xctime( &semdsp->sem_ctime) : _("Not set"));
434 break;
435 case PID:
436 break;
437
438 default:
439 printf("0x%08x ", semdsp->sem_perm.key);
440 if (pw)
441 printf ("%-10d %-10.10s", semdsp->sem_perm.id, pw->pw_name);
442 else
443 printf ("%-10d %-10u", semdsp->sem_perm.id, semdsp->sem_perm.uid);
444 printf (" %-10o %-10ju\n",
445 semdsp->sem_perm.mode & 0777,
446 semdsp->sem_nsems);
447 break;
448 }
449 }
450
451 ipc_sem_free_info(semds);
452 return;
453 }
454
455 static void do_msg (char format, int unit)
456 {
457 struct passwd *pw;
458 struct msg_data *msgds, *msgdsp;
459
460 switch (format) {
461 case LIMITS:
462 {
463 struct ipc_limits lim;
464
465 if (ipc_msg_get_limits(&lim)) {
466 printf (_("unable to fetch message limits\n"));
467 return;
468 }
469 printf (_("------ Messages Limits --------\n"));
470 printf (_("max queues system wide = %d\n"), lim.msgmni);
471 ipc_print_size(unit == IPC_UNIT_DEFAULT ? IPC_UNIT_BYTES : unit,
472 _("max size of message"), lim.msgmax, "\n", 0);
473 ipc_print_size(unit == IPC_UNIT_DEFAULT ? IPC_UNIT_BYTES : unit,
474 _("default max size of queue"), lim.msgmnb, "\n", 0);
475 return;
476 }
477 case STATUS:
478 {
479 struct msginfo msginfo;
480 if (msgctl (0, MSG_INFO, (struct msqid_ds *) (void *) &msginfo) < 0) {
481 printf (_("kernel not configured for message queues\n"));
482 return;
483 }
484 printf (_("------ Messages Status --------\n"));
485 #ifndef __FreeBSD_kernel__
486 printf (_("allocated queues = %d\n"), msginfo.msgpool);
487 printf (_("used headers = %d\n"), msginfo.msgmap);
488 #endif
489 ipc_print_size(unit, _("used space"), msginfo.msgtql,
490 unit == IPC_UNIT_DEFAULT ? _(" bytes\n") : "\n", 0);
491 return;
492 }
493 case CREATOR:
494 printf (_("------ Message Queues Creators/Owners --------\n"));
495 printf ("%-10s %-10s %-10s %-10s %-10s %-10s\n",
496 _("msqid"),_("perms"),_("cuid"),_("cgid"),_("uid"),_("gid"));
497 break;
498
499 case TIME:
500 printf (_("------ Message Queues Send/Recv/Change Times --------\n"));
501 printf ("%-8s %-10s %-20s %-20s %-20s\n",
502 _("msqid"),_("owner"),_("send"),_("recv"),_("change"));
503 break;
504
505 case PID:
506 printf (_("------ Message Queues PIDs --------\n"));
507 printf ("%-10s %-10s %-10s %-10s\n",
508 _("msqid"),_("owner"),_("lspid"),_("lrpid"));
509 break;
510
511 default:
512 printf (_("------ Message Queues --------\n"));
513 printf ("%-10s %-10s %-10s %-10s %-12s %-12s\n",
514 _("key"), _("msqid"), _("owner"), _("perms"),
515 unit == IPC_UNIT_HUMAN ? _("size") : _("used-bytes"),
516 _("messages"));
517 break;
518 }
519
520 /*
521 * Print data
522 */
523 if (ipc_msg_get_info(-1, &msgds) < 1)
524 return;
525
526 for (msgdsp = msgds; msgdsp->next != NULL; msgdsp = msgdsp->next) {
527 if (format == CREATOR) {
528 ipc_print_perms(stdout, &msgdsp->msg_perm);
529 continue;
530 }
531 pw = getpwuid(msgdsp->msg_perm.uid);
532 switch (format) {
533 case TIME:
534 if (pw)
535 printf ("%-8d %-10.10s", msgdsp->msg_perm.id, pw->pw_name);
536 else
537 printf ("%-8d %-10u", msgdsp->msg_perm.id, msgdsp->msg_perm.uid);
538 printf (" %-20.16s", msgdsp->q_stime
539 ? xctime(&msgdsp->q_stime) + 4 : _("Not set"));
540 printf (" %-20.16s", msgdsp->q_rtime
541 ? xctime(&msgdsp->q_rtime) + 4 : _("Not set"));
542 printf (" %-20.16s\n", msgdsp->q_ctime
543 ? xctime(&msgdsp->q_ctime) + 4 : _("Not set"));
544 break;
545 case PID:
546 if (pw)
547 printf ("%-8d %-10.10s", msgdsp->msg_perm.id, pw->pw_name);
548 else
549 printf ("%-8d %-10u", msgdsp->msg_perm.id, msgdsp->msg_perm.uid);
550 printf (" %5d %5d\n",
551 msgdsp->q_lspid, msgdsp->q_lrpid);
552 break;
553
554 default:
555 printf( "0x%08x ",msgdsp->msg_perm.key );
556 if (pw)
557 printf ("%-10d %-10.10s", msgdsp->msg_perm.id, pw->pw_name);
558 else
559 printf ("%-10d %-10u", msgdsp->msg_perm.id, msgdsp->msg_perm.uid);
560 printf (" %-10o ", msgdsp->msg_perm.mode & 0777);
561
562 if (unit == IPC_UNIT_HUMAN)
563 ipc_print_size(unit, NULL, msgdsp->q_cbytes, " ", 6);
564 else
565 ipc_print_size(unit, NULL, msgdsp->q_cbytes, NULL, -12);
566
567 printf (" %-12ju\n", msgdsp->q_qnum);
568 break;
569 }
570 }
571
572 ipc_msg_free_info(msgds);
573 return;
574 }
575
576 static void print_shm(int shmid, int unit)
577 {
578 struct shm_data *shmdata;
579
580 if (ipc_shm_get_info(shmid, &shmdata) < 1) {
581 warnx(_("id %d not found"), shmid);
582 return;
583 }
584
585 printf(_("\nShared memory Segment shmid=%d\n"), shmid);
586 printf(_("uid=%u\tgid=%u\tcuid=%u\tcgid=%u\n"),
587 shmdata->shm_perm.uid, shmdata->shm_perm.gid,
588 shmdata->shm_perm.cuid, shmdata->shm_perm.cgid);
589 printf(_("mode=%#o\taccess_perms=%#o\n"), shmdata->shm_perm.mode,
590 shmdata->shm_perm.mode & 0777);
591 ipc_print_size(unit, unit == IPC_UNIT_HUMAN ? _("size=") : _("bytes="),
592 shmdata->shm_segsz, "\t", 0);
593 printf(_("lpid=%u\tcpid=%u\tnattch=%jd\n"),
594 shmdata->shm_lprid, shmdata->shm_cprid,
595 shmdata->shm_nattch);
596 printf(_("att_time=%-26.24s\n"),
597 shmdata->shm_atim ? xctime(&(shmdata->shm_atim)) : _("Not set"));
598 printf(_("det_time=%-26.24s\n"),
599 shmdata->shm_dtim ? xctime(&shmdata->shm_dtim) : _("Not set"));
600 printf(_("change_time=%-26.24s\n"), xctime(&shmdata->shm_ctim));
601 printf("\n");
602
603 ipc_shm_free_info(shmdata);
604 }
605
606 static void print_msg(int msgid, int unit)
607 {
608 struct msg_data *msgdata;
609
610 if (ipc_msg_get_info(msgid, &msgdata) < 1) {
611 warnx(_("id %d not found"), msgid);
612 return;
613 }
614
615 printf(_("\nMessage Queue msqid=%d\n"), msgid);
616 printf(_("uid=%u\tgid=%u\tcuid=%u\tcgid=%u\tmode=%#o\n"),
617 msgdata->msg_perm.uid, msgdata->msg_perm.gid,
618 msgdata->msg_perm.cuid, msgdata->msg_perm.cgid,
619 msgdata->msg_perm.mode);
620 ipc_print_size(unit, unit == IPC_UNIT_HUMAN ? _("csize=") : _("cbytes="),
621 msgdata->q_cbytes, "\t", 0);
622 ipc_print_size(unit, unit == IPC_UNIT_HUMAN ? _("qsize=") : _("qbytes="),
623 msgdata->q_qbytes, "\t", 0);
624 printf("qnum=%jd\tlspid=%d\tlrpid=%d\n",
625 msgdata->q_qnum,
626 msgdata->q_lspid, msgdata->q_lrpid);
627 printf(_("send_time=%-26.24s\n"),
628 msgdata->q_stime ? xctime(&msgdata->q_stime) : _("Not set"));
629 printf(_("rcv_time=%-26.24s\n"),
630 msgdata->q_rtime ? xctime(&msgdata->q_rtime) : _("Not set"));
631 printf(_("change_time=%-26.24s\n"),
632 msgdata->q_ctime ? xctime(&msgdata->q_ctime) : _("Not set"));
633 printf("\n");
634
635 ipc_msg_free_info(msgdata);
636 }
637
638 static void print_sem(int semid)
639 {
640 struct sem_data *semdata;
641 size_t i;
642
643 if (ipc_sem_get_info(semid, &semdata) < 1) {
644 warnx(_("id %d not found"), semid);
645 return;
646 }
647
648 printf(_("\nSemaphore Array semid=%d\n"), semid);
649 printf(_("uid=%u\t gid=%u\t cuid=%u\t cgid=%u\n"),
650 semdata->sem_perm.uid, semdata->sem_perm.gid,
651 semdata->sem_perm.cuid, semdata->sem_perm.cgid);
652 printf(_("mode=%#o, access_perms=%#o\n"),
653 semdata->sem_perm.mode, semdata->sem_perm.mode & 0777);
654 printf(_("nsems = %ju\n"), semdata->sem_nsems);
655 printf(_("otime = %-26.24s\n"),
656 semdata->sem_otime ? xctime(&semdata->sem_otime) : _("Not set"));
657 printf(_("ctime = %-26.24s\n"), xctime(&semdata->sem_ctime));
658
659 printf("%-10s %-10s %-10s %-10s %-10s\n",
660 _("semnum"), _("value"), _("ncount"), _("zcount"), _("pid"));
661
662 for (i = 0; i < semdata->sem_nsems; i++) {
663 struct sem_elem *e = &semdata->elements[i];
664 printf("%-10zu %-10d %-10d %-10d %-10d\n",
665 i, e->semval, e->ncount, e->zcount, e->pid);
666 }
667 printf("\n");
668 ipc_sem_free_info(semdata);
669 }