|
|
1.1 ! root 1: /* ! 2: * Print out received ipc data corresponding to print optoins. ! 3: */ ! 4: #include <stdio.h> ! 5: #include <pwd.h> ! 6: #include <grp.h> ! 7: #include <time.h> ! 8: #include "ipcs.h" ! 9: ! 10: struct group *grp; ! 11: struct passwd *pstp; ! 12: ! 13: struct msqid_ds *msqbuf; /* message queue data */ ! 14: /* ! 15: * Print information about active message queues ! 16: */ ! 17: print_q() ! 18: { ! 19: int x; /* counter */ ! 20: char date[30]; /* date string */ ! 21: ! 22: printf("MESSAGE QUEUES:\n"); ! 23: ! 24: /* Check if msq is in use */ ! 25: for (x = 0 ; x < NMSQID; x++) ! 26: if (msqbuf[x].msg_perm.mode & IPC_ALLOC) ! 27: break; ! 28: if (x >= NMSQID) ! 29: return; ! 30: ! 31: printf("T ID KEY MODE OWNER GROUP"); ! 32: ! 33: if (cflag) ! 34: printf(" CREATOR CGROUP"); ! 35: ! 36: if (oflag) ! 37: printf(" CBYTES QNUM"); ! 38: ! 39: if (bflag) ! 40: fputs(" QBYTES", stdout); ! 41: ! 42: if (pflag) ! 43: fputs(" LSPID LRPID", stdout); ! 44: ! 45: if (tflag) ! 46: fputs(" STIME RTIME CTIME ", stdout); ! 47: ! 48: puts(""); ! 49: ! 50: for (x = 0 ; x < NMSQID; x++) { ! 51: if (!(msqbuf[x].msg_perm.mode & IPC_ALLOC)) ! 52: continue; ! 53: /* id, mode & key */ ! 54: printf("q%4d%12d", msqbuf[x].msg_perm.seq, ! 55: msqbuf[x].msg_perm.key); ! 56: ! 57: if (msqbuf[x].msg_perm.mode & MSG_RWAIT) { ! 58: printf(" R"); /* pid waiting for msgrcv() */ ! 59: } else { ! 60: if (msqbuf[x].msg_perm.mode & MSG_WWAIT) { ! 61: printf(" S"); /* waiting for msgsnd() */ ! 62: } else { ! 63: printf(" -"); /* no flag set */ ! 64: } ! 65: } ! 66: printf("0%o", msqbuf[x].msg_perm.mode&0777); ! 67: /* get owner's name from /etc/passwd */ ! 68: if ((pstp = getpwuid(msqbuf[x].msg_perm.uid)) == NULL) { ! 69: perror("ipcs: cannot get owner name:"); ! 70: exit(1); ! 71: } ! 72: printf("%7s", pstp->pw_name); ! 73: ! 74: /* get group name of owner */ ! 75: if ((grp = getgrgid(msqbuf[x].msg_perm.gid)) == NULL) { ! 76: perror("ipcs: cannot get group name"); ! 77: exit(1); ! 78: } ! 79: printf("%7s", grp->gr_name); ! 80: ! 81: if (cflag) { ! 82: /* get creator's name from /etc/passwd */ ! 83: if ((pstp = getpwuid(msqbuf[x].msg_perm.cuid)) == NULL){ ! 84: perror("ipcs: cannot get creator name"); ! 85: exit(1); ! 86: } ! 87: printf("%8s", pstp->pw_name); ! 88: ! 89: /* get group name of creator */ ! 90: if ((grp = getgrgid(msqbuf[x].msg_perm.cgid)) == NULL){ ! 91: perror("ipcs: cannot get creator group"); ! 92: exit(1); ! 93: } ! 94: printf("%7s",grp->gr_name); ! 95: } ! 96: ! 97: /* current bytes & # of messages */ ! 98: if (oflag) ! 99: printf("%7d%5d", msqbuf[x].msg_cbytes, ! 100: msqbuf[x].msg_qnum); ! 101: ! 102: /* max # bytes on queue */ ! 103: if (bflag) ! 104: printf("%7d",msqbuf[x].msg_qbytes); ! 105: ! 106: /* last send & receive processes */ ! 107: if (pflag) ! 108: printf("%6d%6d", msqbuf[x].msg_lspid, ! 109: msqbuf[x].msg_lrpid); ! 110: ! 111: /* times of last send and receive and modification*/ ! 112: if (tflag) { ! 113: sprintf(date,"%s", ctime(&msqbuf[x].msg_stime)); ! 114: printf(" %.8s",date + 11); ! 115: sprintf(date,"%8s", ctime(&msqbuf[x].msg_rtime)); ! 116: printf(" %.8s",date + 11); ! 117: sprintf(date,"%s", ctime(&msqbuf[x].msg_ctime)); ! 118: printf(" %.8s",date + 11); ! 119: } ! 120: printf("\n"); ! 121: } ! 122: printf("\n"); ! 123: } ! 124: ! 125: /* ! 126: * Print information about active shared memory segments ! 127: */ ! 128: print_m() ! 129: { ! 130: int x; /* counter for print loop */ ! 131: char date[30]; /* used to hold the date string */ ! 132: ! 133: printf("SHARED MEMORY:\n"); ! 134: ! 135: if (!total_shmids) ! 136: return; ! 137: printf("T ID KEY MODE OWNER GROUP"); ! 138: if (cflag) ! 139: printf(" CREATOR CGROUP"); ! 140: ! 141: if (oflag) ! 142: printf(" NATTCH"); ! 143: ! 144: if (bflag) ! 145: printf(" SEGSZ"); ! 146: if (pflag) ! 147: printf(" CPID LPID"); ! 148: ! 149: if (tflag) ! 150: printf(" ATIME DTIME CTIME"); ! 151: ! 152: printf("\n"); ! 153: ! 154: ! 155: for (x = SHMMNI - 1; x >= 0 ; x--) { ! 156: if (!valid_shmid[x]) ! 157: continue; ! 158: /* id, mode & key */ ! 159: printf("m%4d%12d 0%o", x, shmid[x].shm_perm.key, ! 160: shmid[x].shm_perm.mode & 0777); ! 161: /* get owner's name from /etc/passwd */ ! 162: if ((pstp = getpwuid(shmid[x].shm_perm.uid)) == NULL) { ! 163: perror("ipcs: cannot get owner name"); ! 164: exit(1); ! 165: } ! 166: printf("%7s",pstp->pw_name); ! 167: ! 168: /* get group name of owner */ ! 169: ! 170: if ((grp = getgrgid(shmid[x].shm_perm.gid)) == NULL) { ! 171: perror("ipcs: cannot get owner group"); ! 172: exit(1); ! 173: } ! 174: printf("%7s",grp->gr_name); ! 175: ! 176: if (cflag) { ! 177: /* get creator's name from /etc/passwd */ ! 178: if ((pstp = getpwuid(shmid[x].shm_perm.cuid)) == NULL) { ! 179: perror("ipcs: cannot get creator name"); ! 180: exit(1); ! 181: } ! 182: printf("%8s",pstp->pw_name); ! 183: ! 184: /* get group name of creator */ ! 185: if ((grp = getgrgid(shmid[x].shm_perm.cgid)) == NULL) { ! 186: perror("ipcs: cannot get creator group"); ! 187: exit(1); ! 188: } ! 189: printf("%7s",grp->gr_name); ! 190: } ! 191: ! 192: if (oflag) { /* attached segments */ ! 193: printf("%7d", shmid[x].shm_nattch); ! 194: } ! 195: ! 196: if (bflag) { /* segment size */ ! 197: printf("%6d",shmid[x].shm_segsz); ! 198: } ! 199: ! 200: if (pflag) /* processs id of last op */ ! 201: printf("%6d%5d", shmid[x].shm_cpid, ! 202: shmid[x].shm_lpid); ! 203: /* Time */ ! 204: if (tflag) { ! 205: /* attach time */ ! 206: if (!shmid[x].shm_atime) ! 207: printf(" no-entry "); ! 208: else { ! 209: sprintf(date,"%s", ctime(&shmid[x].shm_atime)); ! 210: printf(" %.8s", date + 11); ! 211: } ! 212: /* detach time */ ! 213: if (!shmid[x].shm_dtime) ! 214: printf(" no-entry"); ! 215: else { ! 216: sprintf(date,"%s", ctime(&shmid[x].shm_dtime)); ! 217: printf(" %.8s", date + 11); ! 218: } ! 219: /* creat time */ ! 220: sprintf(date,"%s", ctime(&shmid[x].shm_ctime)); ! 221: printf(" %.8s", date + 11); ! 222: } ! 223: printf("\n"); ! 224: } ! 225: printf("\n"); ! 226: } ! 227: ! 228: /* ! 229: * Print information about active semaphores ! 230: */ ! 231: print_s() ! 232: { ! 233: int x; /* loop counter */ ! 234: char date[30]; /* holds our date string */ ! 235: ! 236: printf("SEMAPHORES:\n"); ! 237: ! 238: if (!total_sems) ! 239: return; ! 240: ! 241: printf("T ID KEY MODE OWNER GROUP"); ! 242: if (cflag) { ! 243: printf(" CREATOR CGROUP"); ! 244: } ! 245: ! 246: if (bflag) { ! 247: printf(" NSEMS"); ! 248: } ! 249: ! 250: if (tflag) { ! 251: printf(" OTIME CTIME"); ! 252: } ! 253: printf("\n"); ! 254: ! 255: for (x = 0; x < SEMMNI; x++) { ! 256: if (!valid_semid[x]) ! 257: continue; ! 258: ! 259: printf("s%4d%12d 0%o",x, /* mode and key */ ! 260: semid[x].sem_perm.key, ! 261: semid[x].sem_perm.mode & 0777); ! 262: ! 263: /* get owner's name from /etc/passwd */ ! 264: if((pstp = getpwuid(semid[x].sem_perm.uid)) == NULL){ ! 265: printf("Error reading password file!\n"); ! 266: exit(1); ! 267: } ! 268: printf("%7s",pstp->pw_name); ! 269: ! 270: /* get group name of owner */ ! 271: ! 272: if((grp = getgrgid(semid[x].sem_perm.gid)) == NULL){ ! 273: printf("Error reading group file!\n"); ! 274: exit(1); ! 275: } ! 276: printf("%7s",grp->gr_name); ! 277: ! 278: if (cflag) { ! 279: /* get creator's name from /etc/passwd */ ! 280: if((pstp = getpwuid(semid[x].sem_perm.cuid)) == NULL){ ! 281: printf("Error reading password file!\n"); ! 282: exit(1); ! 283: } ! 284: printf("%8s",pstp->pw_name); ! 285: ! 286: /* get group name of creator */ ! 287: if((grp = getgrgid(semid[x].sem_perm.cgid)) == NULL){ ! 288: printf("Error reading group file!\n"); ! 289: exit(1); ! 290: } ! 291: printf("%7s",grp->gr_name); ! 292: } ! 293: ! 294: if (bflag) { /* number of semaphore elements */ ! 295: printf("%6d",semid[x].sem_nsems); ! 296: } ! 297: ! 298: if (tflag) { /* time */ ! 299: if (semid[x].sem_otime) {/* semop time */ ! 300: sprintf(date,"%s", ctime(&semid[x].sem_otime)); ! 301: printf(" %.8s",date + 11); ! 302: } else ! 303: printf(" no-entry"); ! 304: if (semid[x].sem_ctime) { /* Change time */ ! 305: sprintf(date,"%s", ctime(&semid[x].sem_ctime)); ! 306: printf(" %.8s",date + 11); ! 307: } else ! 308: printf(" no-entry"); ! 309: } ! 310: printf("\n"); ! 311: } ! 312: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.