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