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 <errno.h>
0038 #include <memory.h>
0039 #include <sys/types.h>
0040 #include <dirent.h>
0041 #include <sys/stat.h>
0042 #include <utlist.h>
0043
0044 #include <ndrstandard.h>
0045 #include <ndrxd.h>
0046 #include <atmi_int.h>
0047 #include <nstopwatch.h>
0048
0049 #include <ndebug.h>
0050 #include <cmd_processor.h>
0051 #include <signal.h>
0052
0053 #include "userlog.h"
0054 #include "sys_unix.h"
0055
0056
0057
0058
0059
0060
0061
0062
0063 exprivate int request_info(char *qname);
0064
0065
0066
0067
0068 expublic int do_restart_actions(void)
0069 {
0070 int ret=EXSUCCEED;
0071 string_list_t* qlist = NULL;
0072 string_list_t* elt = NULL;
0073 static char server_prefix[NDRX_MAX_Q_SIZE+1];
0074 static int server_prefix_len;
0075
0076
0077
0078
0079
0080
0081 if (EXSUCCEED!=(ret = load_active_config_live()))
0082 {
0083 NDRX_LOG(log_error, "Failed to load active configuration - "
0084 "cannot restart!");
0085 goto out;
0086 }
0087
0088 snprintf(server_prefix, sizeof(server_prefix), NDRX_ADMIN_FMT_PFX, G_sys_config.qprefix);
0089 server_prefix_len=strlen(server_prefix);
0090 NDRX_LOG(log_debug, "server_prefix=[%s]/%d", server_prefix,
0091 server_prefix_len);
0092
0093 NDRX_LOG(log_warn, "Scanning process queues for info gathering");
0094
0095
0096
0097 qlist = ndrx_sys_mqueue_list_make(G_sys_config.qpath, &ret);
0098
0099 if (EXSUCCEED!=ret)
0100 {
0101 NDRX_LOG(log_error, "posix queue listing failed!");
0102 EXFAIL_OUT(ret);
0103 }
0104
0105 LL_FOREACH(qlist,elt)
0106 {
0107 if (0==strncmp(elt->qname, server_prefix, server_prefix_len))
0108 {
0109 NDRX_LOG(log_warn, "Requesting info from: [%s]", elt->qname);
0110 ret=request_info(elt->qname);
0111 }
0112
0113
0114 if (EXSUCCEED!=ret)
0115 goto out;
0116 }
0117
0118
0119 ndrx_stopwatch_reset(&(G_sys_config.time_from_restart));
0120
0121 out:
0122
0123 if (NULL!=qlist)
0124 {
0125 ndrx_string_list_free(qlist);
0126 }
0127
0128 return ret;
0129 }
0130
0131
0132
0133
0134 exprivate int request_info(char *qname)
0135 {
0136 int ret=EXSUCCEED;
0137 command_call_t call;
0138 memset(&call, 0, sizeof(call));
0139
0140 if (EXSUCCEED!=(cmd_generic_call(NDRXD_COM_SRVINFO_RQ, NDRXD_SRC_ADMIN,
0141 NDRXD_CALL_TYPE_GENERIC,
0142 &call, sizeof(call),
0143 G_command_state.listenq_str,
0144 G_command_state.listenq,
0145 (mqd_t)EXFAIL,
0146 qname,
0147 0, NULL,
0148 NULL,
0149 NULL,
0150 NULL,
0151 EXFALSE)))
0152 {
0153
0154 NDRX_LOG(log_error, "Failed to call: [%s]", qname);
0155 }
0156
0157 out:
0158 return ret;
0159 }
0160
0161
0162
0163
0164 expublic int do_restart_chk(void)
0165 {
0166 int ret=EXSUCCEED;
0167 int delta;
0168
0169 if ((delta=ndrx_stopwatch_get_delta_sec(&(G_sys_config.time_from_restart))) > G_app_config->restart_to_check)
0170 {
0171 NDRX_LOG(log_warn, "Restart learning time spent over... "
0172 "switching to normal state!");
0173 G_sys_config.restarting = EXFALSE;
0174 }
0175 else
0176 {
0177 NDRX_LOG(log_warn, "Still learning for %d secs, limit: %d",
0178 delta, G_app_config->restart_to_check);
0179 }
0180
0181 out:
0182 return ret;
0183 }
0184
0185
0186