File: suspsigs_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 (92 lines) | stat: -rwxr-xr-x 2,805 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
/****************************************************************
 *								*
 *	Copyright 2001, 2012 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.	*
 *								*
 ****************************************************************/

#include "mdef.h"

#include <signal.h>
#include <errno.h>

#include "error.h"
#include "gtmsiginfo.h"
#include "gtmimagename.h"
#include "have_crit.h"
#include "suspsigs_handler.h"

#define MAXINOUT	16

GBLREF	volatile int		suspend_status;
GBLREF	uint4			process_id;
GBLREF	volatile int4		exit_state;
GBLREF	volatile int4		gtmMallocDepth; 	/* Recursion indicator */
GBLDEF	uint4			sig_count=0;

void suspsigs_handler(int sig, siginfo_t* info, void *context)
{
	sigset_t	block_susp_sigs, oldsigmask;
	int		status;

	switch(sig)
	{
		case SIGTTIN:
		case SIGTTOU:
			/* Terminal access while running in the background */
			if (!IS_GTMSECSHR_IMAGE)	/* Ignore signal if gtmsecshr */
			{
				if ((EXIT_NOTPENDING < exit_state) || !OK_TO_INTERRUPT)
				{	/* Let the process run in the foreground till it finishes the terminal I/O */
					if (EXIT_NOTPENDING == exit_state)
						suspend_status = DEFER_SUSPEND;
					status = kill(process_id, SIGCONT);
					assert(0 == status);
					/*
					 * If SIGCONT is not delivered before we go back to the I/O operation that caused
					 * SIGTTIN/OU, these signals can be generated again. In such cases,
					 * we might send ourselves an extra SIGCONT. The extra SIGCONT won't affect
					 * the I/O operation since we are running in the foreground already due to the
					 * first SIGCONT.
					 */
					sig_count++;
					/* When process receives SIGTTIN or SIGTTOUT signal, it goes into suspend mode.
					 * If it is NOT OK_TO_INTERRUPT i.e. if process is holding some critical
					 * resources, the suspension of the process is deferred until the critical
					 * resources are released. It is not expected to arrive extra TTIN/TTOU signals
					 * between arrival of first TTIN/TTOU and actual suspension of the process.
					 * If such out of design situation arises, we limit the number of unexpected
					 * TTIN/TTOU to MAXINOUT and then GTMASSERT.
					 */
					if (MAXINOUT == sig_count)
						GTMASSERT;
					break;
				}
				suspend(sig);
			}
			break;

		case SIGTSTP:
			if (!IS_GTMSECSHR_IMAGE)	/* not a good idea to suspend gtmsecshr */
			{
				if (EXIT_NOTPENDING == exit_state) /* not processing other signals */
				{
					if (!OK_TO_INTERRUPT)
					{
						suspend_status = DEFER_SUSPEND;
						break;
					}
					suspend(sig);
				}
			}
			break;

		default:
			GTMASSERT;
	}
	return;
}