summaryrefslogtreecommitdiff
path: root/src/tet3/tcc/environ.c
blob: 24dc8bd7f9505c4100edbc1cf0510f7f1ef336b0 (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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/*
 *	SCCS: @(#)environ.c	1.3 (96/11/04)
 *
 *	UniSoft Ltd., London, England
 *
 * (C) Copyright 1996 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.
 * A copy of the end-user licence agreement is contained in the file
 * Licence which accompanies this distribution.
 * 
 * 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

#ifndef lint
static char sccsid[] = "@(#)environ.c	1.3 (96/11/04) TET3 release 3.3";
#endif

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

SCCS:   	@(#)environ.c	1.3 96/11/04 TETware release 3.3
NAME:		environ.c
PRODUCT:	TETware
AUTHOR:		Andrew Dingwall, UniSoft Ltd.
DATE CREATED:	August 1996

DESCRIPTION:
	functions to manipulate environment variables

MODIFICATIONS:
	Geoff Clare, UniSoft Ltd., August 1996
	Missing <string.h>.

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

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <time.h>
#include <string.h>
#include "dtmac.h"
#include "error.h"
#include "ltoa.h"
#include "servlib.h"
#include "dtetlib.h"
#include "tet3_config.h"
#include "systab.h"
#include "tcc.h"


#ifdef NEEDsrcFile
static char srcFile[] = __FILE__;	/* file name for error reporting */
#endif

/* static function declarations */
static void init1environ PROTOLIST((struct systab *));



/*
**	initenviron() - initialise the environment on each system
*/

void initenviron()
{
	register int sysid, sysmax;
	register struct systab *sp;

	/* do this once for each connected system */
	for (sysid = 0, sysmax = symax(); sysid <= sysmax; sysid++)
		if ((sp = syfind(sysid)) != (struct systab *) 0)
			init1environ(sp);
}

static void init1environ(sp)
struct systab *sp;
{
	/*
	** distributed config variables that are to be passed as
	** communication variables in the environment to each test case
	*/
	static char *comvar[] = {
		"TET_ROOT",
		"TET_EXECUTE",
		"TET_SUITE_ROOT",
		"TET_RUN"
	};

#define Ncomvar	(sizeof comvar / sizeof comvar[0])

	char buf[MAXPATH + 40];
	char *envstr[Ncomvar + 1];
	register char **cvp, *val;
	register char **ep = envstr;

#define Nenvstr	(sizeof envstr / sizeof envstr[0])


	ASSERT_LITE(sp->sy_sysid == 0);

	/* build the list of environment strings */
	for (cvp = comvar; cvp < comvar + Ncomvar; cvp++) {
		if ((val = getdcfg(*cvp, sp->sy_sysid)) == (char *) 0)
			val = "";
		(void) sprintf(buf, "%s=%.*s", *cvp,
			(int) sizeof buf - (int) strlen(*cvp) - 2, val);
		ASSERT(ep < &envstr[Nenvstr]);
		*ep++ = rstrstore(buf);
	}

	/* then add in TET_CODE */
	(void) sprintf(buf, "TET_CODE=%.*s", MAXPATH, sp->sy_rcfname);
	ASSERT(ep < &envstr[Nenvstr]);
	*ep++ = rstrstore(buf);

	/* put the strings in the environment on the specified system */
	if (tcc_putenvv(sp->sy_sysid, envstr, Nenvstr) < 0)
		fatal(0, "can't put communication variables in the environment on system",
			tet_i2a(sp->sy_sysid));

#ifndef TET_LITE	/* -START-LITE-CUT- */
	/* finally, free the storage allocated here */
	for (ep = envstr; ep < envstr + Nenvstr; ep++) {
		TRACE2(tet_Tbuf, 6, "free envstr = %s", tet_i2x(*ep));
		free(*ep);
	}
#endif /* !TET_LITE */	/* -END-LITE-CUT- */
}

/*
**	tcc_putenv() - put a single string into the environment that is
**		passed to test cases and tools
**
**	return 0 if successful or -1 on error
**
**	note that in TETware-Lite, the strings are put directly into the
**	environment of the current process and so must be in static storage
*/

int tcc_putenv(sysid, str)
int sysid;
char *str;
{
	return(tcc_putenvv(sysid, &str, 1));
}

/*
**	tcc_putenv() - strings into the environment that is passed to
**		test cases and tools
**
**	return 0 if successful or -1 on error
**
**	note that in TETware-Lite, the strings are put directly into the
**	environment of the current process and so must be in static storage
*/

int tcc_putenvv(sysid, str, nstr)
int sysid;
char **str;
int nstr;
{
	ASSERT_LITE(sysid == 0);

#ifdef TET_LITE	/* -LITE-CUT-LINE- */

	while (--nstr >= 0)
		if (tet_putenv(*str++) < 0)
			return(-1);

#else	/* -START-LITE-CUT- */

	if (tet_tcputenvv(sysid, str, nstr) < 0) {
		error(tet_tcerrno, "tet_tcputenvv() failed on system",
			tet_i2a(sysid));
		return(-1);
	}

#endif /* TET_LITE */	/* -END-LITE-CUT- */

	return(0);
}