Ticket #5319: mythtv-5319-require_same_time_zone_settings_on_sbe_and_frontends.patch

File mythtv-5319-require_same_time_zone_settings_on_sbe_and_frontends.patch, 9.7 KB (added by sphery <mtdean@…>, 16 years ago)
  • libs/libmythdb/exitcodes.h

    old new  
    1010#define GENERIC_EXIT_DB_ERROR                     250
    1111#define GENERIC_EXIT_SOCKET_ERROR                 249
    1212#define GENERIC_EXIT_OPENING_LOGFILE_ERROR        248
    13 #define GENERIC_EXIT_UNKNOWN_ERROR                247
    14 #define GENERIC_EXIT_EXECL_ERROR                  246
    15 #define FIXME_BUG__LIBRARY_EXIT_NO_THEME          245
    16 #define FIXME_BUG__LIBRARY_EXIT_TFW_FAILED_OPEN   244
    17 #define GENERIC_EXIT_START                        244
     13#define GENERIC_EXIT_INVALID_TIMEZONE             247
     14#define GENERIC_EXIT_UNKNOWN_ERROR                246
     15#define GENERIC_EXIT_EXECL_ERROR                  245
     16#define FIXME_BUG__LIBRARY_EXIT_NO_THEME          244
     17#define FIXME_BUG__LIBRARY_EXIT_TFW_FAILED_OPEN   243
     18#define GENERIC_EXIT_START                        243
    1819#define GENERIC_EXIT_CMD_NOT_FOUND                127
    1920
    2021// libmyth
     
    3334#define FRONTEND_EXIT_DB_OUTOFDATE                GENERIC_EXIT_DB_OUTOFDATE
    3435#define FRONTEND_EXIT_DB_ERROR                    GENERIC_EXIT_DB_ERROR
    3536
     37#define FRONTEND_EXIT_INVALID_TIMEZONE            GENERIC_EXIT_INVALID_TIMEZONE
    3638#define FRONTEND_BUGGY_EXIT_NO_THEME              GENERIC_EXIT_NO_THEME
    3739#define FRONTEND_BUGGY_EXIT_NO_SELECTOR           GENERIC_EXIT_START-1
    3840#define FRONTEND_EXIT_START                       GENERIC_EXIT_START-1
     
    4244#define BACKEND_EXIT_NO_MYTHCONTEXT               GENERIC_EXIT_NO_MYTHCONTEXT
    4345#define BACKEND_EXIT_INVALID_CMDLINE              GENERIC_EXIT_INVALID_CMDLINE
    4446#define BACKEND_EXIT_DB_OUTOFDATE                 GENERIC_EXIT_DB_OUTOFDATE
     47#define BACKEND_EXIT_INVALID_TIMEZONE             GENERIC_EXIT_INVALID_TIMEZONE
    4548#define BACKEND_EXIT_OPENING_LOGFILE_ERROR        GENERIC_EXIT_OPENING_LOGFILE_ERROR
    4649#define BACKEND_EXIT_NO_CONNECT                   GENERIC_EXIT_START-1
    4750#define BACKEND_EXIT_NO_IP_ADDRESS                GENERIC_EXIT_START-2
  • programs/mythbackend/main.cpp

    old new  
    782782        }
    783783    }
    784784
     785    if (!checkTimeZone())
     786    {
     787        // Check for different time zones, different offsets, different times
     788        VERBOSE(VB_IMPORTANT, "The time and/or time zone settings on this "
     789                "system do not match those in use on the master backend. "
     790                "Please ensure all frontend and backend systems are "
     791                "configured to use the same time zone and have the current "
     792                "time properly set.");
     793        VERBOSE(VB_IMPORTANT, "Unable to run with invalid time settings. "
     794                              "Exiting.");
     795        return BACKEND_EXIT_INVALID_TIMEZONE;
     796    }
    785797    if (!UpgradeTVDatabaseSchema(true, true))
    786798    {
    787799        VERBOSE(VB_IMPORTANT, "Couldn't upgrade database to new schema");
  • programs/mythfrontend/main.cpp

    old new  
    13011301    }
    13021302    setuid(getuid());
    13031303
     1304    if (!checkTimeZone())
     1305    {
     1306        // Check for different time zones, different offsets, different times
     1307        VERBOSE(VB_IMPORTANT, "The time and/or time zone settings on this "
     1308                "system do not match those in use on the master backend. "
     1309                "Please ensure all frontend and backend systems are "
     1310                "configured to use the same time zone and have the current "
     1311                "time properly set.");
     1312        VERBOSE(VB_IMPORTANT, "Unable to run with invalid time settings. "
     1313                              "Exiting.");
     1314        return FRONTEND_EXIT_INVALID_TIMEZONE;
     1315    }
    13041316    if (!UpgradeTVDatabaseSchema(upgradeAllowed))
    13051317    {
    13061318        VERBOSE(VB_IMPORTANT,
  • libs/libmyth/util.cpp

    old new  
    349349    return zone_id;
    350350}
    351351
     352/** \fn checkTimeZone()
     353 *  \brief Verifies the time zone settings on this system agree with those
     354 *         on the master backend
     355 */
     356bool checkTimeZone(void)
     357{
     358    if (gContext->IsMasterBackend())
     359        return true;
     360
     361    QStringList master_settings(QString("QUERY_TIME_ZONE"));
     362    if (!gContext->SendReceiveStringList(master_settings))
     363    {
     364        VERBOSE(VB_IMPORTANT, "Unable to determine master backend time zone "
     365                              "settings.  If those settings differ from local "
     366                              "settings, some functionality will fail.");
     367        return true;
     368    }
     369
     370    bool have_zone_IDs = true;
     371    QString master_time_zone_ID = master_settings[0];
     372    QString master_utc_offset = master_settings[1];
     373    QString master_time_string = master_settings[2];
     374    QString local_time_zone_ID = getTimeZoneID();
     375    QString local_utc_offset = format_utc_offset();
     376    QDateTime local_time = mythCurrentDateTime();
     377
     378    if (master_time_zone_ID == "UNDEF")
     379    {
     380        VERBOSE(VB_IMPORTANT, "Unable to determine master backend time zone "
     381                              "settings. If local time zone settings differ "
     382                              "from master backend settings, some "
     383                              "functionality will fail.");
     384        have_zone_IDs = false;
     385    }
     386    if (local_time_zone_ID == "UNDEF")
     387    {
     388        VERBOSE(VB_IMPORTANT, "Unable to determine local time zone settings. "
     389                              "If local time zone settings differ from "
     390                              "master backend settings, some functionality "
     391                              "will fail.");
     392        have_zone_IDs = false;
     393    }
     394
     395    if (have_zone_IDs && (master_time_zone_ID != local_time_zone_ID))
     396    {
     397        VERBOSE(VB_IMPORTANT, "Time zone settings on the master backend "
     398                              "differ from those on this system.");
     399        VERBOSE(VB_IMPORTANT, QString("Detected time zone settings:\n"
     400                "Zone ID: Master: '%1'. Local: '%2'.\n"
     401                "UTC Offset: Master: '%3'. Local: '%4'.\n"
     402                "Current Time: Master: '%5'. Local: '%6'")
     403                .arg(master_time_zone_ID).arg(local_time_zone_ID)
     404                .arg(master_utc_offset).arg(local_utc_offset)
     405                .arg(master_time_string).arg(local_time.toString(Qt::ISODate)));
     406        return false;
     407    }
     408
     409    // Verify offset
     410    if (master_utc_offset == "UNDEF")
     411    {
     412        VERBOSE(VB_IMPORTANT, "Unable to determine master backend UTC "
     413                              "offset. If local time zone settings differ "
     414                              "from master backend settings, some "
     415                              "functionality will fail.");
     416    }
     417    else if (master_utc_offset != local_utc_offset)
     418    {
     419        VERBOSE(VB_IMPORTANT, "UTC offset on the master backend differs "
     420                              "from offset on this system.");
     421        VERBOSE(VB_IMPORTANT, QString("Detected time zone settings:\n"
     422                "Zone ID: Master: '%1'. Local: '%2'.\n"
     423                "UTC Offset: Master: '%3'. Local: '%4'.\n"
     424                "Current Time: Master: '%5'. Local: '%6'")
     425                .arg(master_time_zone_ID).arg(local_time_zone_ID)
     426                .arg(master_utc_offset).arg(local_utc_offset)
     427                .arg(master_time_string).arg(local_time.toString(Qt::ISODate)));
     428        return false;
     429    }
     430
     431    // Verify current time
     432    if (master_time_string == "UNDEF")
     433    {
     434        VERBOSE(VB_IMPORTANT, "Unable to determine current time on the master "
     435                              "backend . If local time or time zone settings "
     436                              "differ from those on the master backend, some "
     437                              "functionality will fail.");
     438    }
     439    else
     440    {
     441        QDateTime master_time = QDateTime::fromString(master_time_string,
     442                                                      Qt::ISODate);
     443        if (abs(master_time.secsTo(local_time)) > 300)
     444        {
     445            VERBOSE(VB_IMPORTANT, "Current time on the master backend "
     446                                  "differs from time on this system.");
     447            VERBOSE(VB_IMPORTANT, QString("Detected time zone settings:\n"
     448                    "Zone ID: Master: '%1'. Local: '%2'.\n"
     449                    "UTC Offset: Master: '%3'. Local: '%4'.\n"
     450                    "Current Time: Master: '%5'. Local: '%6'")
     451                    .arg(master_time_zone_ID).arg(local_time_zone_ID)
     452                    .arg(master_utc_offset).arg(local_utc_offset)
     453                    .arg(master_time_string)
     454                    .arg(local_time.toString(Qt::ISODate)));
     455            return false;
     456        }
     457    }
     458
     459    return true;
     460}
     461
    352462/** \fn encodeLongLong(QStringList&,long long)
    353463 *  \brief Encodes a long for streaming in the MythTV protocol.
    354464 *
  • libs/libmyth/util.h

    old new  
    2626MPUBLIC int calc_utc_offset(void);
    2727MPUBLIC QString format_utc_offset(void);
    2828MPUBLIC QString getTimeZoneID(void);
     29MPUBLIC bool checkTimeZone(void);
    2930
    3031// This is necessary for GCC 3.3, which has llabs(long long)
    3132// but not abs(long long) or std::llabs(long long)