0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034 #include <string.h>
0035 #include <stdio.h>
0036 #include <stdlib.h>
0037 #include <errno.h>
0038 #include <memory.h>
0039 #include <sys/types.h>
0040 #include <sys/stat.h>
0041 #include <ndrstandard.h>
0042 #include <ndebug.h>
0043
0044 #include <ndrx.h>
0045 #include <ndrxdcmn.h>
0046 #include <atmi_int.h>
0047 #include <gencall.h>
0048
0049 #include <nstopwatch.h>
0050 #include <nclopt.h>
0051 #include <sys_unix.h>
0052 #include <utlist.h>
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066 exprivate void print_hdr(void)
0067 {
0068 fprintf(stderr, " SLOT MSGID FLAGS CTIME Q NAME\n");
0069 fprintf(stderr, "------ ---------- ----------------- -------- -----------------------------------\n");
0070 }
0071
0072
0073
0074
0075
0076
0077
0078
0079 expublic int cmd_svmaps(cmd_mapping_t *p_cmd_map, int argc, char **argv, int *p_have_next)
0080 {
0081 int ret=EXSUCCEED;
0082 short print_systemv = EXFALSE;
0083 short print_posix = EXFALSE;
0084 short print_all = EXFALSE;
0085 short print_isused = EXFALSE;
0086 short print_wasused = EXFALSE;
0087 int attach_status = EXFALSE;
0088 ndrx_shm_t *map_p2s;
0089 ndrx_shm_t *map_s2p;
0090 ndrx_sem_t *map_sem;
0091 int i, queuesmax;
0092 ndrx_svq_map_t *el;
0093 ndrx_shm_t *map;
0094 char flagsstr[128];
0095 int total = 0;
0096 ncloptmap_t clopt[] =
0097 {
0098 {'p', BFLD_SHORT, (void *)&print_posix, 0,
0099 NCLOPT_OPT | NCLOPT_TRUEBOOL,
0100 "Posix -> System V mapping table (default)"},
0101 {'s', BFLD_SHORT, (void *)&print_systemv, 0,
0102 NCLOPT_OPT | NCLOPT_TRUEBOOL,
0103 "Print System V -> Posix mapping table"},
0104 {'a', BFLD_SHORT, (void *)&print_all, 0,
0105 NCLOPT_OPT | NCLOPT_TRUEBOOL,
0106 "Print all entries"},
0107 {'i', BFLD_SHORT, (void *)&print_isused, 0,
0108 NCLOPT_OPT | NCLOPT_TRUEBOOL,
0109 "Print entries in use"},
0110 {'w', BFLD_SHORT, (void *)&print_wasused, 0,
0111 NCLOPT_OPT | NCLOPT_TRUEBOOL,
0112 "Print entries which was used"},
0113 {0}
0114 };
0115
0116
0117 if (nstd_parse_clopt(clopt, EXTRUE, argc, argv, EXFALSE))
0118 {
0119 fprintf(stderr, XADMIN_INVALID_OPTIONS_MSG);
0120 EXFAIL_OUT(ret);
0121 }
0122
0123 if (!print_isused && !print_wasused && !print_all)
0124 {
0125 print_isused = EXTRUE;
0126 }
0127
0128 if (EXFAIL==(attach_status = ndrx_svqshm_attach()))
0129 {
0130 fprintf(stderr, "* System V shared resources does not exists\n");
0131 NDRX_LOG(log_error, "System V shared resources does not exists");
0132 EXFAIL_OUT(ret);
0133 }
0134
0135 if (!ndrx_svqshm_shmres_get(&map_p2s, &map_s2p, &map_sem, &queuesmax))
0136 {
0137 fprintf(stderr, "System malfunction, System V SHM must be open!\n");
0138 NDRX_LOG(log_error, "System malfunction, System V SHM must be open");
0139 userlog("System malfunction, System V SHM must be open");
0140 EXFAIL_OUT(ret);
0141 }
0142
0143
0144 print_hdr();
0145
0146
0147
0148
0149 map = map_p2s;
0150
0151 if (print_systemv)
0152 {
0153 map = map_s2p;
0154 }
0155
0156
0157
0158 if (EXSUCCEED!=ndrx_sem_rwlock(map_sem, 0, NDRX_SEM_TYP_READ))
0159 {
0160 goto out;
0161 }
0162
0163 for (i=0; i<queuesmax; i++)
0164 {
0165 el = NDRX_SVQ_INDEX(map->mem, i);
0166
0167 if (print_all ||
0168 (print_isused && (el->flags & NDRX_SVQ_MAP_ISUSED)) ||
0169
0170 (print_wasused && (el->flags & NDRX_SVQ_MAP_WASUSED) &&
0171 !(el->flags & NDRX_SVQ_MAP_ISUSED))
0172
0173 )
0174 {
0175 flagsstr[0]=EXEOS;
0176
0177 if (el->flags & NDRX_SVQ_MAP_ISUSED)
0178 {
0179 if (EXEOS!=flagsstr[0])
0180 {
0181 strcat(flagsstr, ",");
0182 }
0183 strcat(flagsstr, "iuse");
0184 }
0185 else if (el->flags & NDRX_SVQ_MAP_WASUSED)
0186 {
0187 if (EXEOS!=flagsstr[0])
0188 {
0189 strcat(flagsstr, ",");
0190 }
0191 strcat(flagsstr, "wuse");
0192 }
0193
0194 if (el->flags & NDRX_SVQ_MAP_RQADDR)
0195 {
0196 if (EXEOS!=flagsstr[0])
0197 {
0198 strcat(flagsstr, ",");
0199 }
0200 strcat(flagsstr, "rqaddr");
0201 }
0202
0203 fprintf(stdout, "%6d %10d %-17.17s %8.8s %s\n",
0204 i, el->qid, flagsstr,
0205 ndrx_decode_msec(ndrx_stopwatch_get_delta(&el->ctime), 0, 0, 2),
0206 el->qstr);
0207 total++;
0208 }
0209 }
0210
0211
0212 ndrx_sem_rwunlock(map_sem, 0, NDRX_SEM_TYP_READ);
0213
0214
0215 fprintf(stderr, "\nTOTAL: %d\n", total);
0216
0217
0218 out:
0219
0220
0221
0222
0223 if (EXTRUE==attach_status)
0224 {
0225 ndrx_svqshm_detach();
0226 }
0227
0228 return ret;
0229 }
0230