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 <memory.h>
0038
0039
0040 #include <ndrstandard.h>
0041 #include <ndebug.h>
0042 #include <userlog.h>
0043 #include <ndrxd.h>
0044 #include <ndrxdcmn.h>
0045 #include <atmi_shm.h>
0046
0047 #include <bridge_int.h>
0048
0049 #include "cmd_processor.h"
0050 #include "utlist.h"
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064 exprivate void start_start_info(pm_node_t * p_pm, srv_status_t * srvinfo)
0065 {
0066 NDRX_STRCPY_SAFE(p_pm->binary_name_real,
0067 srvinfo->srvinfo.binary_name_real);
0068
0069 NDRX_STRCPY_SAFE(p_pm->rqaddress, srvinfo->srvinfo.rqaddress);
0070 p_pm->resid = srvinfo->srvinfo.resid;
0071 p_pm->svpid = srvinfo->srvinfo.svpid;
0072
0073 p_pm->state = srvinfo->srvinfo.state;
0074 p_pm->state_changed = SANITY_CNT_START;
0075
0076 p_pm->pingtimer = SANITY_CNT_START;
0077 p_pm->rspstwatch = SANITY_CNT_START;
0078 p_pm->pingstwatch = SANITY_CNT_IDLE;
0079 p_pm->killreq = EXFALSE;
0080 p_pm->exec_seq_try = 0;
0081 p_pm->flags = srvinfo->srvinfo.flags;
0082 p_pm->nodeid = srvinfo->srvinfo.nodeid;
0083 p_pm->procgrp_lp_no = srvinfo->srvinfo.procgrp_lp_no;
0084 }
0085
0086
0087
0088
0089
0090
0091 expublic int cmd_srvinfo (command_call_t * call, char *data, size_t len, int context)
0092 {
0093 int ret=EXSUCCEED;
0094 srv_status_t * srvinfo = (srv_status_t *)call;
0095 pm_node_t * p_pm;
0096 pm_node_t * p_pm_chk;
0097 pm_pidhash_t *pm_pid;
0098 int i;
0099 int srvid;
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109 NDRX_LOG(log_debug, "Call from server: %d, state: %d rqaddr: [%s]",
0110 srvinfo->srvinfo.srvid, srvinfo->srvinfo.state,
0111 srvinfo->srvinfo.rqaddress);
0112
0113 srvid=srvinfo->srvinfo.srvid;
0114 if (srvid>=0 && srvid<ndrx_get_G_atmi_env()->max_servers
0115
0116
0117
0118
0119
0120 && NULL!=G_process_model_hash)
0121 {
0122 p_pm = G_process_model_hash[srvid];
0123 }
0124 else
0125 {
0126 NDRX_LOG(log_error, "Corrupted server id: %d - ignore request",
0127 srvid);
0128 goto out;
0129 }
0130
0131 if (NULL==p_pm)
0132 {
0133 NDRX_LOG(log_error, "Unknown server id %d - ignore request!",
0134 srvinfo->srvinfo.srvid);
0135 goto out;
0136 }
0137
0138
0139
0140
0141
0142
0143
0144
0145 pm_pid =pid_hash_get(G_process_model_pid_hash, srvinfo->srvinfo.pid);
0146
0147 if (NULL!=pm_pid)
0148 {
0149 p_pm_chk = pm_pid->p_pm;
0150 if (srvinfo->srvinfo.srvid!=p_pm_chk->srvid)
0151 {
0152 NDRX_LOG(log_error, "Got message from pid=%d, srvid=%d but not "
0153 "match for server id %d for same PID in system!!!",
0154 srvinfo->srvinfo.pid, srvinfo->srvinfo.srvid,
0155 p_pm_chk->srvid);
0156 goto out;
0157 }
0158
0159
0160 if (NDRXD_PM_STARTING == p_pm_chk->state)
0161 {
0162 NDRX_LOG(log_warn, "Binary was starting up, updating status");
0163 start_start_info(p_pm, srvinfo);
0164 }
0165 else if (NDRXD_PM_RUNNING_OK == p_pm_chk->state)
0166 {
0167 NDRX_LOG(log_warn, "Existing server already runs OK "
0168 "this is some mistake!");
0169
0170 goto out;
0171 }
0172 else
0173 {
0174 start_start_info(p_pm, srvinfo);
0175
0176
0177
0178
0179
0180
0181
0182
0183
0184
0185
0186 if (p_pm->pid != srvinfo->srvinfo.pid)
0187 {
0188 NDRX_LOG(log_warn, "We assume that this PID is good "
0189 "one & will remove old one!");
0190
0191 remove_startfail_process(p_pm_chk, NULL, NULL);
0192
0193
0194 ndrxd_shm_resetsrv(p_pm_chk->srvid);
0195
0196
0197 p_pm->pid = srvinfo->srvinfo.pid;
0198 add_to_pid_hash(G_process_model_pid_hash, p_pm);
0199 }
0200 else
0201 {
0202 NDRX_LOG(log_warn, "Seems like shutdown is requested "
0203 "while server starting up!");
0204 }
0205 }
0206
0207 }
0208 else
0209 {
0210
0211
0212 NDRX_LOG(log_warn, "Seems like server is not started by ndrxd! "
0213 "The pid %d was not found in PID hash", srvinfo->srvinfo.pid);
0214
0215 start_start_info(p_pm, srvinfo);
0216
0217 p_pm->pid = srvinfo->srvinfo.pid;
0218 p_pm->reqstate = NDRXD_PM_RUNNING_OK;
0219
0220
0221 add_to_pid_hash(G_process_model_pid_hash, p_pm);
0222 }
0223
0224
0225 brd_begin_diff();
0226 for (i=0; i<srvinfo->svc_count; i++)
0227 {
0228
0229
0230
0231 pm_node_svc_t *svc_info = (pm_node_svc_t *)NDRX_MALLOC(sizeof(pm_node_svc_t));
0232 memset((char *)svc_info, 0, sizeof(svc_info));
0233 if (NULL==svc_info)
0234 {
0235 NDRXD_set_error_fmt(NDRXD_EOS, "Failed to allocate pm_node_svc_t(%d)!",
0236 sizeof(pm_node_svc_t));
0237 ret=EXFAIL;
0238 goto out;
0239 }
0240
0241
0242 svc_info->svc = srvinfo->svcs[i];
0243 NDRX_LOG(log_debug, "Server [%s] advertises: svc: [%s] func: [%s]",
0244 p_pm->binary_name, svc_info->svc.svc_nm,
0245 svc_info->svc.fn_nm);
0246
0247 DL_APPEND(p_pm->svcs, svc_info);
0248
0249 if (EXSUCCEED!=brd_add_svc_to_hash(svc_info->svc.svc_nm))
0250 {
0251 ret=EXFAIL;
0252 goto out;
0253 }
0254 }
0255
0256 if (srvinfo->srvinfo.flags & SRV_KEY_FLAGS_BRIDGE)
0257 {
0258 NDRX_LOG(log_debug, "Server is bridge - update bridge table");
0259 if (EXSUCCEED!=brd_addupd_bridge(srvinfo))
0260 {
0261 ret=EXFAIL;
0262 goto out;
0263 }
0264 }
0265 brd_end_diff();
0266
0267
0268
0269
0270
0271 out:
0272 return ret;
0273 }
0274