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 #include <sys_mqueue.h>
0039 #include <errno.h>
0040 #include <fcntl.h> /* For O_* constants */
0041 #include <sys/stat.h>
0042 #include <unistd.h>
0043
0044 #include <ndrstandard.h>
0045 #include <ndebug.h>
0046 #include <ndrx.h>
0047 #include <atmi.h>
0048 #include <userlog.h>
0049 #include <atmi_int.h>
0050
0051
0052
0053
0054
0055 ndrx_config_t G_config;
0056 exprivate int M_is_reply_q_open = EXFALSE;
0057
0058
0059
0060
0061
0062
0063 expublic int ndrx_xadmin_shm_close(void)
0064 {
0065 int ret = EXSUCCEED;
0066
0067 if (M_is_reply_q_open)
0068 {
0069 ndrx_epoll_shmdetach();
0070
0071
0072 ndrx_libatmi_deinit();
0073 }
0074
0075 M_is_reply_q_open = EXFALSE;
0076
0077 out:
0078 return ret;
0079 }
0080
0081
0082
0083
0084
0085 expublic int ndrx_xadmin_open_rply_q(void)
0086 {
0087 int ret = EXSUCCEED;
0088 int err;
0089 int erri;
0090 #define NDRX_EIDX_EINVAL 0
0091 #define NDRX_EIDX_ENOSPC 1
0092 #define NDRX_EIDX_SYSERR 2
0093
0094 char *reason[]={NDRX_QERR_MSG_EINVAL,
0095 NDRX_QERR_MSG_ENOSPC,
0096 NDRX_QERR_MSG_SYSERR};
0097
0098 NDRX_LOG(log_debug, "About to open xadmin's reply queue");
0099
0100 if (!M_is_reply_q_open)
0101 {
0102 if ((mqd_t)EXFAIL==(G_config.reply_queue = ndrx_mq_open_at(G_config.reply_queue_str,
0103 O_RDWR | O_CREAT,
0104 S_IWUSR | S_IRUSR, NULL)))
0105 {
0106 err = errno;
0107 switch (err)
0108 {
0109 case EINVAL:
0110 erri = NDRX_EIDX_EINVAL;
0111 break;
0112 case ENOSPC:
0113 erri = NDRX_EIDX_ENOSPC;
0114 break;
0115 default:
0116 erri = NDRX_EIDX_SYSERR;
0117 break;
0118 }
0119
0120 NDRX_LOG(log_error, "Failed to open queue: [%s] - %s err: %s",
0121 G_config.reply_queue_str,
0122 reason[erri], strerror(errno));
0123 userlog("Failed to open queue: [%s] - %s err: %s",
0124 G_config.reply_queue_str,
0125 reason[erri], strerror(errno));
0126
0127 fprintf(stderr, "%s\n", reason[erri]);
0128
0129 ret=EXFAIL;
0130 goto out;
0131 }
0132
0133 NDRX_LOG(log_error, "Reply queue [%s] opened!", G_config.reply_queue_str);
0134
0135 fprintf(stderr, "* Shared resources opened...\n");
0136
0137 M_is_reply_q_open=EXTRUE;
0138
0139 }
0140
0141 out:
0142 return ret;
0143 }
0144
0145
0146
0147
0148
0149 expublic int load_env_config(void)
0150 {
0151 char *p;
0152 int ret=EXSUCCEED;
0153
0154 memset(&G_config, 0, sizeof(G_config));
0155 G_config.ndrxd_q = (mqd_t)EXFAIL;
0156 G_config.reply_queue = (mqd_t)EXFAIL;
0157
0158
0159 if (EXSUCCEED!=ndrx_load_common_env())
0160 {
0161 NDRX_LOG(log_error, "Failed to load common env");
0162 ret=EXFAIL;
0163 goto out;
0164 }
0165
0166
0167 if (NULL!=(p = getenv(CONF_NDRX_XADMINTOUT)))
0168 {
0169 int tout = atoi(p);
0170 if (EXSUCCEED!=tptoutset(tout))
0171 {
0172 NDRX_LOG(log_error, "Failed to set `xadmin' Q timeout to: %d: %s",
0173 tout, tpstrerror(tperrno));
0174 EXFAIL_OUT(ret);
0175 }
0176 }
0177 else
0178 {
0179
0180
0181
0182 G_config.listcall_flags|=TPNOTIME;
0183 }
0184
0185 if (NULL==(p=getenv(CONF_NDRX_DPID)))
0186 {
0187 NDRX_LOG(log_error, "Missing %s environment variable!", CONF_NDRX_DPID);
0188 }
0189 else
0190 {
0191 NDRX_STRCPY_SAFE(G_config.pid_file, p);
0192 NDRX_LOG(log_debug, "ndrxd pid file: %s", G_config.pid_file);
0193 }
0194
0195 G_config.qprefix = getenv(CONF_NDRX_QPREFIX);
0196 if (NULL==G_config.qprefix)
0197 {
0198 NDRX_LOG(log_error, "Missing config key %s - FAIL", CONF_NDRX_QPREFIX);
0199 ret=EXFAIL;
0200 goto out;
0201 }
0202
0203 G_config.qpath = getenv(CONF_NDRX_QPATH);
0204 if (NULL==G_config.qpath)
0205 {
0206 NDRX_LOG(log_error, "Missing config key %s - FAIL", CONF_NDRX_QPATH);
0207 ret=EXFAIL;
0208 goto out;
0209 }
0210
0211
0212 snprintf(G_config.ndrxd_q_str, sizeof(G_config.ndrxd_q_str),
0213 NDRX_NDRXD, G_config.qprefix);
0214
0215
0216 snprintf(G_config.reply_queue_str, sizeof(G_config.reply_queue_str),
0217 NDRX_NDRXCLT, G_config.qprefix, getpid());
0218
0219
0220
0221 NDRX_LOG(log_debug, "Reply queue: [%s]",
0222 G_config.reply_queue_str);
0223
0224
0225 G_config.ndrxd_logfile = getenv(CONF_NDRX_DMNLOG);
0226 if (NULL==G_config.ndrxd_logfile)
0227 {
0228 NDRX_LOG(log_error, "Missing config key %s - FAIL", CONF_NDRX_DMNLOG);
0229 ret=EXFAIL;
0230 goto out;
0231 }
0232
0233 p = getenv(CONF_NDRX_IPCKEY);
0234 if (NULL==p)
0235 {
0236
0237 NDRX_LOG(log_error, "Missing config key %s - FAIL", CONF_NDRX_IPCKEY);
0238 userlog("Missing config key %s - FAIL", CONF_NDRX_IPCKEY);
0239 ret=EXFAIL;
0240 goto out;
0241 }
0242 else
0243 {
0244 int tmpkey;
0245
0246
0247 sscanf(p, "%x", &tmpkey);
0248 G_config.ipckey = tmpkey;
0249
0250 NDRX_LOG(log_debug, "SystemV SEM IPC Key set to: [%x]",
0251 G_config.ipckey);
0252 }
0253
0254 out:
0255 return ret;
0256 }
0257
0258