1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306
|
/****************************************************************
* *
* Copyright (c) 2005-2016 Fidelity National Information *
* Services, Inc. and/or its subsidiaries. All rights reserved. *
* *
* This source code contains the intellectual property *
* of its copyright holder(s), and is made available *
* under a license. If you do not know the terms of *
* the license, please stop and do not read further. *
* *
****************************************************************/
/* Based on generic_signal_handler without the db engine references like have_crit().
*
* If we are nesting our handlers in an improper way, this routine will
* not return but will immediately invoke core/termination processing.
*
* Returns if some condition makes it inadvisable to exit now else invokes the system EXIT() system call.
*/
#include "mdef.h"
#include "gtm_string.h"
#include "gtm_unistd.h"
#include "gtm_stdlib.h" /* for EXIT() */
#include "gtm_inet.h"
#include "gtm_stdio.h"
#include "gtm_signal.h"
#include "error.h"
#include "gtmsiginfo.h"
#include "gtmimagename.h"
#include "send_msg.h"
#include "gtmmsg.h"
#include "gdsroot.h"
#include "v15_gdsroot.h"
#include "gtm_facility.h"
#include "fileinfo.h"
#include "gdsbt.h"
#include "v15_gdsbt.h"
#include "gdsblk.h"
#include "gdsfhead.h"
#include "v15_gdsfhead.h"
#include "gdsblkops.h"
#include "gtmio.h"
#include "have_crit.h"
#include "dbcertify.h"
#include "forced_exit_err_display.h"
/* These fields are defined as globals not because they are used globally but
* so they will be easily retrievable even in 'pro' cores.
*/
GBLDEF siginfo_t exi_siginfo;
GBLDEF gtm_sigcontext_t exi_context;
GBLREF int4 forced_exit_err;
GBLREF int4 exi_condition;
GBLREF enum gtmImageTypes image_type;
GBLREF boolean_t dont_want_core;
GBLREF boolean_t created_core;
GBLREF boolean_t need_core;
GBLREF uint4 process_id;
GBLREF volatile int4 exit_state;
GBLREF volatile unsigned int core_in_progress;
GBLREF gtmsiginfo_t signal_info;
GBLREF boolean_t exit_handler_active;
GBLREF phase_static_area *psa_gbl;
LITREF gtmImageName gtmImageNames[];
error_def(ERR_FORCEDHALT);
error_def(ERR_KILLBYSIG);
error_def(ERR_KILLBYSIGUINFO);
error_def(ERR_KILLBYSIGSINFO1);
error_def(ERR_KILLBYSIGSINFO2);
error_def(ERR_KILLBYSIGSINFO3);
error_def(ERR_KRNLKILL);
void dbcertify_signal_handler(int sig, siginfo_t *info, void *context)
{
boolean_t dbc_critical, exit_now;
gtm_sigcontext_t *context_ptr;
void (*signal_routine)();
/* Save parameter value in global variables for easy access in core */
dont_want_core = FALSE; /* (re)set in case we recurse */
created_core = FALSE; /* we can deal with a second core if needbe */
exi_condition = sig;
if (NULL != info)
exi_siginfo = *info;
else
memset(&exi_siginfo, 0, SIZEOF(*info));
#if defined(__ia64) && defined(__hpux)
context_ptr = (gtm_sigcontext_t *)context; /* no way to make a copy of the context */
memset(&exi_context, 0, SIZEOF(exi_context));
#else
if (NULL != context)
exi_context = *(gtm_sigcontext_t *)context;
else
memset(&exi_context, 0, SIZEOF(exi_context));
context_ptr = &exi_context;
#endif
/* Check if we are fielding nested immediate shutdown signals */
if (EXIT_IMMED <= exit_state)
{
switch(sig)
{ /* If we are dealing with one of these three dangerous signals which we have
* already hit while attempting to shutdown once, die with core now.
*/
case SIGSEGV:
case SIGBUS:
case SIGILL:
if (core_in_progress)
{
if (exit_handler_active)
{
UNDERSCORE_EXIT(sig);
} else
EXIT(sig);
}
++core_in_progress;
DUMP_CORE;
assertpro(FALSE);
default:
;
}
}
dbc_critical = ((NULL != psa_gbl) && psa_gbl->dbc_critical);
switch(sig)
{
case SIGINT:
case SIGTERM:
forced_exit_err = ERR_FORCEDHALT;
/* If nothing pending AND we have crit or already in exit processing, wait to
* invoke shutdown.
*/
if ((EXIT_PENDING_TOLERANT >= exit_state) && (dbc_critical || exit_handler_active))
{
SET_FORCED_EXIT_STATE;
exit_state++; /* Make exit pending, may still be tolerant though */
return;
}
exit_state = EXIT_IMMED;
forced_exit_err_display();
dont_want_core = TRUE;
break;
case SIGQUIT: /* Handle SIGQUIT specially which we ALWAYS want to defer if possible as it is always sent */
dont_want_core = TRUE;
extract_signal_info(sig, &exi_siginfo, context_ptr, &signal_info);
switch(signal_info.infotype)
{
case GTMSIGINFO_NONE:
forced_exit_err = ERR_KILLBYSIG;
break;
case GTMSIGINFO_USER:
forced_exit_err = ERR_KILLBYSIGUINFO;
break;
case GTMSIGINFO_ILOC + GTMSIGINFO_BADR:
forced_exit_err = ERR_KILLBYSIGSINFO1;
break;
case GTMSIGINFO_ILOC:
forced_exit_err = ERR_KILLBYSIGSINFO2;
break;
case GTMSIGINFO_BADR:
forced_exit_err = ERR_KILLBYSIGSINFO3;
break;
default:
exit_state = EXIT_IMMED;
assertpro(FALSE);
}
/* If nothing pending AND we have crit or already in exit processing, wait to invoke shutdown */
if ((EXIT_PENDING_TOLERANT >= exit_state) && (dbc_critical || exit_handler_active))
{
SET_FORCED_EXIT_STATE;
exit_state++; /* Make exit pending, may still be tolerant though */
return;
}
exit_state = EXIT_IMMED;
switch(signal_info.infotype)
{
case GTMSIGINFO_NONE:
send_msg_csa(CSA_ARG(NULL) VARLSTCNT(6) ERR_KILLBYSIG, 4,
GTMIMAGENAMETXT(image_type), process_id, sig);
gtm_putmsg_csa(CSA_ARG(NULL) VARLSTCNT(6) ERR_KILLBYSIG, 4,
GTMIMAGENAMETXT(image_type), process_id, sig);
break;
case GTMSIGINFO_USER:
send_msg_csa(CSA_ARG(NULL) VARLSTCNT(8) ERR_KILLBYSIGUINFO, 6, GTMIMAGENAMETXT(image_type),
process_id, sig, signal_info.send_pid, signal_info.send_uid);
gtm_putmsg_csa(CSA_ARG(NULL) VARLSTCNT(8) ERR_KILLBYSIGUINFO, 6,
GTMIMAGENAMETXT(image_type), process_id, sig,
signal_info.send_pid, signal_info.send_uid);
break;
case GTMSIGINFO_ILOC + GTMSIGINFO_BADR:
send_msg_csa(CSA_ARG(NULL) VARLSTCNT(8) ERR_KILLBYSIGSINFO1, 6, GTMIMAGENAMETXT(image_type),
process_id, sig, signal_info.int_iadr, signal_info.bad_vadr);
gtm_putmsg_csa(CSA_ARG(NULL) VARLSTCNT(8) ERR_KILLBYSIGSINFO1, 6,
GTMIMAGENAMETXT(image_type), process_id, sig,
signal_info.int_iadr, signal_info.bad_vadr);
break;
case GTMSIGINFO_ILOC:
send_msg_csa(CSA_ARG(NULL) VARLSTCNT(7) ERR_KILLBYSIGSINFO2, 5, GTMIMAGENAMETXT(image_type),
process_id, sig, signal_info.int_iadr);
gtm_putmsg_csa(CSA_ARG(NULL) VARLSTCNT(7) ERR_KILLBYSIGSINFO2, 5,
GTMIMAGENAMETXT(image_type), process_id, sig, signal_info.int_iadr);
break;
case GTMSIGINFO_BADR:
send_msg_csa(CSA_ARG(NULL) VARLSTCNT(7) ERR_KILLBYSIGSINFO3, 5, GTMIMAGENAMETXT(image_type),
process_id, sig, signal_info.bad_vadr);
gtm_putmsg_csa(CSA_ARG(NULL) VARLSTCNT(7) ERR_KILLBYSIGSINFO3, 5,
GTMIMAGENAMETXT(image_type), process_id, sig, signal_info.bad_vadr);
break;
}
break;
#ifdef _AIX
case SIGDANGER:
forced_exit_err = ERR_KRNLKILL;
/* If nothing pending AND we have crit or already in exit processing, wait to invoke shutdown */
if ((EXIT_PENDING_TOLERANT >= exit_state) && (dbc_critical || exit_handler_active))
{
SET_FORCED_EXIT_STATE;
exit_state++; /* Make exit pending, may still be tolerant though */
return;
}
exit_state = EXIT_IMMED;
forced_exit_err_display();
dont_want_core = TRUE;
break;
#endif
default:
extract_signal_info(sig, &exi_siginfo, context_ptr, &signal_info);
switch(signal_info.infotype)
{
case GTMSIGINFO_NONE:
exit_state = EXIT_IMMED;
send_msg_csa(CSA_ARG(NULL) VARLSTCNT(6) ERR_KILLBYSIG, 4,
GTMIMAGENAMETXT(image_type), process_id, sig);
gtm_putmsg_csa(CSA_ARG(NULL) VARLSTCNT(6) ERR_KILLBYSIG, 4,
GTMIMAGENAMETXT(image_type), process_id, sig);
break;
case GTMSIGINFO_USER:
/* This signal was SENT to us so it can wait until we are out of crit to cause an exit */
forced_exit_err = ERR_KILLBYSIGUINFO;
/* If nothing pending AND we have crit or already exiting, wait to invoke shutdown */
if ((EXIT_PENDING_TOLERANT >= exit_state) && (dbc_critical || exit_handler_active))
{
SET_FORCED_EXIT_STATE;
exit_state++; /* Make exit pending, may still be tolerant though */
need_core = TRUE;
gtm_fork_n_core(); /* Generate "virgin" core while we can */
return;
}
exit_state = EXIT_IMMED;
send_msg_csa(CSA_ARG(NULL) VARLSTCNT(8) ERR_KILLBYSIGUINFO, 6, GTMIMAGENAMETXT(image_type),
process_id, sig, signal_info.send_pid, signal_info.send_uid);
gtm_putmsg_csa(CSA_ARG(NULL) VARLSTCNT(8) ERR_KILLBYSIGUINFO, 6,
GTMIMAGENAMETXT(image_type), process_id, sig,
signal_info.send_pid, signal_info.send_uid);
break;
case GTMSIGINFO_ILOC + GTMSIGINFO_BADR:
exit_state = EXIT_IMMED;
send_msg_csa(CSA_ARG(NULL) VARLSTCNT(8) ERR_KILLBYSIGSINFO1, 6, GTMIMAGENAMETXT(image_type),
process_id, sig, signal_info.int_iadr, signal_info.bad_vadr);
gtm_putmsg_csa(CSA_ARG(NULL) VARLSTCNT(8) ERR_KILLBYSIGSINFO1, 6,
GTMIMAGENAMETXT(image_type), process_id, sig,
signal_info.int_iadr, signal_info.bad_vadr);
break;
case GTMSIGINFO_ILOC:
exit_state = EXIT_IMMED;
send_msg_csa(CSA_ARG(NULL) VARLSTCNT(7) ERR_KILLBYSIGSINFO2, 5, GTMIMAGENAMETXT(image_type),
process_id, sig, signal_info.int_iadr);
gtm_putmsg_csa(CSA_ARG(NULL) VARLSTCNT(7) ERR_KILLBYSIGSINFO2, 5,
GTMIMAGENAMETXT(image_type), process_id, sig, signal_info.int_iadr);
break;
case GTMSIGINFO_BADR:
exit_state = EXIT_IMMED;
send_msg_csa(CSA_ARG(NULL) VARLSTCNT(7) ERR_KILLBYSIGSINFO3, 5, GTMIMAGENAMETXT(image_type),
process_id, sig, signal_info.bad_vadr);
gtm_putmsg_csa(CSA_ARG(NULL) VARLSTCNT(7) ERR_KILLBYSIGSINFO3, 5,
GTMIMAGENAMETXT(image_type), process_id, sig, signal_info.bad_vadr);
break;
default:
exit_state = EXIT_IMMED;
assertpro(FALSE);
}
if (0 != signal_info.sig_err)
{
send_msg_csa(CSA_ARG(NULL) VARLSTCNT(1) signal_info.sig_err);
gtm_putmsg_csa(CSA_ARG(NULL) VARLSTCNT(1) signal_info.sig_err);
}
break;
} /* switch (sig) */
FFLUSH(stdout);
if (!dont_want_core)
{
need_core = TRUE;
gtm_fork_n_core();
}
/* As on VMS, a mupip stop does not drive the condition handlers unless we are in crit */
if ((dbc_critical || (SIGTERM != exi_condition)) && CHANDLER_EXISTS)
DRIVECH(exi_condition);
assert((EXIT_IMMED <= exit_state) || !exit_handler_active);
EXIT(-exi_condition);
}
|