]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
Fix #8275 About incorrect PostgreSQL/system TZ config
authorEric Bollengier <eric@baculasystems.com>
Mon, 29 Nov 2021 16:11:37 +0000 (17:11 +0100)
committerEric Bollengier <eric@baculasystems.com>
Thu, 14 Sep 2023 11:56:56 +0000 (13:56 +0200)
bacula/src/cats/postgresql.c
bacula/src/dird/dird.c
bacula/src/lib/bsys.c
bacula/src/lib/protos.h

index 45abf0125c937b6be43ea676d1da66b984f0e04f..3c7ba650a28f42f9c8f128b0ff8fdb4bcff5093c 100644 (file)
@@ -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
index 8e9c0b91d02437133c1e41220066c96d0eaf9f68..f98a870fa6b87c6e166cd0079bfb4659e1562eaf 100644 (file)
@@ -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;
index c074d0a132b6e52b81209ec38a5cd4ddad55e455..e9c796fc1ed8616b76c4d07a7164d6c9bf2eb271 100644 (file)
@@ -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"
index 8a42cdf8b24df70bd6821e09c60d9040966ca014..e157fe133e50d5e09175d2c822319e551e575551 100644 (file)
@@ -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);