From f323e1e9b6a860ee40fe723270c6c5f2dfd39feb Mon Sep 17 00:00:00 2001 From: Eric Bollengier Date: Mon, 29 Nov 2021 17:11:37 +0100 Subject: [PATCH] Fix #8275 About incorrect PostgreSQL/system TZ config --- bacula/src/cats/postgresql.c | 7 +++++++ bacula/src/dird/dird.c | 1 - bacula/src/lib/bsys.c | 28 ++++++++++++++++++++++++++++ bacula/src/lib/protos.h | 1 + 4 files changed, 36 insertions(+), 1 deletion(-) diff --git a/bacula/src/cats/postgresql.c b/bacula/src/cats/postgresql.c index 45abf0125..3c7ba650a 100644 --- a/bacula/src/cats/postgresql.c +++ b/bacula/src/cats/postgresql.c @@ -251,6 +251,7 @@ bool BDB_POSTGRESQL::bdb_open_database(JCR *jcr) char buf[10], *port; BDB_POSTGRESQL *mdb = this; int print_msg=0; /* 1: warning, 2: error, 3 fatal */ + const char *tz = get_timezone(); P(mutex); if (mdb->m_connected) { @@ -349,6 +350,12 @@ bool BDB_POSTGRESQL::bdb_open_database(JCR *jcr) sql_query("SET cursor_tuple_fraction=1"); sql_query("SET client_min_messages TO WARNING"); + /* For the Timezone to the current director one */ + if (tz && *tz) { + Mmsg(mdb->cmd, "SET timezone = '%s'", tz); + sql_query(mdb->cmd); + } + /* * Tell PostgreSQL we are using standard conforming strings and avoid warnings such as: * WARNING: nonstandard use of \\ in a string literal diff --git a/bacula/src/dird/dird.c b/bacula/src/dird/dird.c index 8e9c0b91d..f98a870fa 100644 --- a/bacula/src/dird/dird.c +++ b/bacula/src/dird/dird.c @@ -254,7 +254,6 @@ int main (int argc, char *argv[]) bool no_signals = false; char *uid = NULL; char *gid = NULL; - init_working_directory(); /* DELETE ME when bugs in MA1512, MA1632 MA1639 are fixed */ MA1512_reload_job_end_cb = reload_job_end_cb; diff --git a/bacula/src/lib/bsys.c b/bacula/src/lib/bsys.c index c074d0a13..e9c796fc1 100644 --- a/bacula/src/lib/bsys.c +++ b/bacula/src/lib/bsys.c @@ -1819,6 +1819,34 @@ int get_home_directories(const char *grpname, alist *dirs) return (dirs->size() > 0) ? 0 : -1; } +static pthread_once_t tz_control = PTHREAD_ONCE_INIT; +static void init_timezone() +{ +#ifdef HAVE_TZSET + tzset(); + +#elif defined(HAVE_WIN32) + _tzset(); +#endif +} + +const char *get_timezone() +{ + if (pthread_once(&tz_control, init_timezone) != 0) { + /* Should not fail, but tzname is initialized to GMT if needed */ + Dmsg0(0, "pthread_once() call for init_timezone() failed\n"); + } +#ifdef HAVE_TZSET + if (*tzname[1]) { + return tzname[1]; + + } else if (*tzname[0]) { + return tzname[0]; + } +#endif + return ""; +} + #ifdef TEST_PROGRAM #include "unittests.h" diff --git a/bacula/src/lib/protos.h b/bacula/src/lib/protos.h index 8a42cdf8b..e157fe133 100644 --- a/bacula/src/lib/protos.h +++ b/bacula/src/lib/protos.h @@ -70,6 +70,7 @@ int display_global_item(HPKT &hpkt); // void display_collector_types(HPKT &hpkt); /* bsys.c */ +const char *get_timezone(); int get_user_home_directory(const char *user, POOLMEM *&home); int get_home_directories(const char *grpname, alist *dirs); char *ucfirst(char *dest, const char *src, int len); -- 2.47.3