Skip to content

Commit e11ef4a

Browse files
committed
Read timezone from /etc/localtime
The previous /etc/timezone is not on the system, but written by xsconsole itself. It's more reasonable to read link from /etc/localtime. This is also consistent with XAPI's behavior. Signed-off-by: Changlei Li <[email protected]>
1 parent fe184d2 commit e11ef4a

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

XSConsoleData.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -844,15 +844,20 @@ def ReadTimezones(self):
844844
self.data['timezones']['cities'][localPath] = filePath
845845

846846
def UpdateFromTimezone(self):
847-
if os.path.isfile('/etc/timezone'):
848-
file = open('/etc/timezone')
849-
self.data['timezones']['current'] = file.readline().rstrip()
850-
file.close()
847+
# Read timezone from /etc/localtime symlink
848+
if os.path.islink('/etc/localtime'):
849+
target = os.readlink('/etc/localtime')
850+
zonePath = '/usr/share/zoneinfo/'
851+
parts = target.split(zonePath, 1)
852+
if len(parts) == 2:
853+
self.data['timezones']['current'] = parts[1]
851854

852855
def TimezoneSet(self, inTimezone):
853856
Auth.Inst().AssertAuthenticated()
854857
self.RequireSession()
855858
self.session.xenapi.host.set_timezone(self.host.opaqueref(), inTimezone)
859+
time.tzset()
860+
self.UpdateFromTimezone()
856861

857862
def CurrentTimeString(self):
858863
return getoutput('/bin/date -R')

0 commit comments

Comments
 (0)