File: mu_signal_process.c

package info (click to toggle)
fis-gtm 6.2-000-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 30,784 kB
  • ctags: 42,554
  • sloc: ansic: 358,483; asm: 4,847; csh: 4,574; sh: 2,261; awk: 200; makefile: 86; sed: 13
file content (118 lines) | stat: -rw-r--r-- 2,994 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/****************************************************************
 *								*
 *	Copyright 2001, 2009 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 <descrip.h>
#include <climsgdef.h>
#include <ssdef.h>
#include <jpidef.h>
#include <signal.h>
#include "gtm_string.h"
#include "cli.h"
#include "util.h"
#include "mu_signal_process.h"
#include "send_msg.h"

static	int 	send_signal(int, int);
GBLREF	uint4	process_id;

#define SENDMSG_OUTPUT(mpname, mpid) 								 \
{												 \
	error_def(ERR_MUPIPSIG);								 \
	if (!MEMCMP_LIT(command, STOP_STR))							 \
		send_msg(VARLSTCNT(9) ERR_MUPIPSIG, 7, LEN_AND_STR(command), signal, process_id, \
			process_id, mpid, mpid); 						 \
	util_out_print("!AD issued to process !AD: (PID=!XL)",  FLUSH, LEN_AND_STR(command), 	 \
		LEN_AND_STR(mpname), mpid);							 \
}

static int send_signal(int pid, int signal)
{
	int status;

	if (SIGUSR1 == signal)
	{	/* Currently only type of posix signal used */
		status = kill(pid, signal);
		if (-1 == status)
		{
			perror("Job Interrupt request failed: ");
			status = SS$_BADPARAM;
		} else
			status = SS$_NORMAL;
	} else
	{	/* Default signal but only ERR_FORCEDHALT currently sent */
		status = sys$forcex(&pid, 0, signal);
		if (status != SS$_NORMAL)
			rts_error(VARLSTCNT(1) status);
	}
	return status;
}

void mu_signal_process(char *command, int signal)
{
	boolean_t	pid_present, name_present;
	int4		pid, length, status, item, outv;
	char		prc_nam[20];
	unsigned short	name_len;
	$DESCRIPTOR(d_prc_nam,"");

	memset(prc_nam, 0, SIZEOF(prc_nam));
	pid_present = name_present = FALSE;
	if (cli_present("id") == CLI_PRESENT)
	{
		if(!cli_get_hex("id", &pid))
			return;
		pid_present = TRUE;
	}
	if (cli_present("name") == CLI_PRESENT)
	{
		name_len = 20;
		if (!cli_get_str("name", prc_nam, &name_len))
			return;
		if (prc_nam[name_len-1] == '"')
			name_len--;
		if (prc_nam[0] == '"')
		{
			d_prc_nam.dsc$a_pointer = &prc_nam[1];
			name_len--;
		} else
			d_prc_nam.dsc$a_pointer = &prc_nam;
		d_prc_nam.dsc$w_length = name_len;
		name_present = TRUE;
	}
	if (!name_present)
	{
		if (SS$_NORMAL == send_signal(pid, signal))
			SENDMSG_OUTPUT("", pid);
		return;
	}
	item = JPI$_PID;
	status = lib$getjpi(&item, 0, &d_prc_nam, &outv, 0, 0);
	if (SS$_NORMAL != status)
	{
		rts_error(VARLSTCNT(1) status);
		return;
	}
	if (!pid_present)
	{
		if (SS$_NORMAL == send_signal(outv, signal))
			SENDMSG_OUTPUT(&prc_nam, outv);
		return;
	}
	if (outv != pid)
	{
		util_out_print("ID !XL and NAME !AD are not the same process", FLUSH, pid, LEN_AND_STR(&prc_nam));
		return;
	}
	if (SS$_NORMAL == send_signal(pid, signal))
		SENDMSG_OUTPUT(&prc_nam, pid);
	return;
}