Changeset 3232 in MondoRescue for branches/3.2/mindi-busybox/util-linux/ipcs.c
- Timestamp:
- Jan 1, 2014, 12:47:38 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.2/mindi-busybox/util-linux/ipcs.c
r2725 r3232 9 9 */ 10 10 11 //usage:#define ipcs_trivial_usage 12 //usage: "[[-smq] -i shmid] | [[-asmq] [-tcplu]]" 13 //usage:#define ipcs_full_usage "\n\n" 14 //usage: " -i Show specific resource" 15 //usage: "\nResource specification:" 16 //usage: "\n -m Shared memory segments" 17 //usage: "\n -q Message queues" 18 //usage: "\n -s Semaphore arrays" 19 //usage: "\n -a All (default)" 20 //usage: "\nOutput format:" 21 //usage: "\n -t Time" 22 //usage: "\n -c Creator" 23 //usage: "\n -p Pid" 24 //usage: "\n -l Limits" 25 //usage: "\n -u Summary" 26 11 27 /* X/OPEN tells us to use <sys/{types,ipc,sem}.h> for semctl() */ 12 28 /* X/OPEN tells us to use <sys/{types,ipc,msg}.h> for msgctl() */ … … 40 56 struct shm_info { 41 57 int used_ids; 42 u long shm_tot; /* total allocated shm */43 u long shm_rss; /* total resident shm */44 u long shm_swp; /* total swapped shm */45 u long swap_attempts;46 u long swap_successes;58 unsigned long shm_tot; /* total allocated shm */ 59 unsigned long shm_rss; /* total resident shm */ 60 unsigned long shm_swp; /* total swapped shm */ 61 unsigned long swap_attempts; 62 unsigned long swap_successes; 47 63 }; 48 64 #endif … … 137 153 return; 138 154 /* glibc 2.1.3 and all earlier libc's have ints as fields 139 155 * of struct shminfo; glibc 2.1.91 has unsigned long; ach */ 140 156 printf("max number of segments = %lu\n" 141 142 143 144 145 146 147 157 "max seg size (kbytes) = %lu\n" 158 "max total shared memory (pages) = %lu\n" 159 "min seg size (bytes) = %lu\n", 160 (unsigned long) shminfo.shmmni, 161 (unsigned long) (shminfo.shmmax >> 10), 162 (unsigned long) shminfo.shmall, 163 (unsigned long) shminfo.shmmin); 148 164 return; 149 165 150 166 case STATUS: 151 167 printf("------ Shared Memory %s --------\n", "Status"); 152 printf( 153 154 155 156 157 158 159 160 161 168 printf("segments allocated %d\n" 169 "pages allocated %ld\n" 170 "pages resident %ld\n" 171 "pages swapped %ld\n" 172 "Swap performance: %ld attempts\t%ld successes\n", 173 shm_info.used_ids, 174 shm_info.shm_tot, 175 shm_info.shm_rss, 176 shm_info.shm_swp, 177 shm_info.swap_attempts, shm_info.swap_successes); 162 178 return; 163 179 164 180 case CREATOR: 165 181 printf("------ Shared Memory %s --------\n", "Segment Creators/Owners"); 166 printf( 167 182 printf("%-10s %-10s %-10s %-10s %-10s %-10s\n", 183 "shmid", "perms", "cuid", "cgid", "uid", "gid"); 168 184 break; 169 185 170 186 case TIME: 171 187 printf("------ Shared Memory %s --------\n", "Attach/Detach/Change Times"); 172 printf( 173 188 printf("%-10s %-10s %-20s %-20s %-20s\n", 189 "shmid", "owner", "attached", "detached", "changed"); 174 190 break; 175 191 176 192 case PID: 177 193 printf("------ Shared Memory %s --------\n", "Creator/Last-op"); 178 printf( 179 194 printf("%-10s %-10s %-10s %-10s\n", 195 "shmid", "owner", "cpid", "lpid"); 180 196 break; 181 197 182 198 default: 183 199 printf("------ Shared Memory %s --------\n", "Segments"); 184 printf( 185 186 200 printf("%-10s %-10s %-10s %-10s %-10s %-10s %-12s\n", 201 "key", "shmid", "owner", "perms", "bytes", "nattch", 202 "status"); 187 203 break; 188 204 } … … 205 221 /* ctime uses static buffer: use separate calls */ 206 222 printf(" %-20.16s", shmseg.shm_atime 207 223 ? ctime(&shmseg.shm_atime) + 4 : "Not set"); 208 224 printf(" %-20.16s", shmseg.shm_dtime 209 225 ? ctime(&shmseg.shm_dtime) + 4 : "Not set"); 210 226 printf(" %-20.16s\n", shmseg.shm_ctime 211 227 ? ctime(&shmseg.shm_ctime) + 4 : "Not set"); 212 228 break; 213 229 case PID: … … 226 242 printf("%-10d %-10d", shmid, ipcp->uid); 227 243 printf(" %-10o %-10lu %-10ld %-6s %-6s\n", ipcp->mode & 0777, 228 229 230 231 232 233 234 235 236 237 238 244 /* 245 * earlier: int, Austin has size_t 246 */ 247 (unsigned long) shmseg.shm_segsz, 248 /* 249 * glibc-2.1.3 and earlier has unsigned short; 250 * Austin has shmatt_t 251 */ 252 (long) shmseg.shm_nattch, 253 ipcp->mode & SHM_DEST ? "dest" : " ", 254 ipcp->mode & SHM_LOCKED ? "locked" : " "); 239 255 break; 240 256 } … … 252 268 union semun arg; 253 269 254 arg.array = (u short *) (void *) &seminfo;270 arg.array = (unsigned short *) (void *) &seminfo; 255 271 maxid = semctl(0, 0, SEM_INFO, arg); 256 272 if (maxid < 0) { … … 262 278 case LIMITS: 263 279 printf("------ Semaphore %s --------\n", "Limits"); 264 arg.array = (u short *) (void *) &seminfo; /* damn union */280 arg.array = (unsigned short *) (void *) &seminfo; /* damn union */ 265 281 if ((semctl(0, 0, IPC_INFO, arg)) < 0) 266 282 return; 267 283 printf("max number of arrays = %d\n" 268 269 270 271 272 273 274 284 "max semaphores per array = %d\n" 285 "max semaphores system wide = %d\n" 286 "max ops per semop call = %d\n" 287 "semaphore max value = %d\n", 288 seminfo.semmni, 289 seminfo.semmsl, 290 seminfo.semmns, seminfo.semopm, seminfo.semvmx); 275 291 return; 276 292 277 293 case STATUS: 278 294 printf("------ Semaphore %s --------\n", "Status"); 279 printf( 280 281 295 printf("used arrays = %d\n" 296 "allocated semaphores = %d\n", 297 seminfo.semusz, seminfo.semaem); 282 298 return; 283 299 284 300 case CREATOR: 285 301 printf("------ Semaphore %s --------\n", "Arrays Creators/Owners"); 286 printf( 287 302 printf("%-10s %-10s %-10s %-10s %-10s %-10s\n", 303 "semid", "perms", "cuid", "cgid", "uid", "gid"); 288 304 break; 289 305 290 306 case TIME: 291 307 printf("------ Shared Memory %s --------\n", "Operation/Change Times"); 292 printf( 293 308 printf("%-8s %-10s %-26.24s %-26.24s\n", 309 "shmid", "owner", "last-op", "last-changed"); 294 310 break; 295 311 … … 299 315 default: 300 316 printf("------ Semaphore %s --------\n", "Arrays"); 301 printf( 302 317 printf("%-10s %-10s %-10s %-10s %-10s\n", 318 "key", "semid", "owner", "perms", "nsems"); 303 319 break; 304 320 } … … 322 338 /* ctime uses static buffer: use separate calls */ 323 339 printf(" %-26.24s", semary.sem_otime 324 340 ? ctime(&semary.sem_otime) : "Not set"); 325 341 printf(" %-26.24s\n", semary.sem_ctime 326 342 ? ctime(&semary.sem_ctime) : "Not set"); 327 343 break; 328 344 case PID: … … 336 352 printf("%-10d %-9d", semid, ipcp->uid); 337 353 printf(" %-10o %-10ld\n", ipcp->mode & 0777, 338 339 340 341 342 343 344 354 /* 355 * glibc-2.1.3 and earlier has unsigned short; 356 * glibc-2.1.91 has variation between 357 * unsigned short and unsigned long 358 * Austin prescribes unsigned short. 359 */ 360 (long) semary.sem_nsems); 345 361 break; 346 362 } … … 368 384 return; 369 385 printf("------ Message%s --------\n", "s: Limits"); 370 printf( 371 372 373 386 printf("max queues system wide = %d\n" 387 "max size of message (bytes) = %d\n" 388 "default max size of queue (bytes) = %d\n", 389 msginfo.msgmni, msginfo.msgmax, msginfo.msgmnb); 374 390 return; 375 391 376 392 case STATUS: 377 393 printf("------ Message%s --------\n", "s: Status"); 378 printf( 379 380 381 394 printf("allocated queues = %d\n" 395 "used headers = %d\n" 396 "used space = %d bytes\n", 397 msginfo.msgpool, msginfo.msgmap, msginfo.msgtql); 382 398 return; 383 399 384 400 case CREATOR: 385 401 printf("------ Message%s --------\n", " Queues: Creators/Owners"); 386 printf( 387 402 printf("%-10s %-10s %-10s %-10s %-10s %-10s\n", 403 "msqid", "perms", "cuid", "cgid", "uid", "gid"); 388 404 break; 389 405 390 406 case TIME: 391 407 printf("------ Message%s --------\n", " Queues Send/Recv/Change Times"); 392 printf( 393 408 printf("%-8s %-10s %-20s %-20s %-20s\n", 409 "msqid", "owner", "send", "recv", "change"); 394 410 break; 395 411 396 412 case PID: 397 413 printf("------ Message%s --------\n", " Queues PIDs"); 398 printf( 399 414 printf("%-10s %-10s %-10s %-10s\n", 415 "msqid", "owner", "lspid", "lrpid"); 400 416 break; 401 417 402 418 default: 403 419 printf("------ Message%s --------\n", " Queues"); 404 printf( 405 420 printf("%-10s %-10s %-10s %-10s %-12s %-12s\n", 421 "key", "msqid", "owner", "perms", "used-bytes", "messages"); 406 422 break; 407 423 } … … 423 439 printf("%-8d %-10d", msqid, ipcp->uid); 424 440 printf(" %-20.16s", msgque.msg_stime 425 441 ? ctime(&msgque.msg_stime) + 4 : "Not set"); 426 442 printf(" %-20.16s", msgque.msg_rtime 427 443 ? ctime(&msgque.msg_rtime) + 4 : "Not set"); 428 444 printf(" %-20.16s\n", msgque.msg_ctime 429 445 ? ctime(&msgque.msg_ctime) + 4 : "Not set"); 430 446 break; 431 447 case PID: … … 444 460 printf("%-10d %-10d", msqid, ipcp->uid); 445 461 printf(" %-10o %-12ld %-12ld\n", ipcp->mode & 0777, 446 447 448 449 450 451 452 462 /* 463 * glibc-2.1.3 and earlier has unsigned short; 464 * glibc-2.1.91 has variation between 465 * unsigned short, unsigned long 466 * Austin has msgqnum_t 467 */ 468 (long) msgque.msg_cbytes, (long) msgque.msg_qnum); 453 469 break; 454 470 } … … 468 484 469 485 printf("\nShared memory Segment shmid=%d\n" 470 471 472 473 474 475 476 477 486 "uid=%d\tgid=%d\tcuid=%d\tcgid=%d\n" 487 "mode=%#o\taccess_perms=%#o\n" 488 "bytes=%ld\tlpid=%d\tcpid=%d\tnattch=%ld\n", 489 shmid, 490 ipcp->uid, ipcp->gid, ipcp->cuid, ipcp->cgid, 491 ipcp->mode, ipcp->mode & 0777, 492 (long) shmds.shm_segsz, shmds.shm_lpid, shmds.shm_cpid, 493 (long) shmds.shm_nattch); 478 494 printf("att_time=%-26.24s\n", 479 495 shmds.shm_atime ? ctime(&shmds.shm_atime) : "Not set"); 480 496 printf("det_time=%-26.24s\n", 481 497 shmds.shm_dtime ? ctime(&shmds.shm_dtime) : "Not set"); 482 498 printf("change_time=%-26.24s\n\n", ctime(&shmds.shm_ctime)); 483 499 } … … 495 511 496 512 printf("\nMessage Queue msqid=%d\n" 497 498 499 500 501 502 503 504 505 506 507 513 "uid=%d\tgid=%d\tcuid=%d\tcgid=%d\tmode=%#o\n" 514 "cbytes=%ld\tqbytes=%ld\tqnum=%ld\tlspid=%d\tlrpid=%d\n", 515 msqid, ipcp->uid, ipcp->gid, ipcp->cuid, ipcp->cgid, ipcp->mode, 516 /* 517 * glibc-2.1.3 and earlier has unsigned short; 518 * glibc-2.1.91 has variation between 519 * unsigned short, unsigned long 520 * Austin has msgqnum_t (for msg_qbytes) 521 */ 522 (long) buf.msg_cbytes, (long) buf.msg_qbytes, 523 (long) buf.msg_qnum, buf.msg_lspid, buf.msg_lrpid); 508 524 509 525 printf("send_time=%-26.24s\n", 510 526 buf.msg_stime ? ctime(&buf.msg_stime) : "Not set"); 511 527 printf("rcv_time=%-26.24s\n", 512 528 buf.msg_rtime ? ctime(&buf.msg_rtime) : "Not set"); 513 529 printf("change_time=%-26.24s\n\n", 514 530 buf.msg_ctime ? ctime(&buf.msg_ctime) : "Not set"); 515 531 } 516 532 … … 529 545 530 546 printf("\nSemaphore Array semid=%d\n" 531 532 533 534 535 536 537 538 539 547 "uid=%d\t gid=%d\t cuid=%d\t cgid=%d\n" 548 "mode=%#o, access_perms=%#o\n" 549 "nsems = %ld\n" 550 "otime = %-26.24s\n", 551 semid, 552 ipcp->uid, ipcp->gid, ipcp->cuid, ipcp->cgid, 553 ipcp->mode, ipcp->mode & 0777, 554 (long) semds.sem_nsems, 555 semds.sem_otime ? ctime(&semds.sem_otime) : "Not set"); 540 556 printf("ctime = %-26.24s\n" 541 542 543 557 "%-10s %-10s %-10s %-10s %-10s\n", 558 ctime(&semds.sem_ctime), 559 "semnum", "value", "ncount", "zcount", "pid"); 544 560 545 561 arg.val = 0;
Note:
See TracChangeset
for help on using the changeset viewer.