…offset does not match… exception when files exist that are meaningless to current platform
See original GitHub issueCurrently, the code in unix.py for get_localzone()
assumes that if any of several platform-specific files exists, then it is actually relevant and appropriate to use. That turns out to be a pretty unsafe assumption though.
It is very common, for instance, for a /etc/sysconfig/clock file to exist on a CentOS 7 system because someone assumed that what used to work on CentOS 6 (based on Sys-V) still applies to CentOS 7 (which is based on systemd) as well. If the system’s timezone is actually still UTC because that didn’t work, or if the system’s timezone is later changed to one that no longer matches what the junk /etc/sysconfig/clock file says, then calling get_localzone()
causes ValueError: Timezone offset does not match system offset: <value 1> != <value 2>. Please, check your config files.
I would be willing to work on a pull request to improve that.
My suggestion is to check whether the system is based on systemd
and to then only check either the files that are relevant for systemd
or those relevant to other init systems (Sys-V, etc.) If it is not possible to determine whether the system is based on systemd
, then check all files as we do now.
is_systemd = None
try:
init_ps = next(
(ps for ps in psutil.process_iter(['pid', 'name']) if ps.pid >= 1),
None)
if init_ps:
is_systemd = init_ps.name == 'systemd'
except Exception:
pass
This kind of implementation would require adding a dependency on the psutil
package. Another option would be to run the ps
command in a subprocess.
Issue Analytics
- State:
- Created 2 years ago
- Comments:11 (7 by maintainers)
Top GitHub Comments
And 4.0 is released, so I’m closing this.
Beta’s with this refactoring is out now.