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 <memory.h>
0039 #include <utlist.h>
0040
0041 #include <ndrstandard.h>
0042
0043 #include <ndebug.h>
0044 #include <userlog.h>
0045 #include <ndrxd.h>
0046 #include <ndrxdcmn.h>
0047
0048 #include "cmd_processor.h"
0049 #include <atmi_shm.h>
0050
0051
0052 #define OFSZ(s,e) EXOFFSET(s,e), EXELEM_SIZE(s,e)
0053
0054
0055
0056
0057
0058
0059
0060 static ndrx_args_loader_t M_appcfg_map[] =
0061 {
0062 {OFSZ(config_t,sanity), "sanity", NDRX_ARGS_INT, 0, 0, 0, INT_MAX},
0063 {OFSZ(config_t,checkpm), "checkpm", NDRX_ARGS_INT, 0, 0, 0, INT_MAX},
0064 {OFSZ(config_t,brrefresh), "brrefresh", NDRX_ARGS_INT, 0, 0, 0, INT_MAX},
0065 {OFSZ(config_t,restart_min), "restart_min", NDRX_ARGS_INT, 0, 0, 0, INT_MAX},
0066 {OFSZ(config_t,restart_step), "restart_step", NDRX_ARGS_INT, 0, 0, 0, INT_MAX},
0067 {OFSZ(config_t,restart_max), "restart_max", NDRX_ARGS_INT, 0, 0, 0, INT_MAX},
0068 {OFSZ(config_t,restart_to_check),"restart_to_check",NDRX_ARGS_INT, 0, 0, 0, INT_MAX},
0069 {OFSZ(config_t,gather_pq_stats), "gather_pq_stats", NDRX_ARGS_BOOL, 0, 0, 0, 0},
0070 {OFSZ(config_t,rqaddrttl), "rqaddrttl", NDRX_ARGS_INT, 0, 0, 0, INT_MAX},
0071 {EXFAIL}
0072 };
0073
0074
0075
0076
0077
0078
0079
0080
0081 expublic void appconfig_reply_mod(command_reply_t *reply, size_t *send_size,
0082 mod_param_t *params)
0083 {
0084 command_reply_appconfig_t * rply = (command_reply_appconfig_t *)reply;
0085 command_appconfig_t *req = (command_appconfig_t *)params->mod_param1;
0086
0087 reply->msg_type = NDRXD_CALL_TYPE_APPCONFIG;
0088
0089 *send_size += (sizeof(command_reply_appconfig_t) - sizeof(command_reply_t));
0090
0091
0092 NDRX_STRCPY_SAFE(rply->setting, req->setting);
0093
0094
0095 NDRX_STRCPY_SAFE(rply->svalue, req->svalue);
0096
0097 NDRX_LOG(log_debug, "magic: %ld", rply->rply.magic);
0098 }
0099
0100
0101
0102
0103
0104
0105
0106 expublic int cmd_appconfig (command_call_t * call, char *data, size_t len,
0107 int context)
0108 {
0109 int ret=EXSUCCEED;
0110 command_appconfig_t *cfg = (command_appconfig_t *)call;
0111 mod_param_t params;
0112
0113
0114
0115
0116
0117 char *errbuf;
0118 int *error_code;
0119 int errbufsz;
0120
0121 memset(¶ms, 0, sizeof(mod_param_t));
0122 params.mod_param1 = (void *)call;
0123
0124 errbuf = NDRXD_error_res_get(&error_code, &errbufsz);
0125
0126
0127
0128
0129
0130
0131 if (NULL==G_app_config)
0132 {
0133 NDRXD_set_error_msg(NDRXD_ECFGLDED, "App config not loaded - idle instance");
0134 }
0135 else if (EXEOS!=cfg->svalue[0])
0136 {
0137 if (EXSUCCEED!=ndrx_args_loader_set(M_appcfg_map, G_app_config,
0138 cfg->setting, cfg->svalue, errbuf, errbufsz))
0139 {
0140 *error_code = NDRXD_EINVAL;
0141 NDRX_LOG(log_error, "Failed to apply [%s] setting", cfg->setting);
0142 }
0143 }
0144 else
0145 {
0146 if (EXSUCCEED!=ndrx_args_loader_get(M_appcfg_map, G_app_config,
0147 cfg->setting, cfg->svalue, sizeof(cfg->svalue), errbuf, errbufsz))
0148 {
0149 *error_code = NDRXD_EINVAL;
0150 NDRX_LOG(log_error, "Failed to get [%s] setting", cfg->setting);
0151 }
0152 }
0153
0154 if (EXSUCCEED!=simple_command_reply(call, ret, 0L, ¶ms, appconfig_reply_mod,
0155 0L, 0, NULL))
0156 {
0157 userlog("Failed to send reply back to [%s]", call->reply_queue);
0158 }
0159
0160 out:
0161 NDRX_LOG(log_warn, "cmd_appconfig returns with status %d", ret);
0162 return ret;
0163 }
0164
0165