Commit d6b5d850 authored by Thomas G. Lockhart's avatar Thomas G. Lockhart

Supress call to tzset() in reset_timezone() if a new time zone has never

 been set in the session.
General cleanup of timezone support code.
parent a90b6a44
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* Routines for handling of 'SET var TO', * Routines for handling of 'SET var TO',
* 'SHOW var' and 'RESET var' statements. * 'SHOW var' and 'RESET var' statements.
* *
* $Id: variable.c,v 1.2 1998/01/07 18:46:26 momjian Exp $ * $Id: variable.c,v 1.3 1998/02/03 16:06:49 thomas Exp $
* *
*/ */
...@@ -22,19 +22,6 @@ extern bool _use_geqo_; ...@@ -22,19 +22,6 @@ extern bool _use_geqo_;
extern int32 _use_geqo_rels_; extern int32 _use_geqo_rels_;
extern bool _use_right_sided_plans_; extern bool _use_right_sided_plans_;
/*-----------------------------------------------------------------------*/
#if USE_EURODATES
#define DATE_EURO TRUE
#else
#define DATE_EURO FALSE
#endif
/*-----------------------------------------------------------------------*/
struct PGVariables PGVariables =
{
{DATE_EURO, Date_Postgres}
};
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
static const char * static const char *
get_token(char **tok, char **val, const char *str) get_token(char **tok, char **val, const char *str)
...@@ -137,26 +124,6 @@ get_token(char **tok, char **val, const char *str) ...@@ -137,26 +124,6 @@ get_token(char **tok, char **val, const char *str)
} }
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
#if FALSE
static bool
parse_null(const char *value)
{
return TRUE;
}
static bool
show_null(const char *value)
{
return TRUE;
}
static bool
reset_null(const char *value)
{
return TRUE;
}
#endif
bool bool
parse_geqo(const char *value) parse_geqo(const char *value)
{ {
...@@ -247,6 +214,7 @@ parse_r_plans(const char *value) ...@@ -247,6 +214,7 @@ parse_r_plans(const char *value)
return TRUE; return TRUE;
} }
/*-----------------------------------------------------------------------*/
bool bool
show_r_plans() show_r_plans()
{ {
...@@ -270,6 +238,7 @@ reset_r_plans() ...@@ -270,6 +238,7 @@ reset_r_plans()
return TRUE; return TRUE;
} }
/*-----------------------------------------------------------------------*/
bool bool
parse_cost_heap(const char *value) parse_cost_heap(const char *value)
{ {
...@@ -302,6 +271,7 @@ reset_cost_heap() ...@@ -302,6 +271,7 @@ reset_cost_heap()
return TRUE; return TRUE;
} }
/*-----------------------------------------------------------------------*/
bool bool
parse_cost_index(const char *value) parse_cost_index(const char *value)
{ {
...@@ -334,6 +304,7 @@ reset_cost_index() ...@@ -334,6 +304,7 @@ reset_cost_index()
return TRUE; return TRUE;
} }
/*-----------------------------------------------------------------------*/
bool bool
parse_date(const char *value) parse_date(const char *value)
{ {
...@@ -470,22 +441,13 @@ parse_timezone(const char *value) ...@@ -470,22 +441,13 @@ parse_timezone(const char *value)
{ {
/* Not yet tried to save original value from environment? */ /* Not yet tried to save original value from environment? */
if (defaultTZ == NULL) if (defaultTZ == NULL)
{
/* found something? then save it for later */ /* found something? then save it for later */
if (getenv("TZ") != NULL) if ((defaultTZ = getenv("TZ")) != NULL)
{ strcpy(TZvalue, defaultTZ);
defaultTZ = getenv("TZ");
if (defaultTZ == NULL)
defaultTZ = (char *) -1;
else
strcpy(TZvalue, defaultTZ);
}
/* found nothing so mark with an invalid pointer */ /* found nothing so mark with an invalid pointer */
else else
{
defaultTZ = (char *) -1; defaultTZ = (char *) -1;
}
}
strcpy(tzbuf, "TZ="); strcpy(tzbuf, "TZ=");
strcat(tzbuf, tok); strcat(tzbuf, tok);
...@@ -519,24 +481,34 @@ show_timezone() ...@@ -519,24 +481,34 @@ show_timezone()
* clears the process-specific environment variables. * clears the process-specific environment variables.
* Other reasonable arguments to putenv() (e.g. "TZ=", "TZ", "") result * Other reasonable arguments to putenv() (e.g. "TZ=", "TZ", "") result
* in a core dump (under Linux anyway). * in a core dump (under Linux anyway).
* - thomas 1998-01-26
*/ */
bool bool
reset_timezone() reset_timezone()
{ {
if ((defaultTZ != NULL) && (defaultTZ != (char *) -1)) /* no time zone has been set in this session? */
if (defaultTZ == NULL)
{
}
/* time zone was set and original explicit time zone available? */
else if (defaultTZ != (char *) -1)
{ {
strcpy(tzbuf, "TZ="); strcpy(tzbuf, "TZ=");
strcat(tzbuf, TZvalue); strcat(tzbuf, TZvalue);
if (putenv(tzbuf) != 0) if (putenv(tzbuf) != 0)
elog(ERROR, "Unable to set TZ environment variable to %s", TZvalue); elog(ERROR, "Unable to set TZ environment variable to %s", TZvalue);
tzset();
} }
/* otherwise, time zone was set but no original explicit time zone available */
else else
{ {
strcpy(tzbuf, "="); strcpy(tzbuf, "=");
if (putenv(tzbuf) != 0) if (putenv(tzbuf) != 0)
elog(ERROR, "Unable to clear TZ environment variable", NULL); elog(ERROR, "Unable to clear TZ environment variable", NULL);
tzset();
} }
tzset();
return TRUE; return TRUE;
} /* reset_timezone() */ } /* reset_timezone() */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment