Skip to content
Snippets Groups Projects
Commit 5ddb2dba authored by Benjamin Drung's avatar Benjamin Drung
Browse files

Fix exit status 10 for invalid /etc/localtime symlinks

parent 201987e5
No related branches found
No related tags found
No related merge requests found
......@@ -79,6 +79,25 @@ class TestDebconf(unittest.TestCase):
stdout=subprocess.DEVNULL,
)
def test_broken_symlink(self) -> None:
"""Test pointing /etc/localtime to an invalid location."""
self._set_timezone(pathlib.Path("/bin/sh"))
self._reset_debconf()
self._call_dpkg_reconfigure()
self.assertEqual(self._get_timezone(), "Etc/UTC")
self.assertEqual(self._get_selection(), "Etc/UTC")
def test_broken_symlink_but_debconf_preseed(self) -> None:
"""Test broken /etc/localtime but existing debconf answers."""
self._set_timezone(pathlib.Path("/bin/sh"))
self._call_debconf_set_selections(
"tzdata tzdata/Areas select Pacific\n"
"tzdata tzdata/Zones/Pacific select Yap\n"
)
self._call_dpkg_reconfigure()
self.assertEqual(self._get_timezone(), "Pacific/Yap")
self.assertEqual(self._get_selection(), "Pacific/Yap")
def test_etc_localtime_precedes_debconf_preseed(self) -> None:
"""Test dpkg-reconfigure uses /etc/localtime over preseed."""
self._set_timezone("Asia/Jerusalem")
......
......@@ -298,44 +298,38 @@ elif [ -e "$DPKG_ROOT/etc/timezone" ]; then
fi
TIMEZONE="$(convert_timezone "$TIMEZONE")"
if [ -f "$DPKG_ROOT/usr/share/zoneinfo/$TIMEZONE" ] ; then
AREA="${TIMEZONE%%/*}"
ZONE="${TIMEZONE#*/}"
fi
# The timezone is already configured
if [ -L "$DPKG_ROOT/etc/localtime" ] ; then
# Don't ask the user, except if he/she explicitely asked that
if [ -z "$DEBCONF_RECONFIGURE" ] ; then
db_fset tzdata/Areas seen true
db_fset "tzdata/Zones/$AREA" seen true
fi
# The timezone has never been configured or is falsely configured
elif ! [ -L "$DPKG_ROOT/etc/localtime" ] || [ -n "$DEBCONF_RECONFIGURE" ] ; then
if [ -z "$AREA" ] || [ -z "$ZONE" ] ; then
RET=""
db_fget tzdata/Areas seen || RET=false
if [ "$RET" = true ] ; then
db_get tzdata/Areas
AREA=$RET
else
AREA="Etc"
fi
else
RET=""
db_fget tzdata/Areas seen || RET=false
if [ "$RET" = true ] ; then
db_get tzdata/Areas
AREA=$RET
else
AREA="Etc"
fi
RET=""
db_fget "tzdata/Zones/$AREA" seen || RET=false
if [ "$RET" = true ] ; then
db_get "tzdata/Zones/$AREA"
ZONE=$RET
else
ZONE="UTC"
fi
RET=""
db_fget "tzdata/Zones/$AREA" seen || RET=false
if [ "$RET" = true ] ; then
db_get "tzdata/Zones/$AREA"
ZONE=$RET
else
ZONE="UTC"
fi
db_fset tzdata/Areas seen false
db_fset "tzdata/Zones/$AREA" seen false
# The user want to handle the timezone by him/herself
else
exit 0
fi
# Initializes debconf default values from the ones found in
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment