summaryrefslogtreecommitdiff
path: root/src/tet3/tccd/etab.c
blob: 83f76a9faea6acd2419cab8ac22b8ade281b05cc (plain)
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
/*
 *      SCCS:  @(#)etab.c	1.6 (96/11/04) 
 *
 *	UniSoft Ltd., London, England
 *
 * (C) Copyright 1992 X/Open Company Limited
 *
 * All rights reserved.  No part of this source code may be reproduced,
 * stored in a retrieval system, or transmitted, in any form or by any
 * means, electronic, mechanical, photocopying, recording or otherwise,
 * except as stated in the end-user licence agreement, without the prior
 * permission of the copyright owners.
 *
 * X/Open and the 'X' symbol are trademarks of X/Open Company Limited in
 * the UK and other countries.
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

/************************************************************************

SCCS:   	@(#)etab.c	1.6 96/11/04 TETware release 3.3
NAME:		etab.c
PRODUCT:	TETware
AUTHOR:		Andrew Dingwall, UniSoft Ltd.
DATE CREATED:	April 1992

DESCRIPTION:
	executed process table administration functions

MODIFICATIONS:

	Aaron Plattner, April 2010
	Fixed warnings when compiled with GCC's -Wall option.

************************************************************************/


#include <stdlib.h>
#include <signal.h>
#include <errno.h>
#include <sys/types.h>
#include "dtmac.h"
#include "dtmsg.h"
#include "ptab.h"
#include "etab.h"
#include "error.h"
#include "llist.h"
#include "bstring.h"
#include "tccd.h"

#ifndef NOTRACE
#include "ltoa.h"
#endif

static struct etab *etab;		/* ptr to head of exec table */


/*
**	etalloc() - allocate an exec table element and return a pointer thereto
**
**	return (struct etab *) 0 on error
*/

struct etab *etalloc()
{
	register struct etab *ep;

	errno = 0;

	if ((ep = (struct etab *) malloc(sizeof *ep)) == (struct etab *) 0) {
		error(errno, "can't allocate etab element", (char *) 0);
		return((struct etab *) 0);
	}
	TRACE2(tet_Tbuf, 6, "allocate etab = %s", tet_i2x(ep));
	bzero((char *) ep, sizeof *ep);

	return(ep);
}

/*
**	etfree() - free an exec table element
*/

void etfree(ep)
struct etab *ep;
{
	TRACE2(tet_Tbuf, 6, "free etab = %s", tet_i2x(ep));

	if (ep)
		free((char *) ep);
}

/*
**	etadd() - insert an element in the etab list
*/

void etadd(ep)
struct etab *ep;
{
	tet_listinsert((struct llist **) &etab, (struct llist *) ep);
}

/*
**	etrm() - remove an element from the etab list
*/

void etrm(ep)
struct etab *ep;
{
	tet_listremove((struct llist **) &etab, (struct llist *) ep);
}

/*
**	etfind() - search the exec table for entry matching pid and
**		return a pointer thereto
**
**	return (struct etab *) 0 if not found
*/

struct etab *etfind(pid)
register int pid;
{
	register struct etab *ep;

	for (ep = etab; ep; ep = ep->et_next)
		if (ep->et_pid == pid)
			break;

	return(ep);
}

/*
**	etdead() - etab processing when a process logs off or dies
*/

void etdead(pp)
struct ptab *pp;
{
	register struct etab *ep;
	register int done;

	do {
		done = 1;
		for (ep = etab; ep; ep = ep->et_next)
			if (ep->et_ptab == pp) {
				if (ep->et_state == ES_RUNNING)
					KILL(ep->et_pid, SIGHUP);
				etrm(ep);
				etfree(ep);
				done = 0;
				break;
			}
	} while (!done);
}