File: jobexam_signal_handler.c

package info (click to toggle)
fis-gtm 7.1-006-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 32,908 kB
  • sloc: ansic: 344,906; asm: 5,184; csh: 4,859; sh: 2,000; awk: 294; makefile: 73; sed: 13
file content (120 lines) | stat: -rwxr-xr-x 4,680 bytes parent folder | download | duplicates (7)
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
/****************************************************************
 *								*
 *	Copyright 2001, 2013 Fidelity Information Services, Inc	*
 *								*
 *	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.	*
 *								*
 ****************************************************************/

/* jobexam signal processor:

   a very simplistic stripped down version of generic_signal_handler(). It is
   only intended to handle terminal errors during execution of the $zjobexam
   function. These are currently SIGSEGV and SIGBUS. On receipt, we use
   rts error to drive the appropriate message and let the condition handler
   take care of it.

 */

#include "mdef.h"
#include "gtm_string.h"

#include <signal.h>
#include "gtm_inet.h"

#include "gtm_stdio.h"
#include "error.h"
#include "gtmsiginfo.h"
#include "gtmimagename.h"
#include "jobexam_signal_handler.h"
#include "send_msg.h"
#include "gtmmsg.h"

GBLREF	uint4			process_id;
GBLREF	enum gtmImageTypes	image_type;
GBLREF	boolean_t		need_core;
DEBUG_ONLY(GBLREF boolean_t ok_to_UNWIND_in_exit_handling;)
LITREF	gtmImageName		gtmImageNames[];

error_def(ERR_JOBEXAMFAIL);
error_def(ERR_KILLBYSIG);
error_def(ERR_KILLBYSIGUINFO);
error_def(ERR_KILLBYSIGSINFO1);
error_def(ERR_KILLBYSIGSINFO2);
error_def(ERR_KILLBYSIGSINFO3);

void jobexam_signal_handler(int sig, siginfo_t *info, void *context)
{
	siginfo_t	exi_siginfo;
	gtmsiginfo_t	signal_info;
	gtm_sigcontext_t exi_context, *context_ptr;

	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
	extract_signal_info(sig, &exi_siginfo, context_ptr, &signal_info);
	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;
		default:
			GTMASSERT;
	}
	send_msg_csa(CSA_ARG(NULL) VARLSTCNT(3) ERR_JOBEXAMFAIL, 1, process_id);
	/* Create a core to examine later. Note this handler is only enabled for two fatal core types so we don't
	 * do any futher checking in this regard.
	 */
	need_core = TRUE;
	gtm_fork_n_core();
	/* Note this routine do NOT invoke create_fatal_error_zshow_dmp() because it would in turn call jobexam
	 * again which would loop us right back around to here. We basically want to do UNWIND(NULL, NULL) logic
	 * but the UNWIND macro can only be used in a condition handler so next is a block that pretends it is
	 * our condition handler and does the needful.
	 */
	{	/* Needs new block since START_CH declares a new var used in UNWIND() */
		int arg = 0;	/* Needed for START_CH macro if debugging enabled */
		START_CH(TRUE);
		DEBUG_ONLY(ok_to_UNWIND_in_exit_handling = TRUE);
		UNWIND(NULL, NULL);
	}
}