Skip to content

Commit d6b5d85

Browse files
author
Thomas G. Lockhart
committed
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.
1 parent a90b6a4 commit d6b5d85

File tree

1 file changed

+20
-48
lines changed

1 file changed

+20
-48
lines changed

src/backend/commands/variable.c

Lines changed: 20 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Routines for handling of 'SET var TO',
33
* 'SHOW var' and 'RESET var' statements.
44
*
5-
* $Id: variable.c,v 1.2 1998/01/07 18:46:26 momjian Exp $
5+
* $Id: variable.c,v 1.3 1998/02/03 16:06:49 thomas Exp $
66
*
77
*/
88

@@ -22,19 +22,6 @@ extern bool _use_geqo_;
2222
extern int32 _use_geqo_rels_;
2323
extern bool _use_right_sided_plans_;
2424

25-
/*-----------------------------------------------------------------------*/
26-
#if USE_EURODATES
27-
#define DATE_EURO TRUE
28-
#else
29-
#define DATE_EURO FALSE
30-
#endif
31-
32-
/*-----------------------------------------------------------------------*/
33-
struct PGVariables PGVariables =
34-
{
35-
{DATE_EURO, Date_Postgres}
36-
};
37-
3825
/*-----------------------------------------------------------------------*/
3926
static const char *
4027
get_token(char **tok, char **val, const char *str)
@@ -137,26 +124,6 @@ get_token(char **tok, char **val, const char *str)
137124
}
138125

139126
/*-----------------------------------------------------------------------*/
140-
#if FALSE
141-
static bool
142-
parse_null(const char *value)
143-
{
144-
return TRUE;
145-
}
146-
147-
static bool
148-
show_null(const char *value)
149-
{
150-
return TRUE;
151-
}
152-
153-
static bool
154-
reset_null(const char *value)
155-
{
156-
return TRUE;
157-
}
158-
#endif
159-
160127
bool
161128
parse_geqo(const char *value)
162129
{
@@ -247,6 +214,7 @@ parse_r_plans(const char *value)
247214
return TRUE;
248215
}
249216

217+
/*-----------------------------------------------------------------------*/
250218
bool
251219
show_r_plans()
252220
{
@@ -270,6 +238,7 @@ reset_r_plans()
270238
return TRUE;
271239
}
272240

241+
/*-----------------------------------------------------------------------*/
273242
bool
274243
parse_cost_heap(const char *value)
275244
{
@@ -302,6 +271,7 @@ reset_cost_heap()
302271
return TRUE;
303272
}
304273

274+
/*-----------------------------------------------------------------------*/
305275
bool
306276
parse_cost_index(const char *value)
307277
{
@@ -334,6 +304,7 @@ reset_cost_index()
334304
return TRUE;
335305
}
336306

307+
/*-----------------------------------------------------------------------*/
337308
bool
338309
parse_date(const char *value)
339310
{
@@ -470,22 +441,13 @@ parse_timezone(const char *value)
470441
{
471442
/* Not yet tried to save original value from environment? */
472443
if (defaultTZ == NULL)
473-
{
474444
/* found something? then save it for later */
475-
if (getenv("TZ") != NULL)
476-
{
477-
defaultTZ = getenv("TZ");
478-
if (defaultTZ == NULL)
479-
defaultTZ = (char *) -1;
480-
else
481-
strcpy(TZvalue, defaultTZ);
482-
}
445+
if ((defaultTZ = getenv("TZ")) != NULL)
446+
strcpy(TZvalue, defaultTZ);
447+
483448
/* found nothing so mark with an invalid pointer */
484449
else
485-
{
486450
defaultTZ = (char *) -1;
487-
}
488-
}
489451

490452
strcpy(tzbuf, "TZ=");
491453
strcat(tzbuf, tok);
@@ -519,24 +481,34 @@ show_timezone()
519481
* clears the process-specific environment variables.
520482
* Other reasonable arguments to putenv() (e.g. "TZ=", "TZ", "") result
521483
* in a core dump (under Linux anyway).
484+
* - thomas 1998-01-26
522485
*/
523486
bool
524487
reset_timezone()
525488
{
526-
if ((defaultTZ != NULL) && (defaultTZ != (char *) -1))
489+
/* no time zone has been set in this session? */
490+
if (defaultTZ == NULL)
491+
{
492+
}
493+
494+
/* time zone was set and original explicit time zone available? */
495+
else if (defaultTZ != (char *) -1)
527496
{
528497
strcpy(tzbuf, "TZ=");
529498
strcat(tzbuf, TZvalue);
530499
if (putenv(tzbuf) != 0)
531500
elog(ERROR, "Unable to set TZ environment variable to %s", TZvalue);
501+
tzset();
532502
}
503+
504+
/* otherwise, time zone was set but no original explicit time zone available */
533505
else
534506
{
535507
strcpy(tzbuf, "=");
536508
if (putenv(tzbuf) != 0)
537509
elog(ERROR, "Unable to clear TZ environment variable", NULL);
510+
tzset();
538511
}
539-
tzset();
540512

541513
return TRUE;
542514
} /* reset_timezone() */

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy