[Buildroot] [PATCH 2/2] system: use Etc/UTC as default timezone

Yann E. MORIN yann.morin.1998 at free.fr
Mon Jul 3 19:22:10 UTC 2017


Even though no timezone implicitly means UTC, systemd is not all that
happy when it does not have a timezone set. This is all fine on a RW
filesystem because systemd will create a symlink on its own (to
Etc/UTC), but not so much on a RO filesystem, causing all kind of
issues at boot time (up to the point that the system is unusable).

We fix that by defaulting to using Etc/UTC when no timezone is set.

Signed-off-by: "Yann E. MORIN" <yann.morin.1998 at free.fr>
Cc: Richard Braun <rbraun at sceen.net>
Cc: Alexandre Belloni <alexandre.belloni at free-electrons.com>
Cc: Martin Bark <martin at barkynet.com>
Cc: Maxime Hadjinlian <maxime.hadjinlian at gmail.com>

---
Note: our packaging of systemd currently does not support running on a
RO filesystem. This patch is part of the on-going effort to make it so.
---
 package/tz/tz.mk         | 17 +++++++++--------
 package/tzdata/tzdata.mk | 19 ++++++++++---------
 system/Config.in         |  3 +--
 3 files changed, 20 insertions(+), 19 deletions(-)

diff --git a/package/tz/tz.mk b/package/tz/tz.mk
index 6b1f9f4d24..8043406979 100644
--- a/package/tz/tz.mk
+++ b/package/tz/tz.mk
@@ -7,7 +7,11 @@
 TZ_DEPENDENCIES = host-tzdata host-tzdump
 TZ_LICENSE = Public domain
 
+# If local time is not set, use Etc/UTC as a default.
 TZ_LOCALTIME = $(call qstrip,$(BR2_TARGET_LOCALTIME))
+ifeq ($(TZ_LOCALTIME),)
+TZ_LOCALTIME = Etc/UTC
+endif
 
 define TZ_BUILD_CMDS
 	(cd $(HOST_DIR)/usr/share/zoneinfo/posix/; \
@@ -25,15 +29,12 @@ define TZ_INSTALL_TARGET_CMDS
 		$(TARGET_DIR)/usr/share/zoneinfo/iso3166.tab
 	mkdir -p $(TARGET_DIR)/usr/share/zoneinfo/uclibc
 	cp -a $(@D)/output/* $(TARGET_DIR)/usr/share/zoneinfo/uclibc
-	if [ -n "$(TZ_LOCALTIME)" ]; then \
-		if [ ! -f $(TARGET_DIR)/usr/share/zoneinfo/uclibc/$(TZ_LOCALTIME) ]; then \
-			printf "Error: '%s' is not a valid timezone, check your BR2_TARGET_LOCALTIME setting\n" \
-				"$(TZ_LOCALTIME)"; \
-			exit 1; \
-		fi; \
-		cd $(TARGET_DIR)/etc; \
-		ln -sf ../usr/share/zoneinfo/uclibc/$(TZ_LOCALTIME) TZ; \
+	if [ ! -f $(TARGET_DIR)/usr/share/zoneinfo/uclibc/$(TZ_LOCALTIME) ]; then \
+		printf "Error: '%s' is not a valid timezone, check your BR2_TARGET_LOCALTIME setting\n" \
+			"$(TZ_LOCALTIME)"; \
+		exit 1; \
 	fi
+	ln -sf ../usr/share/zoneinfo/uclibc/$(TZ_LOCALTIME) $(TARGET_DIR)/etc/TZ
 endef
 
 $(eval $(generic-package))
diff --git a/package/tzdata/tzdata.mk b/package/tzdata/tzdata.mk
index 802d8479a3..84ac564410 100644
--- a/package/tzdata/tzdata.mk
+++ b/package/tzdata/tzdata.mk
@@ -24,7 +24,11 @@ else
 TZDATA_ZONELIST = $(call qstrip,$(BR2_TARGET_TZ_ZONELIST))
 endif
 
+# If local time is not set, use Etc/UTC as a default.
 TZDATA_LOCALTIME = $(call qstrip,$(BR2_TARGET_LOCALTIME))
+ifeq ($(TZDATA_LOCALTIME),)
+TZDATA_LOCALTIME = Etc/UTC
+endif
 
 # No need to extract for target, we're using the host-installed files
 TZDATA_EXTRACT_CMDS =
@@ -36,16 +40,13 @@ define TZDATA_INSTALL_TARGET_CMDS
 	for zone in posix/*; do \
 	    ln -sfn "$${zone}" "$${zone##*/}"; \
 	done
-	if [ -n "$(TZDATA_LOCALTIME)" ]; then \
-	    if [ ! -f $(TARGET_DIR)/usr/share/zoneinfo/$(TZDATA_LOCALTIME) ]; then \
-	        printf "Error: '%s' is not a valid timezone, check your BR2_TARGET_LOCALTIME setting\n" \
-	               "$(TZDATA_LOCALTIME)"; \
-	        exit 1; \
-	    fi; \
-	    cd $(TARGET_DIR)/etc; \
-	    ln -sf ../usr/share/zoneinfo/$(TZDATA_LOCALTIME) localtime; \
-	    echo "$(TZDATA_LOCALTIME)" >timezone; \
+	if [ ! -f $(TARGET_DIR)/usr/share/zoneinfo/$(TZDATA_LOCALTIME) ]; then \
+		printf "Error: '%s' is not a valid timezone, check your BR2_TARGET_LOCALTIME setting\n" \
+			"$(TZDATA_LOCALTIME)"; \
+		exit 1; \
 	fi
+	ln -sf ../usr/share/zoneinfo/$(TZDATA_LOCALTIME) $(TARGET_DIR)/etc/localtime
+	echo "$(TZDATA_LOCALTIME)" >$(TARGET_DIR)/etc/timezone
 endef
 
 define HOST_TZDATA_BUILD_CMDS
diff --git a/system/Config.in b/system/Config.in
index b47ae43844..643c6f37f1 100644
--- a/system/Config.in
+++ b/system/Config.in
@@ -454,8 +454,7 @@ config BR2_TARGET_LOCALTIME
 	    Pacific/Wallis
 	    ...
 
-	  If empty, no local time will be set, and the dates will be
-	  expressed in UTC.
+	  If empty, the default is to use Etc/UTC as a localtime.
 
 endif # BR2_TARGET_TZ_INFO
 
-- 
2.11.0



More information about the buildroot mailing list