|
From: EXT-Smith, E. M <eri...@BO...> - 2003-10-17 13:33:11
|
Stefan, Leif, et al.
Last evening I was trying to get our 7 services running under WinXP and =
discovered something that may be the underlying cause of a large number =
of problems on the Windows platforms.
It appeared when my service would start up properly as a console, but =
would not start as a service.
It comes down to the putenv()/getenv() calls in the wrapper_win.c file.
putenv() specifies :
" Note that the string given to putenv must be static or global. =
Unpredictable results will occur if a local or dynamic string given to =
putenv is used after the string memory is released. "
(from Borland C++ Builder C Runtime Library Reference)
Within wrapper_win.c, the env buffer (used to pass info into putenv()) =
is local, reused, and removed from scope before the values are used.
For me, this appeared as an expected environment variable not being =
found during conf file resolution.
I made significant modifications to my version last evening to =
compensate for this.
I also changed some of the #ifdef values to use _DEBUG instead of DEBUG, =
and there are a few additional log_printf's that helped me find the =
problem.
Here's the DIFF.
407,408d405
< log_printf(WRAPPER_SOURCE_WRAPPER, LEVEL_DEBUG, "Clearing up =
old command line"); < log_printf(WRAPPER_SOURCE_WRAPPER, =
LEVEL_DEBUG, "Old Command Line \"%s\"", wrapperData->jvmCommand); =
417,419c414
< < #ifdef _DEBUG < log_printf(WRAPPER_SOURCE_WRAPPER, LEVEL_DEBUG, =
"JVM Command Line Parameters"); ---
> /*
421c416
< log_printf(WRAPPER_SOURCE_WRAPPER, LEVEL_DEBUG, "%d : %s", i, =
strings[i]); ---
> printf("%d : %s\n", i, strings[i]);
423c418
< #endif ---
> */
1021c1016
< #ifdef _DEBUG ---
> #ifdef DEBUG
1201,1202d1195
< static char **envKeys =3D NULL; < static int envKeysCount =3D 0; =
1204d1196
< int envCount =3D 0; 1216c1208
< // CHAR env[MAX_PROPERTY_NAME_LENGTH - 1 + =
MAX_PROPERTY_VALUE_LENGTH - 1 + 2]; ---
> CHAR env[MAX_PROPERTY_NAME_LENGTH - 1 + MAX_PROPERTY_VALUE_LENGTH =
- 1 + 2];
1220c1212
< #ifdef _DEBUG ---
> #ifdef DEBUG
1235,1261d1225
< < // First time through, count all of the keys. < do =
{ < cbName =3D MAX_PROPERTY_NAME_LENGTH; < =
cbData =3D MAX_PROPERTY_VALUE_LENGTH; < err =3D =
RegEnumValue(hKey, dwIndex, name, &cbName, NULL, &type, data, &cbData); =
< dwIndex++; < } while (err !=3D =
ERROR_NO_MORE_ITEMS); < < if ( 0 < dwIndex ) { < // =
Now allocate a buffer for the environment strings. < if ( =
NULL !=3D envKeys ) { < int x =3D 0; < =
for ( x =3D 0; x < envKeysCount; x++ ) { < if ( NULL =
!=3D envKeys[ x ] ) { < free( envKeys[ x ] ); < =
envKeys[ x ] =3D NULL; < } < =
} < free( envKeys ); < =
envKeys =3D NULL; < } < envKeys =3D =
calloc(dwIndex, sizeof( char * ) ); < envKeysCount =3D =
dwIndex; < } < if ( NULL !=3D *envKeys ) { < =
dwIndex =3D 0; 1267c1231
< #ifdef _DEBUG ---
> #ifdef DEBUG
1271,1274c1235,1236
< envKeys[ dwIndex ] =3D =
malloc(MAX_PROPERTY_NAME_LENGTH - 1 + MAX_PROPERTY_VALUE_LENGTH - 1 + =
2); < if ( NULL !=3D envKeys[ dwIndex ] ) { < =
sprintf(envKeys[ dwIndex ], "%s=3D%s", name, data); < =
if (putenv(envKeys[ dwIndex ] ) ) { ---
> sprintf(env, "%s=3D%s", name, data);
> if (putenv(env)) {
1279c1241
< #ifdef _DEBUG ---
> #ifdef DEBUG
1282d1243
< } 1292d1252
< } 1295c1255
< #ifdef _DEBUG ---
> #ifdef DEBUG
1311c1271
< #ifdef _DEBUG ---
> #ifdef DEBUG
1316c1276
< #ifdef _DEBUG ---
> #ifdef DEBUG
1320c1280
< #ifdef _DEBUG ---
> #ifdef DEBUG
1333c1293
< #ifdef _DEBUG ---
> #ifdef DEBUG
1339c1299
< #ifdef _DEBUG ---
> #ifdef DEBUG
1342,1344c1302,1303
< // Replace the env string. < =
sprintf(envKeys[ dwIndex ], "%s=3D%s", =
name, data); < if (putenv(envKeys[ =
dwIndex ])) { ---
> sprintf(env, "%s=3D%s", name, =
data);
> if (putenv(env)) {
1362c1321
< #ifdef _DEBUG ---
> #ifdef DEBUG
1369c1328
< #ifdef _DEBUG ---
> #ifdef DEBUG
1904c1863
< #ifdef _DEBUG ---
> #ifdef DEBUG
1912c1871
< #ifdef _DEBUG ---
> #ifdef DEBUG
Eric M. Smith
InfoStructure Systems
Boeing Chairman's Innovation Initiative
|