summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNils Philippsen <nils@redhat.com>2012-10-22 10:13:31 (GMT)
committerNils Philippsen <nils@redhat.com>2012-10-22 12:30:16 (GMT)
commitbf4da651992bc62f5249527aa438d2dab031b924 (patch)
treea89a4aba08df13578cbcfd5fae9bd5ac7397904e
parentec8d57ac8cbd3c22e0dddc56f31fc012ff15e57f (diff)
downloadsystem-config-date-bf4da651992bc62f5249527aa438d2dab031b924.zip
system-config-date-bf4da651992bc62f5249527aa438d2dab031b924.tar.gz
system-config-date-bf4da651992bc62f5249527aa438d2dab031b924.tar.xz
read/write /etc/localtime as symbolic link (#824033)
only fall back to using /etc/sysconfig/clock if it is present
-rw-r--r--src/scdate/core/timezoneBackend.py69
-rw-r--r--src/timezone_map_gui.py5
2 files changed, 37 insertions, 37 deletions
diff --git a/src/scdate/core/timezoneBackend.py b/src/scdate/core/timezoneBackend.py
index b112c98..4367918 100644
--- a/src/scdate/core/timezoneBackend.py
+++ b/src/scdate/core/timezoneBackend.py
@@ -2,7 +2,7 @@
#
# timezoneBackend - provides the backend for system time zone calls
#
-# Copyright © 2001 - 2007, 2009 Red Hat, Inc.
+# Copyright © 2001 - 2007, 2009, 2012 Red Hat, Inc.
# Copyright © 2001 - 2004 Brent Fox <bfox@redhat.com>
# Tammy Fox <tfox@redhat.com>
#
@@ -26,7 +26,8 @@
# Nils Philippsen <nils@redhat.com>
import os
-from slip.util.files import linkorcopyfile
+from slip.util.files import (linkorcopyfile, symlink_atomically,
+ overwrite_safely)
def bool(val):
if val: return "true"
@@ -42,21 +43,13 @@ class timezoneBackend(object):
else:
utc = "true"
- linkorcopyfile (fromFile, "/etc/localtime")
+ symlink_atomically(fromFile, "/etc/localtime", force=True)
#Check to see if /var/spool/postfix/etc/localtime exists
if os.access("/var/spool/postfix/etc/localtime", os.F_OK) == 1:
#If it does, copy the new time zone file into the chroot jail
linkorcopyfile (fromFile, "/var/spool/postfix/etc/localtime")
- #Write info to the /etc/sysconfig/clock file
- f = open("/etc/sysconfig/clock", "w")
- f.write ("# The time zone of the system is defined by the contents of /etc/localtime.\n")
- f.write ("# This file is only for evaluation by system-config-date, do not rely on its\n")
- f.write ("# contents elsewhere.\n")
- f.write('ZONE="%s"\n' % timezone)
- f.close()
-
if self._adjtimeHasUTCInfo:
f = open("/etc/adjtime", "r")
l = f.readlines()
@@ -79,37 +72,43 @@ class timezoneBackend(object):
self.utc = asUtc
def __init__(self):
- self.tz = "America/New_York"
+ self.tz = None
self.utc = "false"
- path = '/etc/sysconfig/clock'
+ localtime = "/etc/localtime"
+ zoneinfo = "/usr/share/zoneinfo/" # must end with "/"
+ legacy_path = "/etc/sysconfig/clock"
lines = []
self._canHwClock = None
self._adjtimeHasUTCInfo = None
- if os.access(path, os.R_OK):
- fd = open(path, 'r')
+ if os.path.exists(localtime) and os.path.islink(localtime):
+ tzfile = os.path.realpath(localtime)
+ if tzfile.startswith(zoneinfo):
+ self.tz = tzfile[len(zoneinfo):].replace('_', ' ')
+
+ if not self.tz and os.access(legacy_path, os.R_OK):
+ fd = open(legacy_path, 'r')
lines = fd.readlines()
fd.close()
- else:
- #There's no /etc/sysconfig/clock file, so make one
- fd = open(path, 'w')
- fd.close
- pass
-
- try:
- for line in lines:
- line = line.strip ()
- if len (line) and line[0] == '#':
- continue
- try:
- tokens = line.split ("=")
- if tokens[0] == "ZONE":
- self.tz = tokens[1].replace ('"', '')
- self.tz = self.tz.replace ('_', ' ')
- except:
- pass
- except:
- pass
+
+ try:
+ for line in lines:
+ line = line.strip()
+ if len(line) and line[0] == '#':
+ continue
+ try:
+ tokens = line.split("=")
+ if tokens[0] == "ZONE":
+ self.tz = tokens[1].replace('"', '')
+ self.tz = self.tz.replace('_', ' ')
+ except:
+ pass
+ except:
+ pass
+
+ if not self.tz:
+ self.tz = "America/New York"
+
if os.access("/etc/adjtime", os.R_OK):
fd = open("/etc/adjtime", 'r')
lines = fd.readlines()
diff --git a/src/timezone_map_gui.py b/src/timezone_map_gui.py
index c6cebd9..c8e02e8 100644
--- a/src/timezone_map_gui.py
+++ b/src/timezone_map_gui.py
@@ -214,7 +214,8 @@ class TimezoneMap (gtk.VBox):
if entry.tz == default:
self.currentEntry = entry
if entry.tz == "America/New York":
- #In case the /etc/sysconfig/clock is messed up, use New York as default
+ # In case the /etc/localtime is messed up, use New York as
+ # default
self.fallbackEntry = entry
self.treeStore.set_sort_column_id (self.columns.TZSORT, gtk.SORT_ASCENDING)
@@ -604,7 +605,7 @@ class TimezoneMap (gtk.VBox):
self.markers[self.currentEntry.tz].show ()
if not entry:
- # If the value in /etc/sysconfig/clock is invalid, default to New York
+ # If the /etc/localtime symlink is invalid, default to New York
self.currentEntry = self.fallbackEntry
else:
self.currentEntry = entry