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
0035 #include <string.h>
0036 #include <stdio.h>
0037 #include <stdlib.h>
0038 #include <errno.h>
0039 #include <memory.h>
0040 #include <sys/types.h>
0041 #include <sys/stat.h>
0042 #include <ndrstandard.h>
0043 #include <ndebug.h>
0044
0045 #include <ndrx.h>
0046 #include <ndrxdcmn.h>
0047 #include <atmi_int.h>
0048 #include <gencall.h>
0049
0050 #include <nstopwatch.h>
0051 #include <nclopt.h>
0052 #include <sys_unix.h>
0053 #include <utlist.h>
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069 expublic int cmd_svqids(cmd_mapping_t *p_cmd_map, int argc, char **argv, int *p_have_next)
0070 {
0071 int ret=EXSUCCEED;
0072 ndrx_growlist_t list;
0073 int i;
0074 mdrx_sysv_res_t *p_res;
0075 int print_ids=EXFALSE;
0076 int print_keys=EXFALSE;
0077
0078 ncloptmap_t clopt[] =
0079 {
0080 {'i', BFLD_INT, (void *)&print_ids, sizeof(print_ids),
0081 NCLOPT_OPT|NCLOPT_TRUEBOOL, "Print IDs only"},
0082 {'k', BFLD_INT, (void *)&print_keys, sizeof(print_keys),
0083 NCLOPT_OPT|NCLOPT_TRUEBOOL, "Print Keys only"},
0084 {0}
0085 };
0086
0087 memset(&list, 0, sizeof(list));
0088
0089
0090 if (nstd_parse_clopt(clopt, EXTRUE, argc, argv, EXFALSE))
0091 {
0092 fprintf(stderr, XADMIN_INVALID_OPTIONS_MSG);
0093 EXFAIL_OUT(ret);
0094 }
0095
0096 if (EXSUCCEED!=ndrx_sys_sysv_user_res(&list, NDRX_SV_RESTYPE_QUE))
0097 {
0098 fprintf(stderr, "Failed to list System V queues\n");
0099 NDRX_LOG(log_error, "Failed to list System V queues");
0100 EXFAIL_OUT(ret);
0101 }
0102
0103 if (print_ids)
0104 {
0105 fprintf(stderr, " QUEUE ID\n");
0106 fprintf(stderr, "------------\n");
0107 }
0108 else if (print_keys)
0109 {
0110 fprintf(stderr, " IPC KEY\n");
0111 fprintf(stderr, "----------\n");
0112 }
0113 else
0114 {
0115 fprintf(stderr, " QUEUE ID IPC KEY\n");
0116 fprintf(stderr, "------------ ----------\n");
0117 }
0118
0119 p_res = (mdrx_sysv_res_t *)list.mem;
0120
0121 for (i=0; i<=list.maxindexused; i++)
0122 {
0123 if (print_ids)
0124 {
0125 fprintf(stdout, "%12u\n", p_res[i].id);
0126 }
0127 else if (print_keys)
0128 {
0129 fprintf(stdout, "0x%08x\n", p_res[i].key);
0130 }
0131 else
0132 {
0133 fprintf(stdout, "%12u 0x%08x\n", p_res[i].id, p_res[i].key);
0134 }
0135 }
0136
0137 out:
0138 ndrx_growlist_free(&list);
0139
0140 return ret;
0141 }
0142
0143
0144
0145
0146
0147
0148
0149
0150 expublic int cmd_svsemids(cmd_mapping_t *p_cmd_map, int argc, char **argv, int *p_have_next)
0151 {
0152 int ret=EXSUCCEED;
0153 ndrx_growlist_t list;
0154 int i;
0155 mdrx_sysv_res_t *p_res;
0156 int print_ids=EXFALSE;
0157 int print_keys=EXFALSE;
0158
0159 ncloptmap_t clopt[] =
0160 {
0161 {'i', BFLD_INT, (void *)&print_ids, sizeof(print_ids),
0162 NCLOPT_OPT|NCLOPT_TRUEBOOL, "Print IDs only"},
0163 {'k', BFLD_INT, (void *)&print_keys, sizeof(print_keys),
0164 NCLOPT_OPT|NCLOPT_TRUEBOOL, "Print Keys only"},
0165 {0}
0166 };
0167
0168 memset(&list, 0, sizeof(list));
0169
0170
0171 if (nstd_parse_clopt(clopt, EXTRUE, argc, argv, EXFALSE))
0172 {
0173 fprintf(stderr, XADMIN_INVALID_OPTIONS_MSG);
0174 EXFAIL_OUT(ret);
0175 }
0176
0177 if (EXSUCCEED!=ndrx_sys_sysv_user_res(&list, NDRX_SV_RESTYPE_SEM))
0178 {
0179 fprintf(stderr, "Failed to list System V semaphores\n");
0180 NDRX_LOG(log_error, "Failed to list System V Semaphores");
0181 EXFAIL_OUT(ret);
0182 }
0183
0184 if (print_ids)
0185 {
0186 fprintf(stderr, "SEMAPHORE ID\n");
0187 fprintf(stderr, "------------\n");
0188 }
0189 else if (print_keys)
0190 {
0191 fprintf(stderr, " IPC KEY\n");
0192 fprintf(stderr, "----------\n");
0193 }
0194 else
0195 {
0196 fprintf(stderr, "SEMAPHORE ID IPC KEY\n");
0197 fprintf(stderr, "------------ ----------\n");
0198 }
0199
0200 p_res = (mdrx_sysv_res_t *)list.mem;
0201
0202 for (i=0; i<=list.maxindexused; i++)
0203 {
0204 if (print_ids)
0205 {
0206 fprintf(stdout, "%12u\n", p_res[i].id);
0207 }
0208 else if (print_keys)
0209 {
0210 fprintf(stdout, "0x%08x\n", p_res[i].key);
0211 }
0212 else
0213 {
0214 fprintf(stdout, "%12u 0x%08x\n", p_res[i].id, p_res[i].key);
0215 }
0216 }
0217
0218 out:
0219 ndrx_growlist_free(&list);
0220
0221 return ret;
0222 }
0223
0224