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