Changeset 1770 in MondoRescue for branches/stable/mindi-busybox/util-linux/ipcs.c
- Timestamp:
- Nov 6, 2007, 11:01:53 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/stable/mindi-busybox/util-linux/ipcs.c
r821 r1770 1 /* vi: set sw=4 ts=4: */ 1 2 /* 2 3 * ipcs.c -- provides information on allocated ipc resources. … … 8 9 */ 9 10 10 #include <stdio.h>11 #include <stdlib.h>12 #include <getopt.h>13 #include <errno.h>14 #include <time.h>15 #include <pwd.h>16 #include <grp.h>17 18 11 /* X/OPEN tells us to use <sys/{types,ipc,sem}.h> for semctl() */ 19 12 /* X/OPEN tells us to use <sys/{types,ipc,msg}.h> for msgctl() */ … … 25 18 #include <sys/shm.h> 26 19 27 #include " busybox.h"20 #include "libbb.h" 28 21 29 22 /*-------------------------------------------------------------------*/ … … 32 25 #ifndef SHM_DEST 33 26 /* shm_mode upper byte flags */ 34 #define SHM_DEST 01000 35 #define SHM_LOCKED 02000 27 #define SHM_DEST 01000 /* segment will be destroyed on last detach */ 28 #define SHM_LOCKED 02000 /* segment will not be swapped */ 36 29 #endif 37 30 … … 46 39 #define SHM_INFO 14 47 40 struct shm_info { 48 intused_ids;49 ulong shm_tot;/* total allocated shm */50 ulong shm_rss;/* total resident shm */51 ulong shm_swp;/* total swapped shm */52 53 41 int used_ids; 42 ulong shm_tot; /* total allocated shm */ 43 ulong shm_rss; /* total resident shm */ 44 ulong shm_swp; /* total swapped shm */ 45 ulong swap_attempts; 46 ulong swap_successes; 54 47 }; 55 48 #endif … … 69 62 X/OPEN tells us to define it ourselves, but until recently 70 63 Linux include files would also define it. */ 71 #if defined 64 #if defined(__GNU_LIBRARY__) && !defined(_SEM_SEMUN_UNDEFINED) 72 65 /* union semun is defined by including <sys/sem.h> */ 73 66 #else … … 86 79 glibc-1.09 has no support for sysv ipc. 87 80 glibc 2 uses __key, __seq */ 88 #if defined 81 #if defined(__GNU_LIBRARY__) && __GNU_LIBRARY__ > 1 89 82 #define KEY __key 90 83 #else … … 98 91 #define PID 5 99 92 100 101 static void print_perms (int id, struct ipc_perm *ipcp) { 93 static char format; 94 95 static void print_perms(int id, struct ipc_perm *ipcp) 96 { 102 97 struct passwd *pw; 103 98 struct group *gr; 104 99 105 bb_printf("%-10d %-10o", id, ipcp->mode & 0777);100 printf("%-10d %-10o", id, ipcp->mode & 0777); 106 101 107 102 if ((pw = getpwuid(ipcp->cuid))) 108 bb_printf(" %-10s", pw->pw_name);103 printf(" %-10s", pw->pw_name); 109 104 else 110 bb_printf(" %-10d", ipcp->cuid);105 printf(" %-10d", ipcp->cuid); 111 106 if ((gr = getgrgid(ipcp->cgid))) 112 bb_printf(" %-10s", gr->gr_name);107 printf(" %-10s", gr->gr_name); 113 108 else 114 bb_printf(" %-10d", ipcp->cgid);109 printf(" %-10d", ipcp->cgid); 115 110 116 111 if ((pw = getpwuid(ipcp->uid))) 117 bb_printf(" %-10s", pw->pw_name);112 printf(" %-10s", pw->pw_name); 118 113 else 119 bb_printf(" %-10d", ipcp->uid);114 printf(" %-10d", ipcp->uid); 120 115 if ((gr = getgrgid(ipcp->gid))) 121 bb_printf(" %-10s\n", gr->gr_name);116 printf(" %-10s\n", gr->gr_name); 122 117 else 123 bb_printf(" %-10d\n", ipcp->gid);124 } 125 126 127 static void do_shm (char format)118 printf(" %-10d\n", ipcp->gid); 119 } 120 121 122 static void do_shm(void) 128 123 { 129 124 int maxid, shmid, id; … … 134 129 struct passwd *pw; 135 130 136 maxid = shmctl 131 maxid = shmctl(0, SHM_INFO, (struct shmid_ds *) (void *) &shm_info); 137 132 if (maxid < 0) { 138 bb_printf ("kernel not configured for shared memory\n");133 printf("kernel not configured for %s\n", "shared memory"); 139 134 return; 140 135 } … … 142 137 switch (format) { 143 138 case LIMITS: 144 bb_printf ("------ Shared Memory Limits --------\n");145 if ((shmctl (0, IPC_INFO, (struct shmid_ds *) (void *) &shminfo)) < 0)139 printf("------ Shared Memory %s --------\n", "Limits"); 140 if ((shmctl(0, IPC_INFO, (struct shmid_ds *) (void *) &shminfo)) < 0) 146 141 return; 147 142 /* glibc 2.1.3 and all earlier libc's have ints as fields 148 143 of struct shminfo; glibc 2.1.91 has unsigned long; ach */ 149 bb_printf("max number of segments = %lu\n"150 "max seg size (kbytes) = %lu\n"151 "max total shared memory (pages) = %lu\n"152 "min seg size (bytes) = %lu\n",153 (unsigned long) shminfo.shmmni,154 (unsigned long) (shminfo.shmmax >> 10),155 (unsigned long) shminfo.shmall,156 (unsigned long) shminfo.shmmin);144 printf("max number of segments = %lu\n" 145 "max seg size (kbytes) = %lu\n" 146 "max total shared memory (pages) = %lu\n" 147 "min seg size (bytes) = %lu\n", 148 (unsigned long) shminfo.shmmni, 149 (unsigned long) (shminfo.shmmax >> 10), 150 (unsigned long) shminfo.shmall, 151 (unsigned long) shminfo.shmmin); 157 152 return; 158 153 159 154 case STATUS: 160 bb_printf ("------ Shared Memory Status --------\n"161 162 "pages allocated %ld\n"163 "pages resident %ld\n"164 "pages swapped %ld\n"165 "Swap performance: %ld attempts\t%ld successes\n",166 shm_info.used_ids,167 shm_info.shm_tot,168 shm_info.shm_rss,169 shm_info.shm_swp,170 shm_info.swap_attempts, shm_info.swap_successes);155 printf("------ Shared Memory %s --------\n", "Status"); 156 printf( "segments allocated %d\n" 157 "pages allocated %ld\n" 158 "pages resident %ld\n" 159 "pages swapped %ld\n" 160 "Swap performance: %ld attempts\t%ld successes\n", 161 shm_info.used_ids, 162 shm_info.shm_tot, 163 shm_info.shm_rss, 164 shm_info.shm_swp, 165 shm_info.swap_attempts, shm_info.swap_successes); 171 166 return; 172 167 173 168 case CREATOR: 174 bb_printf ("------ Shared Memory Segment Creators/Owners --------\n"175 176 "shmid","perms","cuid","cgid","uid","gid");169 printf("------ Shared Memory %s --------\n", "Segment Creators/Owners"); 170 printf( "%-10s %-10s %-10s %-10s %-10s %-10s\n", 171 "shmid", "perms", "cuid", "cgid", "uid", "gid"); 177 172 break; 178 173 179 174 case TIME: 180 bb_printf ("------ Shared Memory Attach/Detach/Change Times --------\n"181 182 "shmid","owner","attached","detached","changed");175 printf("------ Shared Memory %s --------\n", "Attach/Detach/Change Times"); 176 printf( "%-10s %-10s %-20s %-20s %-20s\n", 177 "shmid", "owner", "attached", "detached", "changed"); 183 178 break; 184 179 185 180 case PID: 186 bb_printf ("------ Shared Memory Creator/Last-op --------\n"187 188 "shmid","owner","cpid","lpid");181 printf("------ Shared Memory %s --------\n", "Creator/Last-op"); 182 printf( "%-10s %-10s %-10s %-10s\n", 183 "shmid", "owner", "cpid", "lpid"); 189 184 break; 190 185 191 186 default: 192 bb_printf ("------ Shared Memory Segments --------\n" 193 "%-10s %-10s %-10s %-10s %-10s %-10s %-12s\n", 194 "key","shmid","owner","perms","bytes","nattch","status"); 187 printf("------ Shared Memory %s --------\n", "Segments"); 188 printf( "%-10s %-10s %-10s %-10s %-10s %-10s %-12s\n", 189 "key", "shmid", "owner", "perms", "bytes", "nattch", 190 "status"); 195 191 break; 196 192 } 197 193 198 194 for (id = 0; id <= maxid; id++) { 199 shmid = shmctl 195 shmid = shmctl(id, SHM_STAT, &shmseg); 200 196 if (shmid < 0) 201 197 continue; 202 if (format == CREATOR) 203 print_perms 198 if (format == CREATOR) { 199 print_perms(shmid, ipcp); 204 200 continue; 205 201 } … … 208 204 case TIME: 209 205 if (pw) 210 bb_printf("%-10d %-10.10s", shmid, pw->pw_name);211 else 212 bb_printf("%-10d %-10d", shmid, ipcp->uid);206 printf("%-10d %-10.10s", shmid, pw->pw_name); 207 else 208 printf("%-10d %-10d", shmid, ipcp->uid); 213 209 /* ctime uses static buffer: use separate calls */ 214 bb_printf("%-20.16s", shmseg.shm_atime215 216 bb_printf(" %-20.16s", shmseg.shm_dtime217 218 bb_printf(" %-20.16s\n", shmseg.shm_ctime219 210 printf(" %-20.16s", shmseg.shm_atime 211 ? ctime(&shmseg.shm_atime) + 4 : "Not set"); 212 printf(" %-20.16s", shmseg.shm_dtime 213 ? ctime(&shmseg.shm_dtime) + 4 : "Not set"); 214 printf(" %-20.16s\n", shmseg.shm_ctime 215 ? ctime(&shmseg.shm_ctime) + 4 : "Not set"); 220 216 break; 221 217 case PID: 222 218 if (pw) 223 bb_printf ("%-10d %-10.10s", shmid, pw->pw_name); 224 else 225 bb_printf ("%-10d %-10d", shmid, ipcp->uid); 226 bb_printf (" %-10d %-10d\n", 227 shmseg.shm_cpid, shmseg.shm_lpid); 219 printf("%-10d %-10.10s", shmid, pw->pw_name); 220 else 221 printf("%-10d %-10d", shmid, ipcp->uid); 222 printf(" %-10d %-10d\n", shmseg.shm_cpid, shmseg.shm_lpid); 228 223 break; 229 224 230 225 default: 231 bb_printf("0x%08x ",ipcp->KEY ); 232 if (pw) 233 bb_printf ("%-10d %-10.10s", shmid, pw->pw_name); 234 else 235 bb_printf ("%-10d %-10d", shmid, ipcp->uid); 236 bb_printf ("%-10o %-10lu %-10ld %-6s %-6s\n", 237 ipcp->mode & 0777, 238 /* 239 * earlier: int, Austin has size_t 240 */ 241 (unsigned long) shmseg.shm_segsz, 242 /* 243 * glibc-2.1.3 and earlier has unsigned short; 244 * Austin has shmatt_t 245 */ 246 (long) shmseg.shm_nattch, 247 ipcp->mode & SHM_DEST ? "dest" : " ", 248 ipcp->mode & SHM_LOCKED ? "locked" : " "); 249 break; 250 } 251 } 252 return; 253 } 254 255 256 static void do_sem (char format) 226 printf("0x%08x ", ipcp->KEY); 227 if (pw) 228 printf("%-10d %-10.10s", shmid, pw->pw_name); 229 else 230 printf("%-10d %-10d", shmid, ipcp->uid); 231 printf(" %-10o %-10lu %-10ld %-6s %-6s\n", ipcp->mode & 0777, 232 /* 233 * earlier: int, Austin has size_t 234 */ 235 (unsigned long) shmseg.shm_segsz, 236 /* 237 * glibc-2.1.3 and earlier has unsigned short; 238 * Austin has shmatt_t 239 */ 240 (long) shmseg.shm_nattch, 241 ipcp->mode & SHM_DEST ? "dest" : " ", 242 ipcp->mode & SHM_LOCKED ? "locked" : " "); 243 break; 244 } 245 } 246 } 247 248 249 static void do_sem(void) 257 250 { 258 251 int maxid, semid, id; … … 263 256 union semun arg; 264 257 265 arg.array = (ushort *) 266 maxid = semctl 258 arg.array = (ushort *) (void *) &seminfo; 259 maxid = semctl(0, 0, SEM_INFO, arg); 267 260 if (maxid < 0) { 268 bb_printf ("kernel not configured for semaphores\n");261 printf("kernel not configured for %s\n", "semaphores"); 269 262 return; 270 263 } … … 272 265 switch (format) { 273 266 case LIMITS: 274 bb_printf ("------ Semaphore Limits --------\n");275 arg.array = (ushort *) (void *) &seminfo; 276 if ((semctl (0, 0, IPC_INFO, arg)) < 0)267 printf("------ Semaphore %s --------\n", "Limits"); 268 arg.array = (ushort *) (void *) &seminfo; /* damn union */ 269 if ((semctl(0, 0, IPC_INFO, arg)) < 0) 277 270 return; 278 bb_printf ("max number of arrays = %d\n" 279 "max semaphores per array = %d\n" 280 "max semaphores system wide = %d\n" 281 "max ops per semop call = %d\n" 282 "semaphore max value = %d\n", 283 seminfo.semmni, 284 seminfo.semmsl, 285 seminfo.semmns, 286 seminfo.semopm, 287 seminfo.semvmx); 271 printf("max number of arrays = %d\n" 272 "max semaphores per array = %d\n" 273 "max semaphores system wide = %d\n" 274 "max ops per semop call = %d\n" 275 "semaphore max value = %d\n", 276 seminfo.semmni, 277 seminfo.semmsl, 278 seminfo.semmns, seminfo.semopm, seminfo.semvmx); 288 279 return; 289 280 290 281 case STATUS: 291 bb_printf ("------ Semaphore Status --------\n" 292 "used arrays = %d\n" 293 "allocated semaphores = %d\n", 294 seminfo.semusz, 295 seminfo.semaem); 282 printf("------ Semaphore %s --------\n", "Status"); 283 printf( "used arrays = %d\n" 284 "allocated semaphores = %d\n", 285 seminfo.semusz, seminfo.semaem); 296 286 return; 297 287 298 288 case CREATOR: 299 bb_printf ("------ Semaphore Arrays Creators/Owners --------\n"300 301 "semid","perms","cuid","cgid","uid","gid");289 printf("------ Semaphore %s --------\n", "Arrays Creators/Owners"); 290 printf( "%-10s %-10s %-10s %-10s %-10s %-10s\n", 291 "semid", "perms", "cuid", "cgid", "uid", "gid"); 302 292 break; 303 293 304 294 case TIME: 305 bb_printf ("------ Shared Memory Operation/Change Times --------\n"306 307 "shmid","owner","last-op","last-changed");295 printf("------ Shared Memory %s --------\n", "Operation/Change Times"); 296 printf( "%-8s %-10s %-26.24s %-26.24s\n", 297 "shmid", "owner", "last-op", "last-changed"); 308 298 break; 309 299 … … 312 302 313 303 default: 314 bb_printf ("------ Semaphore Arrays --------\n"315 316 "key","semid","owner","perms","nsems");304 printf("------ Semaphore %s --------\n", "Arrays"); 305 printf( "%-10s %-10s %-10s %-10s %-10s\n", 306 "key", "semid", "owner", "perms", "nsems"); 317 307 break; 318 308 } … … 320 310 for (id = 0; id <= maxid; id++) { 321 311 arg.buf = (struct semid_ds *) &semary; 322 semid = semctl 312 semid = semctl(id, 0, SEM_STAT, arg); 323 313 if (semid < 0) 324 314 continue; 325 if (format == CREATOR) 326 print_perms 315 if (format == CREATOR) { 316 print_perms(semid, ipcp); 327 317 continue; 328 318 } … … 331 321 case TIME: 332 322 if (pw) 333 bb_printf ("%-8d %-10.10s", semid, pw->pw_name); 334 else 335 bb_printf ("%-8d %-10d", semid, ipcp->uid); 336 bb_printf (" %-26.24s", semary.sem_otime 337 ? ctime(&semary.sem_otime) : "Not set"); 338 bb_printf (" %-26.24s\n", semary.sem_ctime 339 ? ctime(&semary.sem_ctime) : "Not set"); 323 printf("%-8d %-10.10s", semid, pw->pw_name); 324 else 325 printf("%-8d %-10d", semid, ipcp->uid); 326 /* ctime uses static buffer: use separate calls */ 327 printf(" %-26.24s", semary.sem_otime 328 ? ctime(&semary.sem_otime) : "Not set"); 329 printf(" %-26.24s\n", semary.sem_ctime 330 ? ctime(&semary.sem_ctime) : "Not set"); 340 331 break; 341 332 case PID: … … 343 334 344 335 default: 345 bb_printf("0x%08x ", ipcp->KEY); 346 if (pw) 347 bb_printf ("%-10d %-10.9s", semid, pw->pw_name); 348 else 349 bb_printf ("%-10d %-9d", semid, ipcp->uid); 350 bb_printf ("%-10o %-10ld\n", 351 ipcp->mode & 0777, 352 /* 353 * glibc-2.1.3 and earlier has unsigned short; 354 * glibc-2.1.91 has variation between 355 * unsigned short and unsigned long 356 * Austin prescribes unsigned short. 357 */ 358 (long) semary.sem_nsems); 359 break; 360 } 361 } 362 } 363 364 365 static void do_msg (char format) 336 printf("0x%08x ", ipcp->KEY); 337 if (pw) 338 printf("%-10d %-10.9s", semid, pw->pw_name); 339 else 340 printf("%-10d %-9d", semid, ipcp->uid); 341 printf(" %-10o %-10ld\n", ipcp->mode & 0777, 342 /* 343 * glibc-2.1.3 and earlier has unsigned short; 344 * glibc-2.1.91 has variation between 345 * unsigned short and unsigned long 346 * Austin prescribes unsigned short. 347 */ 348 (long) semary.sem_nsems); 349 break; 350 } 351 } 352 } 353 354 355 static void do_msg(void) 366 356 { 367 357 int maxid, msqid, id; … … 371 361 struct passwd *pw; 372 362 373 maxid = msgctl 363 maxid = msgctl(0, MSG_INFO, (struct msqid_ds *) (void *) &msginfo); 374 364 if (maxid < 0) { 375 bb_printf ("kernel not configured for message queues\n");365 printf("kernel not configured for %s\n", "message queues"); 376 366 return; 377 367 } … … 379 369 switch (format) { 380 370 case LIMITS: 381 if ((msgctl (0, IPC_INFO, (struct msqid_ds *) (void *) &msginfo)) < 0)371 if ((msgctl(0, IPC_INFO, (struct msqid_ds *) (void *) &msginfo)) < 0) 382 372 return; 383 bb_printf ("------ Messages: Limits --------\n" 384 "max queues system wide = %d\n" 385 "max size of message (bytes) = %d\n" 386 "default max size of queue (bytes) = %d\n", 387 msginfo.msgmni, 388 msginfo.msgmax, 389 msginfo.msgmnb); 373 printf("------ Message%s --------\n", "s: Limits"); 374 printf( "max queues system wide = %d\n" 375 "max size of message (bytes) = %d\n" 376 "default max size of queue (bytes) = %d\n", 377 msginfo.msgmni, msginfo.msgmax, msginfo.msgmnb); 390 378 return; 391 379 392 380 case STATUS: 393 bb_printf ("------ Messages: Status --------\n" 394 "allocated queues = %d\n" 395 "used headers = %d\n" 396 "used space = %d bytes\n", 397 msginfo.msgpool, 398 msginfo.msgmap, 399 msginfo.msgtql); 381 printf("------ Message%s --------\n", "s: Status"); 382 printf( "allocated queues = %d\n" 383 "used headers = %d\n" 384 "used space = %d bytes\n", 385 msginfo.msgpool, msginfo.msgmap, msginfo.msgtql); 400 386 return; 401 387 402 388 case CREATOR: 403 bb_printf ("------ Message Queues: Creators/Owners --------\n"404 405 "msqid","perms","cuid","cgid","uid","gid");389 printf("------ Message%s --------\n", " Queues: Creators/Owners"); 390 printf( "%-10s %-10s %-10s %-10s %-10s %-10s\n", 391 "msqid", "perms", "cuid", "cgid", "uid", "gid"); 406 392 break; 407 393 408 394 case TIME: 409 bb_printf ("------ Message Queues Send/Recv/Change Times --------\n"410 411 "msqid","owner","send","recv","change");395 printf("------ Message%s --------\n", " Queues Send/Recv/Change Times"); 396 printf( "%-8s %-10s %-20s %-20s %-20s\n", 397 "msqid", "owner", "send", "recv", "change"); 412 398 break; 413 399 414 400 case PID: 415 bb_printf ("------ Message Queues PIDs --------\n"416 417 "msqid","owner","lspid","lrpid");401 printf("------ Message%s --------\n", " Queues PIDs"); 402 printf( "%-10s %-10s %-10s %-10s\n", 403 "msqid", "owner", "lspid", "lrpid"); 418 404 break; 419 405 420 406 default: 421 bb_printf ("------ Message Queues --------\n"422 423 "key","msqid","owner","perms","used-bytes","messages");407 printf("------ Message%s --------\n", " Queues"); 408 printf( "%-10s %-10s %-10s %-10s %-12s %-12s\n", 409 "key", "msqid", "owner", "perms", "used-bytes", "messages"); 424 410 break; 425 411 } 426 412 427 413 for (id = 0; id <= maxid; id++) { 428 msqid = msgctl 414 msqid = msgctl(id, MSG_STAT, &msgque); 429 415 if (msqid < 0) 430 416 continue; 431 if (format == CREATOR) 432 print_perms 417 if (format == CREATOR) { 418 print_perms(msqid, ipcp); 433 419 continue; 434 420 } … … 437 423 case TIME: 438 424 if (pw) 439 bb_printf("%-8d %-10.10s", msqid, pw->pw_name);440 else 441 bb_printf("%-8d %-10d", msqid, ipcp->uid);442 bb_printf(" %-20.16s", msgque.msg_stime443 ? ctime(&msgque.msg_stime) + 4 : "Not set");444 bb_printf(" %-20.16s", msgque.msg_rtime445 ? ctime(&msgque.msg_rtime) + 4 : "Not set");446 bb_printf(" %-20.16s\n", msgque.msg_ctime447 ? ctime(&msgque.msg_ctime) + 4 : "Not set");425 printf("%-8d %-10.10s", msqid, pw->pw_name); 426 else 427 printf("%-8d %-10d", msqid, ipcp->uid); 428 printf(" %-20.16s", msgque.msg_stime 429 ? ctime(&msgque.msg_stime) + 4 : "Not set"); 430 printf(" %-20.16s", msgque.msg_rtime 431 ? ctime(&msgque.msg_rtime) + 4 : "Not set"); 432 printf(" %-20.16s\n", msgque.msg_ctime 433 ? ctime(&msgque.msg_ctime) + 4 : "Not set"); 448 434 break; 449 435 case PID: 450 436 if (pw) 451 bb_printf ("%-8d %-10.10s", msqid, pw->pw_name); 452 else 453 bb_printf ("%-8d %-10d", msqid, ipcp->uid); 454 bb_printf (" %5d %5d\n", 455 msgque.msg_lspid, msgque.msg_lrpid); 437 printf("%-8d %-10.10s", msqid, pw->pw_name); 438 else 439 printf("%-8d %-10d", msqid, ipcp->uid); 440 printf(" %5d %5d\n", msgque.msg_lspid, msgque.msg_lrpid); 456 441 break; 457 442 458 443 default: 459 bb_printf( "0x%08x ",ipcp->KEY ); 460 if (pw) 461 bb_printf ("%-10d %-10.10s", msqid, pw->pw_name); 462 else 463 bb_printf ("%-10d %-10d", msqid, ipcp->uid); 464 bb_printf (" %-10o %-12ld %-12ld\n", 465 ipcp->mode & 0777, 466 /* 467 * glibc-2.1.3 and earlier has unsigned short; 468 * glibc-2.1.91 has variation between 469 * unsigned short, unsigned long 470 * Austin has msgqnum_t 471 */ 472 (long) msgque.msg_cbytes, 473 (long) msgque.msg_qnum); 474 break; 475 } 476 } 477 return; 478 } 479 480 481 static void print_shm (int shmid) 444 printf("0x%08x ", ipcp->KEY); 445 if (pw) 446 printf("%-10d %-10.10s", msqid, pw->pw_name); 447 else 448 printf("%-10d %-10d", msqid, ipcp->uid); 449 printf(" %-10o %-12ld %-12ld\n", ipcp->mode & 0777, 450 /* 451 * glibc-2.1.3 and earlier has unsigned short; 452 * glibc-2.1.91 has variation between 453 * unsigned short, unsigned long 454 * Austin has msgqnum_t 455 */ 456 (long) msgque.msg_cbytes, (long) msgque.msg_qnum); 457 break; 458 } 459 } 460 } 461 462 463 static void print_shm(int shmid) 482 464 { 483 465 struct shmid_ds shmds; 484 466 struct ipc_perm *ipcp = &shmds.shm_perm; 485 467 486 if (shmctl (shmid, IPC_STAT, &shmds) == -1) { 487 perror ("shmctl "); 488 return; 489 } 490 491 bb_printf ("\nShared memory Segment shmid=%d\n" 492 "uid=%d\tgid=%d\tcuid=%d\tcgid=%d\n" 493 "mode=%#o\taccess_perms=%#o\n" 494 "bytes=%ld\tlpid=%d\tcpid=%d\tnattch=%ld\n" 495 "att_time=%-26.24s\n" 496 "det_time=%-26.24s\n" 497 "change_time=%-26.24s\n" 498 "\n", 499 shmid, 500 ipcp->uid, ipcp->gid, ipcp->cuid, ipcp->cgid, 501 ipcp->mode, ipcp->mode & 0777, 502 (long) shmds.shm_segsz, shmds.shm_lpid, shmds.shm_cpid, 503 (long) shmds.shm_nattch, 504 shmds.shm_atime ? ctime (&shmds.shm_atime) : "Not set", 505 shmds.shm_dtime ? ctime (&shmds.shm_dtime) : "Not set", 506 ctime (&shmds.shm_ctime)); 507 return; 508 } 509 510 511 static void print_msg (int msqid) 468 if (shmctl(shmid, IPC_STAT, &shmds) == -1) { 469 bb_perror_msg("shmctl"); 470 return; 471 } 472 473 printf("\nShared memory Segment shmid=%d\n" 474 "uid=%d\tgid=%d\tcuid=%d\tcgid=%d\n" 475 "mode=%#o\taccess_perms=%#o\n" 476 "bytes=%ld\tlpid=%d\tcpid=%d\tnattch=%ld\n", 477 shmid, 478 ipcp->uid, ipcp->gid, ipcp->cuid, ipcp->cgid, 479 ipcp->mode, ipcp->mode & 0777, 480 (long) shmds.shm_segsz, shmds.shm_lpid, shmds.shm_cpid, 481 (long) shmds.shm_nattch); 482 printf("att_time=%-26.24s\n", 483 shmds.shm_atime ? ctime(&shmds.shm_atime) : "Not set"); 484 printf("det_time=%-26.24s\n", 485 shmds.shm_dtime ? ctime(&shmds.shm_dtime) : "Not set"); 486 printf("change_time=%-26.24s\n\n", ctime(&shmds.shm_ctime)); 487 } 488 489 490 static void print_msg(int msqid) 512 491 { 513 492 struct msqid_ds buf; 514 493 struct ipc_perm *ipcp = &buf.msg_perm; 515 494 516 if (msgctl (msqid, IPC_STAT, &buf) == -1) { 517 perror ("msgctl "); 518 return; 519 } 520 521 bb_printf ("\nMessage Queue msqid=%d\n" 522 "uid=%d\tgid=%d\tcuid=%d\tcgid=%d\tmode=%#o\n" 523 "cbytes=%ld\tqbytes=%ld\tqnum=%ld\tlspid=%d\tlrpid=%d\n" 524 "send_time=%-26.24s\n" 525 "rcv_time=%-26.24s\n" 526 "change_time=%-26.24s\n" 527 "\n", 528 msqid, 529 ipcp->uid, ipcp->gid, ipcp->cuid, ipcp->cgid, ipcp->mode, 530 /* 531 * glibc-2.1.3 and earlier has unsigned short; 532 * glibc-2.1.91 has variation between 533 * unsigned short, unsigned long 534 * Austin has msgqnum_t (for msg_qbytes) 535 */ 536 (long) buf.msg_cbytes, (long) buf.msg_qbytes, 537 (long) buf.msg_qnum, buf.msg_lspid, buf.msg_lrpid, 538 buf.msg_stime ? ctime (&buf.msg_stime) : "Not set", 539 buf.msg_rtime ? ctime (&buf.msg_rtime) : "Not set", 540 buf.msg_ctime ? ctime (&buf.msg_ctime) : "Not set"); 541 return; 542 } 543 544 static void print_sem (int semid) 495 if (msgctl(msqid, IPC_STAT, &buf) == -1) { 496 bb_perror_msg("msgctl"); 497 return; 498 } 499 500 printf("\nMessage Queue msqid=%d\n" 501 "uid=%d\tgid=%d\tcuid=%d\tcgid=%d\tmode=%#o\n" 502 "cbytes=%ld\tqbytes=%ld\tqnum=%ld\tlspid=%d\tlrpid=%d\n", 503 msqid, ipcp->uid, ipcp->gid, ipcp->cuid, ipcp->cgid, ipcp->mode, 504 /* 505 * glibc-2.1.3 and earlier has unsigned short; 506 * glibc-2.1.91 has variation between 507 * unsigned short, unsigned long 508 * Austin has msgqnum_t (for msg_qbytes) 509 */ 510 (long) buf.msg_cbytes, (long) buf.msg_qbytes, 511 (long) buf.msg_qnum, buf.msg_lspid, buf.msg_lrpid); 512 513 printf("send_time=%-26.24s\n", 514 buf.msg_stime ? ctime(&buf.msg_stime) : "Not set"); 515 printf("rcv_time=%-26.24s\n", 516 buf.msg_rtime ? ctime(&buf.msg_rtime) : "Not set"); 517 printf("change_time=%-26.24s\n\n", 518 buf.msg_ctime ? ctime(&buf.msg_ctime) : "Not set"); 519 } 520 521 static void print_sem(int semid) 545 522 { 546 523 struct semid_ds semds; … … 550 527 551 528 arg.buf = &semds; 552 if (semctl (semid, 0, IPC_STAT, arg) < 0) {553 perror ("semctl");554 return; 555 } 556 557 bb_printf("\nSemaphore Array semid=%d\n"558 "uid=%d\t gid=%d\t cuid=%d\t cgid=%d\n"559 "mode=%#o, access_perms=%#o\n"560 "nsems = %ld\n"561 "otime = %-26.24s\n"562 "ctime = %-26.24s\n"563 "%-10s %-10s %-10s %-10s %-10s\n",564 semid,565 ipcp->uid, ipcp->gid, ipcp->cuid, ipcp->cgid,566 ipcp->mode, ipcp->mode & 0777,567 (long) semds.sem_nsems,568 semds.sem_otime ? ctime (&semds.sem_otime) : "Not set",569 ctime(&semds.sem_ctime),570 "semnum","value","ncount","zcount","pid");529 if (semctl(semid, 0, IPC_STAT, arg)) { 530 bb_perror_msg("semctl"); 531 return; 532 } 533 534 printf("\nSemaphore Array semid=%d\n" 535 "uid=%d\t gid=%d\t cuid=%d\t cgid=%d\n" 536 "mode=%#o, access_perms=%#o\n" 537 "nsems = %ld\n" 538 "otime = %-26.24s\n", 539 semid, 540 ipcp->uid, ipcp->gid, ipcp->cuid, ipcp->cgid, 541 ipcp->mode, ipcp->mode & 0777, 542 (long) semds.sem_nsems, 543 semds.sem_otime ? ctime(&semds.sem_otime) : "Not set"); 544 printf("ctime = %-26.24s\n" 545 "%-10s %-10s %-10s %-10s %-10s\n", 546 ctime(&semds.sem_ctime), 547 "semnum", "value", "ncount", "zcount", "pid"); 571 548 572 549 arg.val = 0; 573 for (i =0; i < semds.sem_nsems; i++) {550 for (i = 0; i < semds.sem_nsems; i++) { 574 551 int val, ncnt, zcnt, pid; 575 val = semctl (semid, i, GETVAL, arg); 576 ncnt = semctl (semid, i, GETNCNT, arg); 577 zcnt = semctl (semid, i, GETZCNT, arg); 578 pid = semctl (semid, i, GETPID, arg); 552 553 val = semctl(semid, i, GETVAL, arg); 554 ncnt = semctl(semid, i, GETNCNT, arg); 555 zcnt = semctl(semid, i, GETZCNT, arg); 556 pid = semctl(semid, i, GETPID, arg); 579 557 if (val < 0 || ncnt < 0 || zcnt < 0 || pid < 0) { 580 perror ("semctl "); 581 bb_fflush_stdout_and_exit (1); 582 } 583 bb_printf ("%-10d %-10d %-10d %-10d %-10d\n", 584 i, val, ncnt, zcnt, pid); 585 } 586 bb_printf ("\n"); 587 return; 588 } 589 590 int ipcs_main (int argc, char **argv) { 591 int opt, msg = 0, sem = 0, shm = 0, id=0, print=0; 592 char format = 0; 593 char options[] = "atclupsmqi:ih?"; 594 595 while ((opt = getopt (argc, argv, options)) != -1) { 596 switch (opt) { 597 case 'i': 598 id = atoi (optarg); 599 print = 1; 600 break; 601 case 'a': 602 msg = shm = sem = 1; 603 break; 604 case 'q': 605 msg = 1; 606 break; 607 case 's': 608 sem = 1; 609 break; 610 case 'm': 611 shm = 1; 612 break; 613 case 't': 614 format = TIME; 615 break; 616 case 'c': 617 format = CREATOR; 618 break; 619 case 'p': 620 format = PID; 621 break; 622 case 'l': 623 format = LIMITS; 624 break; 625 case 'u': 626 format = STATUS; 627 break; 628 case 'h': 629 case '?': 630 bb_show_usage(); 631 bb_fflush_stdout_and_exit (0); 632 } 633 } 634 635 if (print) { 636 if (shm) { 637 print_shm (id); 638 bb_fflush_stdout_and_exit (0); 639 } 640 if (sem) { 641 print_sem (id); 642 bb_fflush_stdout_and_exit (0); 643 } 644 if (msg) { 645 print_msg (id); 646 bb_fflush_stdout_and_exit (0); 558 bb_perror_msg_and_die("semctl"); 559 } 560 printf("%-10d %-10d %-10d %-10d %-10d\n", i, val, ncnt, zcnt, pid); 561 } 562 puts(""); 563 } 564 565 int ipcs_main(int argc, char **argv); 566 int ipcs_main(int argc, char **argv) 567 { 568 int id = 0; 569 unsigned flags = 0; 570 unsigned opt; 571 char *opt_i; 572 #define flag_print (1<<0) 573 #define flag_msg (1<<1) 574 #define flag_sem (1<<2) 575 #define flag_shm (1<<3) 576 577 opt = getopt32(argv, "i:aqsmtcplu", &opt_i); 578 if (opt & 0x1) { // -i 579 id = xatoi(opt_i); 580 flags |= flag_print; 581 } 582 if (opt & 0x2) flags |= flag_msg | flag_sem | flag_shm; // -a 583 if (opt & 0x4) flags |= flag_msg; // -q 584 if (opt & 0x8) flags |= flag_sem; // -s 585 if (opt & 0x10) flags |= flag_shm; // -m 586 if (opt & 0x20) format = TIME; // -t 587 if (opt & 0x40) format = CREATOR; // -c 588 if (opt & 0x80) format = PID; // -p 589 if (opt & 0x100) format = LIMITS; // -l 590 if (opt & 0x200) format = STATUS; // -u 591 592 if (flags & flag_print) { 593 if (flags & flag_shm) { 594 print_shm(id); 595 fflush_stdout_and_exit(0); 596 } 597 if (flags & flag_sem) { 598 print_sem(id); 599 fflush_stdout_and_exit(0); 600 } 601 if (flags & flag_msg) { 602 print_msg(id); 603 fflush_stdout_and_exit(0); 647 604 } 648 605 bb_show_usage(); 649 bb_fflush_stdout_and_exit (0); 650 } 651 652 if ( !shm && !msg && !sem) 653 msg = sem = shm = 1; 654 bb_printf ("\n"); 655 656 if (shm) { 657 do_shm (format); 658 bb_printf ("\n"); 659 } 660 if (sem) { 661 do_sem (format); 662 bb_printf ("\n"); 663 } 664 if (msg) { 665 do_msg (format); 666 bb_printf ("\n"); 667 } 668 return 0; 669 } 670 606 } 607 608 if (!(flags & (flag_shm | flag_msg | flag_sem))) 609 flags |= flag_msg | flag_shm | flag_sem; 610 puts(""); 611 612 if (flags & flag_shm) { 613 do_shm(); 614 puts(""); 615 } 616 if (flags & flag_sem) { 617 do_sem(); 618 puts(""); 619 } 620 if (flags & flag_msg) { 621 do_msg(); 622 puts(""); 623 } 624 fflush_stdout_and_exit(0); 625 }
Note:
See TracChangeset
for help on using the changeset viewer.