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