From ced4594599c5dab1c6987e203a0640280c5c5ac9 Mon Sep 17 00:00:00 2001 From: gambas Date: Fri, 11 Jan 2019 15:23:50 +0100 Subject: [PATCH] Take care of components that modifiy the 'environ' variable. Using 'gb.httpd' does not crash anymore. [INTERPRETER] * BUG: Take care of components that modifiy the 'environ' variable. Using 'gb.httpd' does not crash anymore. --- gb.httpd/src/libhttpd.c | 3 ++- gb.httpd/src/main.c | 4 +++- gb.httpd/src/thttpd.h | 2 +- main/gbx/gbx_api.c | 3 ++- main/gbx/gbx_local.c | 13 ++++++++++--- main/gbx/gbx_value.h | 2 -- main/share/gambas.h | 1 + 7 files changed, 19 insertions(+), 9 deletions(-) diff --git a/gb.httpd/src/libhttpd.c b/gb.httpd/src/libhttpd.c index ba3225467..4ecec5a0c 100644 --- a/gb.httpd/src/libhttpd.c +++ b/gb.httpd/src/libhttpd.c @@ -3512,7 +3512,7 @@ static void cgi_child(httpd_conn * hc) #ifdef CGI_NICE /* Set priority. */ - (void) nice(CGI_NICE); + (void)nice(CGI_NICE); #endif /* CGI_NICE */ #if 0 @@ -3559,6 +3559,7 @@ static void cgi_child(httpd_conn * hc) #endif environ = envp; + //fprintf(stderr, "%s\n", hc->encodedurl); run_cgi(); } diff --git a/gb.httpd/src/main.c b/gb.httpd/src/main.c index 9c0c6a62f..394adc585 100644 --- a/gb.httpd/src/main.c +++ b/gb.httpd/src/main.c @@ -66,7 +66,7 @@ void EXPORT GB_MAIN(int argc, char **argv) if (setjmp(_setjmp_env) == 0) { - setlocale(LC_ALL, "C"); + GB.System.SetLanguage("C"); env = getenv("GB_HTTPD_DEBUG"); if (env && env[0] && strcmp(env, "0") != 0) @@ -75,7 +75,9 @@ void EXPORT GB_MAIN(int argc, char **argv) thttpd_main(argc, argv, GB.System.Debug()); } else + { GB.System.HasForked(); + } } int EXPORT GB_INIT() diff --git a/gb.httpd/src/thttpd.h b/gb.httpd/src/thttpd.h index 43cb032ef..e85e72396 100644 --- a/gb.httpd/src/thttpd.h +++ b/gb.httpd/src/thttpd.h @@ -273,7 +273,7 @@ /* CONFIGURE: nice(2) value to use for CGI programs. If this is undefined, ** CGI programs run at normal priority. */ -#define CGI_NICE 10 +//#define CGI_NICE 10 /* CONFIGURE: $PATH to use for CGI programs. */ diff --git a/main/gbx/gbx_api.c b/main/gbx/gbx_api.c index 87d1e4b17..31ceb8bf0 100644 --- a/main/gbx/gbx_api.c +++ b/main/gbx/gbx_api.c @@ -254,6 +254,7 @@ const void *const GAMBAS_Api[] = (void *)GB_SystemCharset, (void *)LOCAL_get_lang, + (void *)LOCAL_set_lang, (void *)GB_SystemDomainName, (void *)GB_IsRightToLeft, (void *)GB_SystemPath, @@ -2366,8 +2367,8 @@ bool GB_SystemDebug(void) void GB_SystemHasForked(void) { MATH_init(); - FILE_init(); + LOCAL_init(); if (EXEC_profile) DEBUG.Profile.Cancel(); diff --git a/main/gbx/gbx_local.c b/main/gbx/gbx_local.c index 76b43b63e..18a978725 100644 --- a/main/gbx/gbx_local.c +++ b/main/gbx/gbx_local.c @@ -119,6 +119,9 @@ static bool _currency; static char *_lang = NULL; +extern char **environ; +static char **_environ; + #define add_currency_flag(_flag) (LOCAL_local.currency_flag <<= 1, LOCAL_local.currency_flag |= (!!(_flag))) #define test_currency_flag(_negative, _space, _before, _intl) (!!(LOCAL_local.currency_flag & (1 << ((!!_negative) + ((!!_before) << 1) + ((!!_intl) << 2))))) @@ -597,6 +600,7 @@ static void fill_local_info(void) void LOCAL_init(void) { + _environ = environ; LOCAL_set_lang(NULL); } @@ -604,17 +608,20 @@ void LOCAL_exit(void) { if (env_LANG) { - unsetenv("LANG"); + if (environ == _environ) + unsetenv("LANG"); STRING_free(&env_LANG); } if (env_LC_ALL) { - unsetenv("LC_ALL"); + if (environ == _environ) + unsetenv("LC_ALL"); STRING_free(&env_LC_ALL); } if (env_LANGUAGE) { - unsetenv("LANGUAGE"); + if (environ == _environ) + unsetenv("LANGUAGE"); STRING_free(&env_LANGUAGE); } diff --git a/main/gbx/gbx_value.h b/main/gbx/gbx_value.h index 2acc793ed..ea055aec7 100644 --- a/main/gbx/gbx_value.h +++ b/main/gbx/gbx_value.h @@ -149,8 +149,6 @@ typedef intptr_t value[2]; } VALUE_VOID; - - typedef struct { diff --git a/main/share/gambas.h b/main/share/gambas.h index 982b71fe3..0df2610e7 100644 --- a/main/share/gambas.h +++ b/main/share/gambas.h @@ -1104,6 +1104,7 @@ typedef struct { char *(*Charset)(void); char *(*Language)(void); + void (*SetLanguage)(const char *); char *(*DomainName)(void); bool (*IsRightToLeft)(void); char *(*Path)(void);