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 <stdio.h>
0035 #include <stdlib.h>
0036 #include <string.h>
0037 #include <errno.h>
0038 #include <regex.h>
0039 #include <utlist.h>
0040 #include <unistd.h>
0041 #include <signal.h>
0042 #include <fcntl.h>
0043
0044 #include <ndebug.h>
0045 #include <atmi.h>
0046 #include <atmi_int.h>
0047 #include <typed_buf.h>
0048 #include <ndrstandard.h>
0049 #include <ubf.h>
0050 #include <Exfields.h>
0051 #include <Excompat.h>
0052 #include <ubfutil.h>
0053 #include <sys_unix.h>
0054 #include <gencall.h>
0055 #include "tpadmsv.h"
0056 #include "expr.h"
0057
0058
0059
0060
0061
0062
0063
0064
0065 typedef struct
0066 {
0067 char lmid[MAXTIDENT+1];
0068 long srvid;
0069 char rqaddr[128+1];
0070 char state[3+1];
0071 long timerestart;
0072 long pid;
0073 char servername[78+1];
0074 char clopt[256+1];
0075 long generation;
0076 } ndrx_adm_server_t;
0077
0078
0079
0080
0081 expublic ndrx_adm_elmap_t ndrx_G_server_map[] =
0082 {
0083
0084 {TA_LMID, TPADM_EL(ndrx_adm_server_t, lmid)}
0085 ,{TA_SRVID, TPADM_EL(ndrx_adm_server_t, srvid)}
0086 ,{TA_RQADDR, TPADM_EL(ndrx_adm_server_t, rqaddr)}
0087 ,{TA_STATE, TPADM_EL(ndrx_adm_server_t, state)}
0088 ,{TA_TIMERESTART, TPADM_EL(ndrx_adm_server_t, timerestart)}
0089 ,{TA_PID, TPADM_EL(ndrx_adm_server_t, pid)}
0090 ,{TA_SERVERNAME, TPADM_EL(ndrx_adm_server_t, servername)}
0091 ,{TA_CLOPT, TPADM_EL(ndrx_adm_server_t, clopt)}
0092 ,{TA_GENERATION, TPADM_EL(ndrx_adm_server_t, generation)}
0093 ,{BBADFLDID}
0094 };
0095
0096
0097
0098
0099 exprivate ndrx_adm_cursors_t *M_cursnew;
0100 exprivate int M_idx = 0;
0101
0102
0103
0104
0105
0106
0107
0108
0109 exprivate int ndrx_adm_server_proc_list(command_reply_t *reply, size_t reply_len)
0110 {
0111 command_reply_ppm_t * ppm_info = (command_reply_ppm_t*)reply;
0112 int ret = EXSUCCEED;
0113
0114 if (NDRXD_CALL_TYPE_PM_PPM!=reply->msg_type)
0115 {
0116
0117 goto out;
0118 }
0119
0120 NDRX_LOG(log_debug, "ppm out: [%s]", ppm_info->binary_name);
0121
0122 ndrx_adm_server_t srv;
0123 memset(&srv, 0, sizeof(srv));
0124
0125 srv.srvid = ppm_info->srvid;
0126 srv.pid = ppm_info->pid;
0127 NDRX_STRCPY_SAFE(srv.rqaddr, ppm_info->rqaddress);
0128 srv.timerestart = ppm_info->state_changed;
0129 srv.generation = ppm_info->exec_seq_try + 1;
0130 snprintf(srv.lmid, sizeof(srv.lmid), "%ld", tpgetnodeid());
0131
0132 if (NDRXD_PM_RUNNING_OK==ppm_info->state)
0133 {
0134 NDRX_STRCPY_SAFE(srv.state, "ACT");
0135 }
0136 else if (NDRXD_PM_STARTING==ppm_info->state)
0137 {
0138 NDRX_STRCPY_SAFE(srv.state, "RES");
0139 }
0140 else if (NDRXD_PM_STOPPING==ppm_info->state)
0141 {
0142 NDRX_STRCPY_SAFE(srv.state, "CLE");
0143 }
0144 else if (NDRXD_PM_NOT_STARTED==ppm_info->state || NDRXD_PM_EXIT==ppm_info->state)
0145 {
0146 NDRX_STRCPY_SAFE(srv.state, "INA");
0147 }
0148 else
0149 {
0150 NDRX_STRCPY_SAFE(srv.state, "DEA");
0151 }
0152
0153 NDRX_STRCPY_SAFE(srv.servername, ppm_info->binary_name);
0154 NDRX_STRCPY_SAFE(srv.clopt, ppm_info->binary_name_real);
0155
0156 if (EXSUCCEED!=ndrx_growlist_add(&M_cursnew->list, (void *)&srv, M_idx))
0157 {
0158 NDRX_LOG(log_error, "Growlist failed - out of memory?");
0159 EXFAIL_OUT(ret);
0160 }
0161
0162 NDRX_LOG(log_debug, "Server [%s]/%ld state %s added", srv.servername,
0163 srv.srvid, srv.state);
0164 M_idx++;
0165 out:
0166 return ret;
0167 }
0168
0169
0170
0171
0172
0173
0174
0175 expublic int ndrx_adm_server_get(char *clazz, ndrx_adm_cursors_t *cursnew, long flags)
0176 {
0177 int ret = EXSUCCEED;
0178
0179
0180 M_idx = 0;
0181
0182 ndrx_growlist_init(&cursnew->list, 100, sizeof(ndrx_adm_server_t));
0183
0184 M_cursnew = cursnew;
0185 cursnew->map = ndrx_G_server_map;
0186
0187 if (EXSUCCEED!=ndrx_adm_list_call(ndrx_adm_server_proc_list,
0188 NDRXD_COM_XAPPM_RQ, NDRXD_COM_XAPPM_RP, ndrx_get_G_atmi_conf()->ndrxd_q_str))
0189 {
0190 NDRX_LOG(log_error, "Failed to call PPM");
0191 EXFAIL_OUT(ret);
0192 }
0193
0194 out:
0195
0196 if (EXSUCCEED!=ret)
0197 {
0198 ndrx_growlist_free(&M_cursnew->list);
0199 }
0200
0201 return ret;
0202 }
0203
0204