File: gtm_c_stack_trace_semop.c

package info (click to toggle)
fis-gtm 6.3-007-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 36,284 kB
  • sloc: ansic: 328,861; asm: 5,182; csh: 5,102; sh: 1,918; awk: 291; makefile: 69; sed: 13
file content (96 lines) | stat: -rw-r--r-- 2,972 bytes parent folder | download
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
/****************************************************************
 *								*
 * Copyright (c) 2011-2017 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.	*
 *								*
 ****************************************************************/
#include "mdef.h"
#include "gtm_ipc.h"
#include <sys/sem.h>
#include <errno.h>
#include "gtm_c_stack_trace.h"
#include "gtm_c_stack_trace_semop.h"
#include "semwt2long_handler.h"
#include "wbox_test_init.h"
#include "gt_timer.h"
#include "gdsroot.h"
#include "gdsbt.h"
#include "gdsfhead.h"

GBLREF uint4            process_id;
#ifdef DEBUG
GBLREF	gd_region	*gv_cur_region;
GBLREF  sgmnt_addrs     *cs_addrs;
#endif
int try_semop_get_c_stack(int semid, struct sembuf sops[], int nsops)
{
	int                     stuckcnt, loopcount;
	int                     semop_pid, save_errno;
	int                     last_sem_trace, rc;
#	ifdef DEBUG
	node_local_ptr_t        cnl = NULL;
#	endif
	DCL_THREADGBL_ACCESS;

	SETUP_THREADGBL_ACCESS;
#	ifdef DEBUG
	if ((NULL != gv_cur_region) && gv_cur_region->open && (NULL != cs_addrs))
		cnl = cs_addrs->nl;
#	endif
	stuckcnt = 0;
	loopcount = -1;
	save_errno = 0;
	last_sem_trace = -1;
	TREF(semwait2long) = TRUE;
	do
	{
		/* If we are entering the loop for the first time or there was an interrupt and that 	*/
		/* was due to the timer pop (which sets semop2long), restart the timer			*/
		if (TREF(semwait2long))
		{
			TREF(semwait2long) = FALSE;
			start_timer((TID)semwt2long_handler,(int4)MAX_SEM_WAIT_TIME, semwt2long_handler, 0, NULL);
		}
		rc = semop(semid, sops, nsops);
		if (-1 == rc)
		{
			save_errno = errno;
			/* Timer popped, get C-stack trace */
			if ((EINTR == save_errno) && TREF(semwait2long))
			{
				stuckcnt++;
				last_sem_trace = -1;
				for (loopcount = 0; loopcount < nsops; loopcount++)
				{
					if ((last_sem_trace != sops[loopcount].sem_num) && (0 == sops[loopcount].sem_op))
					{	/* Do not take trace of the same process again, in a point of time */
						last_sem_trace = sops[loopcount].sem_num;
						semop_pid = semctl(semid, sops[loopcount].sem_num, GETPID);
						if ((-1 != semop_pid) && (semop_pid != process_id))
						{
							GET_C_STACK_FROM_SCRIPT("SEMOP_INFO", process_id, semop_pid, stuckcnt);
							/* Got stack trace signal the first process to continue */
#							ifdef DEBUG
							if (cnl)
								GTM_WHITE_BOX_TEST(WBTEST_SEMTOOLONG_STACK_TRACE,
									cnl->wbox_test_seq_num, 3);
#							endif
						} else if (-1 == semop_pid)
						{
							rc = -1;
							save_errno = errno;
							break;
						}
					}
				}
			}
		}
	} while ((-1 == rc) && (EINTR == save_errno));
	cancel_timer((TID)semwt2long_handler);
	return (-1 == rc) ? save_errno : 0;
}