]> git.ipfire.org Git - thirdparty/util-linux.git/blame - sys-utils/ipcs.c
misc: cosmetics, remove argument from usage(FILE*)
[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 19#include <getopt.h>
eb63b9b8 20
eb76ca98 21#include "c.h"
3ab18da8 22#include "nls.h"
efb8854f 23#include "closestream.h"
bf7b8d77 24
e5995acd 25#include "ipcutils.h"
7eda085c 26
7e3c5f1c
SK
27enum output_formats {
28 NOTSPECIFIED,
29 LIMITS,
30 STATUS,
31 CREATOR,
32 TIME,
33 PID
34};
56692a67
SK
35enum {
36 OPT_HUMAN = CHAR_MAX + 1
37};
6dbe3af9 38
56692a67
SK
39static void do_shm (char format, int unit);
40static void print_shm (int id, int unit);
1e2418a2 41static void do_sem (char format);
b5504a3d 42static void print_sem (int id);
56692a67
SK
43static void do_msg (char format, int unit);
44static void print_msg (int id, int unit);
6dbe3af9 45
278e7203
KZ
46/* we read time as int64_t from /proc, so cast... */
47#define xctime(_x) ctime((time_t *) (_x))
48
86be6a32 49static void __attribute__((__noreturn__)) usage(void)
09f53dab 50{
86be6a32 51 FILE *out = stdout;
7009af0e 52 fputs(USAGE_HEADER, out);
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
7009af0e 59 fputs(USAGE_OPTIONS, out);
0de963ce 60 fputs(_(" -i, --id <id> print details on resource identified by <id>\n"), out);
7009af0e
BS
61 fputs(USAGE_HELP, out);
62 fputs(USAGE_VERSION, out);
63
64 fputs(USAGE_SEPARATOR, out);
09f53dab
SK
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);
7009af0e
BS
70
71 fputs(USAGE_SEPARATOR, out);
afd86656 72 fputs(_("Output options:\n"), out);
09f53dab 73 fputs(_(" -t, --time show attach, detach and change times\n"), out);
0de963ce 74 fputs(_(" -p, --pid show PIDs of creator and last operator\n"), out);
09f53dab
SK
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);
0de963ce 78 fputs(_(" --human show sizes in human-readable format\n"), out);
19b7b517 79 fputs(_(" -b, --bytes show sizes in bytes\n"), out);
6f162034 80 fprintf(out, USAGE_MAN_TAIL("ipcs(1)"));
7009af0e 81
86be6a32 82 exit(EXIT_SUCCESS);
6dbe3af9
KZ
83}
84
1e13900a
SK
85int main (int argc, char **argv)
86{
fa03fa05 87 int opt, msg = 0, shm = 0, sem = 0, id = 0, specific = 0;
7e3c5f1c 88 char format = NOTSPECIFIED;
56692a67 89 int unit = IPC_UNIT_DEFAULT;
09f53dab
SK
90 static const struct option longopts[] = {
91 {"id", required_argument, NULL, 'i'},
09f53dab 92 {"queues", no_argument, NULL, 'q'},
fa03fa05 93 {"shmems", no_argument, NULL, 'm'},
09f53dab
SK
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'},
56692a67 101 {"human", no_argument, NULL, OPT_HUMAN},
19b7b517 102 {"bytes", no_argument, NULL, 'b'},
09f53dab
SK
103 {"version", no_argument, NULL, 'V'},
104 {"help", no_argument, NULL, 'h'},
105 {NULL, 0, NULL, 0}
106 };
fa03fa05 107 char options[] = "i:qmsatpclubVh";
6dbe3af9 108
7eda085c
KZ
109 setlocale(LC_ALL, "");
110 bindtextdomain(PACKAGE, LOCALEDIR);
111 textdomain(PACKAGE);
efb8854f 112 atexit(close_stdout);
7eda085c 113
09f53dab 114 while ((opt = getopt_long(argc, argv, options, longopts, NULL)) != -1) {
6dbe3af9
KZ
115 switch (opt) {
116 case 'i':
117 id = atoi (optarg);
fa03fa05 118 specific = 1;
6dbe3af9
KZ
119 break;
120 case 'a':
121 msg = shm = sem = 1;
122 break;
123 case 'q':
124 msg = 1;
125 break;
6dbe3af9
KZ
126 case 'm':
127 shm = 1;
128 break;
fa03fa05
BS
129 case 's':
130 sem = 1;
131 break;
6dbe3af9
KZ
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;
56692a67
SK
147 case OPT_HUMAN:
148 unit = IPC_UNIT_HUMAN;
149 break;
19b7b517
SK
150 case 'b':
151 unit = IPC_UNIT_BYTES;
152 break;
bf7b8d77 153 case 'h':
86be6a32 154 usage();
09f53dab
SK
155 case 'V':
156 printf(UTIL_LINUX_VERSION);
157 return EXIT_SUCCESS;
158 default:
677ec86c 159 errtryhelp(EXIT_FAILURE);
6dbe3af9
KZ
160 }
161 }
162
fa03fa05
BS
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);
1e13900a 169 if (shm)
56692a67 170 print_shm (id, unit);
4dad230f 171 if (sem)
6dbe3af9 172 print_sem (id);
bf7b8d77 173 } else {
fa03fa05
BS
174 if (!msg && !shm && !sem)
175 msg = shm = sem = 1;
bf7b8d77 176 printf ("\n");
fa03fa05
BS
177 if (msg) {
178 do_msg (format, unit);
179 printf ("\n");
180 }
bf7b8d77 181 if (shm) {
56692a67 182 do_shm (format, unit);
bf7b8d77
KZ
183 printf ("\n");
184 }
185 if (sem) {
186 do_sem (format);
187 printf ("\n");
6dbe3af9 188 }
6dbe3af9 189 }
bf7b8d77 190 return EXIT_SUCCESS;
6dbe3af9
KZ
191}
192
56692a67 193static void do_shm (char format, int unit)
6dbe3af9 194{
6dbe3af9 195 struct passwd *pw;
058e8154 196 struct shm_data *shmds, *shmdsp;
6dbe3af9 197
6dbe3af9
KZ
198 switch (format) {
199 case LIMITS:
61e14b4a
KZ
200 {
201 struct ipc_limits lim;
61e29ab4 202 uint64_t tmp, pgsz = getpagesize();
61e14b4a 203
fcae4063
RM
204 if (ipc_shm_get_limits(&lim)) {
205 printf (_("unable to fetch shared memory limits\n"));
6dbe3af9 206 return;
fcae4063
RM
207 }
208 printf (_("------ Shared Memory Limits --------\n"));
e5995acd 209 printf (_("max number of segments = %ju\n"), lim.shmmni);
56692a67
SK
210 ipc_print_size(unit == IPC_UNIT_DEFAULT ? IPC_UNIT_KB : unit,
211 _("max seg size"), lim.shmmax, "\n", 0);
61e29ab4
RM
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 }
56692a67 218 ipc_print_size(unit == IPC_UNIT_DEFAULT ? IPC_UNIT_KB : unit,
61e29ab4 219 _("max total shared memory"), tmp, "\n", 0);
56692a67
SK
220 ipc_print_size(unit == IPC_UNIT_DEFAULT ? IPC_UNIT_BYTES : unit,
221 _("min seg size"), lim.shmmin, "\n", 0);
6dbe3af9 222 return;
61e14b4a 223 }
6dbe3af9 224 case STATUS:
61e14b4a
KZ
225 {
226 int maxid;
929c2575
KZ
227 struct shmid_ds shmbuf;
228 struct shm_info *shm_info;
61e14b4a 229
929c2575
KZ
230 maxid = shmctl (0, SHM_INFO, &shmbuf);
231 shm_info = (struct shm_info *) &shmbuf;
61e14b4a
KZ
232 if (maxid < 0) {
233 printf (_("kernel not configured for shared memory\n"));
234 return;
235 }
236
7eda085c 237 printf (_("------ Shared Memory Status --------\n"));
1e13900a 238 /*
455fe9a0 239 * TRANSLATORS: This output format is maintained for backward
1e13900a
SK
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 */
4163ab18 249 printf (_("segments allocated %d\n"
1e13900a
SK
250 "pages allocated %ld\n"
251 "pages resident %ld\n"
252 "pages swapped %ld\n"
253 "Swap performance: %ld attempts\t %ld successes\n"),
929c2575
KZ
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);
6dbe3af9 259 return;
61e14b4a 260 }
6dbe3af9 261
61e14b4a
KZ
262 /*
263 * Headers only
264 */
6dbe3af9 265 case CREATOR:
7eda085c 266 printf (_("------ Shared Memory Segment Creators/Owners --------\n"));
11658135
BS
267 printf ("%-10s %-10s %-10s %-10s %-10s %-10s\n",
268 _("shmid"),_("perms"),_("cuid"),_("cgid"),_("uid"),_("gid"));
6dbe3af9
KZ
269 break;
270
271 case TIME:
7eda085c 272 printf (_("------ Shared Memory Attach/Detach/Change Times --------\n"));
11658135 273 printf ("%-10s %-10s %-20s %-20s %-20s\n",
364cda48
KZ
274 _("shmid"),_("owner"),_("attached"),_("detached"),
275 _("changed"));
6dbe3af9
KZ
276 break;
277
278 case PID:
3c462efe 279 printf (_("------ Shared Memory Creator/Last-op PIDs --------\n"));
11658135 280 printf ("%-10s %-10s %-10s %-10s\n",
364cda48 281 _("shmid"),_("owner"),_("cpid"),_("lpid"));
6dbe3af9
KZ
282 break;
283
284 default:
7eda085c 285 printf (_("------ Shared Memory Segments --------\n"));
11658135 286 printf ("%-10s %-10s %-10s %-10s %-10s %-10s %-12s\n",
56692a67
SK
287 _("key"),_("shmid"),_("owner"),_("perms"),
288 unit == IPC_UNIT_HUMAN ? _("size") : _("bytes"),
364cda48 289 _("nattch"),_("status"));
6dbe3af9
KZ
290 break;
291 }
292
61e14b4a
KZ
293 /*
294 * Print data
295 */
296 if (ipc_shm_get_info(-1, &shmds) < 1)
058e8154 297 return;
058e8154
SK
298
299 for (shmdsp = shmds; shmdsp->next != NULL; shmdsp = shmdsp->next) {
6dbe3af9 300 if (format == CREATOR) {
058e8154 301 ipc_print_perms(stdout, &shmdsp->shm_perm);
6dbe3af9
KZ
302 continue;
303 }
058e8154 304 pw = getpwuid(shmdsp->shm_perm.uid);
6dbe3af9 305 switch (format) {
bf7b8d77 306 case TIME:
6dbe3af9 307 if (pw)
058e8154 308 printf ("%-10d %-10.10s", shmdsp->shm_perm.id, pw->pw_name);
6dbe3af9 309 else
058e8154 310 printf ("%-10d %-10u", shmdsp->shm_perm.id, shmdsp->shm_perm.uid);
c07ebfa1 311 /* ctime uses static buffer: use separate calls */
058e8154 312 printf(" %-20.16s", shmdsp->shm_atim
278e7203 313 ? xctime(&shmdsp->shm_atim) + 4 : _("Not set"));
058e8154 314 printf(" %-20.16s", shmdsp->shm_dtim
278e7203 315 ? xctime(&shmdsp->shm_dtim) + 4 : _("Not set"));
058e8154 316 printf(" %-20.16s\n", shmdsp->shm_ctim
278e7203 317 ? xctime(&shmdsp->shm_ctim) + 4 : _("Not set"));
6dbe3af9
KZ
318 break;
319 case PID:
320 if (pw)
058e8154 321 printf ("%-10d %-10.10s", shmdsp->shm_perm.id, pw->pw_name);
6dbe3af9 322 else
058e8154
SK
323 printf ("%-10d %-10u", shmdsp->shm_perm.id, shmdsp->shm_perm.uid);
324 printf (" %-10u %-10u\n",
325 shmdsp->shm_cprid, shmdsp->shm_lprid);
6dbe3af9 326 break;
bf7b8d77 327
6dbe3af9 328 default:
058e8154 329 printf("0x%08x ", shmdsp->shm_perm.key);
6dbe3af9 330 if (pw)
058e8154 331 printf ("%-10d %-10.10s", shmdsp->shm_perm.id, pw->pw_name);
6dbe3af9 332 else
058e8154 333 printf ("%-10d %-10u", shmdsp->shm_perm.id, shmdsp->shm_perm.uid);
56692a67 334 printf (" %-10o ", shmdsp->shm_perm.mode & 0777);
7e88f617
KZ
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
278e7203 341 printf (" %-10ju %-6s %-6s\n",
058e8154
SK
342 shmdsp->shm_nattch,
343 shmdsp->shm_perm.mode & SHM_DEST ? _("dest") : " ",
344 shmdsp->shm_perm.mode & SHM_LOCKED ? _("locked") : " ");
6dbe3af9
KZ
345 break;
346 }
347 }
058e8154
SK
348
349 ipc_shm_free_info(shmds);
6dbe3af9
KZ
350 return;
351}
352
1e2418a2 353static void do_sem (char format)
6dbe3af9 354{
6dbe3af9 355 struct passwd *pw;
1e2418a2 356 struct sem_data *semds, *semdsp;
bf7b8d77 357
6dbe3af9
KZ
358 switch (format) {
359 case LIMITS:
1e2418a2
SK
360 {
361 struct ipc_limits lim;
362
fcae4063
RM
363 if (ipc_sem_get_limits(&lim)) {
364 printf (_("unable to fetch semaphore limits\n"));
6dbe3af9 365 return;
fcae4063
RM
366 }
367 printf (_("------ Semaphore Limits --------\n"));
e5995acd
SK
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);
e3ca1312 372 printf (_("semaphore max value = %u\n"), lim.semvmx);
6dbe3af9 373 return;
1e2418a2 374 }
6dbe3af9 375 case STATUS:
1e2418a2
SK
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 }
7eda085c
KZ
384 printf (_("------ Semaphore Status --------\n"));
385 printf (_("used arrays = %d\n"), seminfo.semusz);
386 printf (_("allocated semaphores = %d\n"), seminfo.semaem);
6dbe3af9 387 return;
1e2418a2 388 }
6dbe3af9
KZ
389
390 case CREATOR:
7eda085c 391 printf (_("------ Semaphore Arrays Creators/Owners --------\n"));
11658135
BS
392 printf ("%-10s %-10s %-10s %-10s %-10s %-10s\n",
393 _("semid"),_("perms"),_("cuid"),_("cgid"),_("uid"),_("gid"));
6dbe3af9
KZ
394 break;
395
396 case TIME:
4ac0f9d0 397 printf (_("------ Semaphore Operation/Change Times --------\n"));
11658135 398 printf ("%-8s %-10s %-26.24s %-26.24s\n",
4ac0f9d0 399 _("semid"),_("owner"),_("last-op"),_("last-changed"));
6dbe3af9
KZ
400 break;
401
402 case PID:
403 break;
404
405 default:
7eda085c 406 printf (_("------ Semaphore Arrays --------\n"));
11658135 407 printf ("%-10s %-10s %-10s %-10s %-10s\n",
6557c512 408 _("key"),_("semid"),_("owner"),_("perms"),_("nsems"));
6dbe3af9
KZ
409 break;
410 }
411
1e2418a2
SK
412 /*
413 * Print data
414 */
415 if (ipc_sem_get_info(-1, &semds) < 1)
416 return;
1e2418a2
SK
417
418 for (semdsp = semds; semdsp->next != NULL; semdsp = semdsp->next) {
6dbe3af9 419 if (format == CREATOR) {
1e2418a2 420 ipc_print_perms(stdout, &semdsp->sem_perm);
6dbe3af9
KZ
421 continue;
422 }
1e2418a2 423 pw = getpwuid(semdsp->sem_perm.uid);
6dbe3af9 424 switch (format) {
bf7b8d77 425 case TIME:
6dbe3af9 426 if (pw)
1e2418a2 427 printf ("%-8d %-10.10s", semdsp->sem_perm.id, pw->pw_name);
6dbe3af9 428 else
1e2418a2
SK
429 printf ("%-8d %-10u", semdsp->sem_perm.id, semdsp->sem_perm.uid);
430 printf (" %-26.24s", semdsp->sem_otime
278e7203 431 ? xctime(&semdsp->sem_otime) : _("Not set"));
1e2418a2 432 printf (" %-26.24s\n", semdsp->sem_ctime
278e7203 433 ? xctime( &semdsp->sem_ctime) : _("Not set"));
6dbe3af9
KZ
434 break;
435 case PID:
436 break;
bf7b8d77 437
6dbe3af9 438 default:
1e2418a2 439 printf("0x%08x ", semdsp->sem_perm.key);
6dbe3af9 440 if (pw)
1e2418a2 441 printf ("%-10d %-10.10s", semdsp->sem_perm.id, pw->pw_name);
6dbe3af9 442 else
1e2418a2 443 printf ("%-10d %-10u", semdsp->sem_perm.id, semdsp->sem_perm.uid);
278e7203 444 printf (" %-10o %-10ju\n",
1e2418a2
SK
445 semdsp->sem_perm.mode & 0777,
446 semdsp->sem_nsems);
6dbe3af9
KZ
447 break;
448 }
449 }
1e2418a2
SK
450
451 ipc_sem_free_info(semds);
452 return;
6dbe3af9
KZ
453}
454
56692a67 455static void do_msg (char format, int unit)
6dbe3af9 456{
6dbe3af9 457 struct passwd *pw;
35118dfc 458 struct msg_data *msgds, *msgdsp;
bf7b8d77 459
6dbe3af9
KZ
460 switch (format) {
461 case LIMITS:
35118dfc
SK
462 {
463 struct ipc_limits lim;
464
fcae4063
RM
465 if (ipc_msg_get_limits(&lim)) {
466 printf (_("unable to fetch message limits\n"));
6dbe3af9 467 return;
fcae4063 468 }
f29922a5 469 printf (_("------ Messages Limits --------\n"));
e5995acd 470 printf (_("max queues system wide = %d\n"), lim.msgmni);
56692a67
SK
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);
6dbe3af9 475 return;
35118dfc 476 }
6dbe3af9 477 case STATUS:
35118dfc
SK
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 }
f29922a5 484 printf (_("------ Messages Status --------\n"));
e4a382b7 485#ifndef __FreeBSD_kernel__
7eda085c
KZ
486 printf (_("allocated queues = %d\n"), msginfo.msgpool);
487 printf (_("used headers = %d\n"), msginfo.msgmap);
e4a382b7 488#endif
fce1a348 489 ipc_print_size(unit, _("used space"), msginfo.msgtql,
56692a67 490 unit == IPC_UNIT_DEFAULT ? _(" bytes\n") : "\n", 0);
6dbe3af9 491 return;
35118dfc 492 }
6dbe3af9 493 case CREATOR:
f29922a5 494 printf (_("------ Message Queues Creators/Owners --------\n"));
11658135
BS
495 printf ("%-10s %-10s %-10s %-10s %-10s %-10s\n",
496 _("msqid"),_("perms"),_("cuid"),_("cgid"),_("uid"),_("gid"));
6dbe3af9
KZ
497 break;
498
499 case TIME:
7eda085c 500 printf (_("------ Message Queues Send/Recv/Change Times --------\n"));
11658135 501 printf ("%-8s %-10s %-20s %-20s %-20s\n",
7eda085c 502 _("msqid"),_("owner"),_("send"),_("recv"),_("change"));
6dbe3af9
KZ
503 break;
504
505 case PID:
bf7b8d77 506 printf (_("------ Message Queues PIDs --------\n"));
11658135 507 printf ("%-10s %-10s %-10s %-10s\n",
364cda48 508 _("msqid"),_("owner"),_("lspid"),_("lrpid"));
6dbe3af9
KZ
509 break;
510
511 default:
7eda085c 512 printf (_("------ Message Queues --------\n"));
11658135 513 printf ("%-10s %-10s %-10s %-10s %-12s %-12s\n",
364cda48 514 _("key"), _("msqid"), _("owner"), _("perms"),
56692a67
SK
515 unit == IPC_UNIT_HUMAN ? _("size") : _("used-bytes"),
516 _("messages"));
6dbe3af9
KZ
517 break;
518 }
519
35118dfc
SK
520 /*
521 * Print data
522 */
523 if (ipc_msg_get_info(-1, &msgds) < 1)
524 return;
35118dfc
SK
525
526 for (msgdsp = msgds; msgdsp->next != NULL; msgdsp = msgdsp->next) {
527 if (format == CREATOR) {
528 ipc_print_perms(stdout, &msgdsp->msg_perm);
6dbe3af9
KZ
529 continue;
530 }
35118dfc 531 pw = getpwuid(msgdsp->msg_perm.uid);
6dbe3af9 532 switch (format) {
364cda48 533 case TIME:
6dbe3af9 534 if (pw)
35118dfc 535 printf ("%-8d %-10.10s", msgdsp->msg_perm.id, pw->pw_name);
6dbe3af9 536 else
35118dfc
SK
537 printf ("%-8d %-10u", msgdsp->msg_perm.id, msgdsp->msg_perm.uid);
538 printf (" %-20.16s", msgdsp->q_stime
278e7203 539 ? xctime(&msgdsp->q_stime) + 4 : _("Not set"));
35118dfc 540 printf (" %-20.16s", msgdsp->q_rtime
278e7203 541 ? xctime(&msgdsp->q_rtime) + 4 : _("Not set"));
35118dfc 542 printf (" %-20.16s\n", msgdsp->q_ctime
278e7203 543 ? xctime(&msgdsp->q_ctime) + 4 : _("Not set"));
6dbe3af9
KZ
544 break;
545 case PID:
bf7b8d77 546 if (pw)
35118dfc 547 printf ("%-8d %-10.10s", msgdsp->msg_perm.id, pw->pw_name);
bf7b8d77 548 else
35118dfc 549 printf ("%-8d %-10u", msgdsp->msg_perm.id, msgdsp->msg_perm.uid);
bf7b8d77 550 printf (" %5d %5d\n",
35118dfc 551 msgdsp->q_lspid, msgdsp->q_lrpid);
bf7b8d77 552 break;
fd6b7a7f 553
6dbe3af9 554 default:
35118dfc 555 printf( "0x%08x ",msgdsp->msg_perm.key );
6dbe3af9 556 if (pw)
35118dfc 557 printf ("%-10d %-10.10s", msgdsp->msg_perm.id, pw->pw_name);
6dbe3af9 558 else
35118dfc 559 printf ("%-10d %-10u", msgdsp->msg_perm.id, msgdsp->msg_perm.uid);
56692a67 560 printf (" %-10o ", msgdsp->msg_perm.mode & 0777);
7e88f617
KZ
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
278e7203 567 printf (" %-12ju\n", msgdsp->q_qnum);
6dbe3af9
KZ
568 break;
569 }
570 }
35118dfc
SK
571
572 ipc_msg_free_info(msgds);
6dbe3af9
KZ
573 return;
574}
575
56692a67 576static void print_shm(int shmid, int unit)
6dbe3af9 577{
3ec6f778
SK
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"),
e0bbe3d6 587 shmdata->shm_perm.uid, shmdata->shm_perm.gid,
3ec6f778
SK
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);
56692a67
SK
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,
3ec6f778
SK
595 shmdata->shm_nattch);
596 printf(_("att_time=%-26.24s\n"),
278e7203 597 shmdata->shm_atim ? xctime(&(shmdata->shm_atim)) : _("Not set"));
3ec6f778 598 printf(_("det_time=%-26.24s\n"),
278e7203
KZ
599 shmdata->shm_dtim ? xctime(&shmdata->shm_dtim) : _("Not set"));
600 printf(_("change_time=%-26.24s\n"), xctime(&shmdata->shm_ctim));
3ec6f778
SK
601 printf("\n");
602
603 ipc_shm_free_info(shmdata);
6dbe3af9
KZ
604}
605
2ba641e5 606static void print_msg(int msgid, int unit)
6dbe3af9 607{
2bd2f79d 608 struct msg_data *msgdata;
6dbe3af9 609
2bd2f79d
SK
610 if (ipc_msg_get_info(msgid, &msgdata) < 1) {
611 warnx(_("id %d not found"), msgid);
612 return;
613 }
bf7b8d77 614
2bd2f79d
SK
615 printf(_("\nMessage Queue msqid=%d\n"), msgid);
616 printf(_("uid=%u\tgid=%u\tcuid=%u\tcgid=%u\tmode=%#o\n"),
e0bbe3d6 617 msgdata->msg_perm.uid, msgdata->msg_perm.gid,
2bd2f79d
SK
618 msgdata->msg_perm.cuid, msgdata->msg_perm.cgid,
619 msgdata->msg_perm.mode);
56692a67
SK
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,
2bd2f79d
SK
626 msgdata->q_lspid, msgdata->q_lrpid);
627 printf(_("send_time=%-26.24s\n"),
278e7203 628 msgdata->q_stime ? xctime(&msgdata->q_stime) : _("Not set"));
2bd2f79d 629 printf(_("rcv_time=%-26.24s\n"),
278e7203 630 msgdata->q_rtime ? xctime(&msgdata->q_rtime) : _("Not set"));
2bd2f79d 631 printf(_("change_time=%-26.24s\n"),
278e7203 632 msgdata->q_ctime ? xctime(&msgdata->q_ctime) : _("Not set"));
2bd2f79d
SK
633 printf("\n");
634
635 ipc_msg_free_info(msgdata);
6dbe3af9
KZ
636}
637
b5504a3d 638static void print_sem(int semid)
6dbe3af9 639{
b5504a3d 640 struct sem_data *semdata;
b60b3c1b 641 size_t i;
6dbe3af9 642
b5504a3d
SK
643 if (ipc_sem_get_info(semid, &semdata) < 1) {
644 warnx(_("id %d not found"), semid);
645 return;
6dbe3af9 646 }
b5504a3d
SK
647
648 printf(_("\nSemaphore Array semid=%d\n"), semid);
649 printf(_("uid=%u\t gid=%u\t cuid=%u\t cgid=%u\n"),
e0bbe3d6 650 semdata->sem_perm.uid, semdata->sem_perm.gid,
b5504a3d
SK
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);
278e7203 654 printf(_("nsems = %ju\n"), semdata->sem_nsems);
b5504a3d 655 printf(_("otime = %-26.24s\n"),
278e7203
KZ
656 semdata->sem_otime ? xctime(&semdata->sem_otime) : _("Not set"));
657 printf(_("ctime = %-26.24s\n"), xctime(&semdata->sem_ctime));
b5504a3d
SK
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];
e3ca1312 664 printf("%-10zu %-10d %-10d %-10d %-10d\n",
b5504a3d
SK
665 i, e->semval, e->ncount, e->zcount, e->pid);
666 }
667 printf("\n");
668 ipc_sem_free_info(semdata);
6dbe3af9 669}