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