From 4db61f2677eeb1479f3ee30aad2517296918ded4 Mon Sep 17 00:00:00 2001 From: Nick Peng Date: Sun, 23 Jun 2019 21:32:05 +0800 Subject: [PATCH] Fix TimeZone issue when static compile --- package/openwrt/files/etc/init.d/smartdns | 29 +++++++++++++++++++++++ package/optware/S50smartdns | 23 ++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/package/openwrt/files/etc/init.d/smartdns b/package/openwrt/files/etc/init.d/smartdns index 9e86325..4d29c98 100644 --- a/package/openwrt/files/etc/init.d/smartdns +++ b/package/openwrt/files/etc/init.d/smartdns @@ -126,6 +126,30 @@ conf_append() echo "$1 $2" >> $SMARTDNS_CONF_TMP } +get_tz() +{ + SET_TZ="" + + if [ -e "/etc/localtime" ]; then + return + fi + + for tzfile in /etc/TZ /var/etc/TZ + do + if [ ! -e "$tzfile" ]; then + continue + fi + + tz="`cat $tzfile 2>/dev/null`" + done + + if [ -z "$tz" ]; then + return + fi + + SET_TZ=$tz +} + load_server() { local section="$1" @@ -336,6 +360,11 @@ load_service() { procd_set_param limits core="unlimited" fi + get_tz + if [ ! -z "$SET_TZ" ]; then + procd_set_param env TZ="$SET_TZ" + fi + procd_set_param command /usr/sbin/smartdns -f -c $SMARTDNS_CONF $args if [ "$RESPAWN" = "1" ]; then procd_set_param respawn ${respawn_threshold:-3600} ${respawn_timeout:-5} ${respawn_retry:-5} diff --git a/package/optware/S50smartdns b/package/optware/S50smartdns index b2da4af..4d18aa0 100644 --- a/package/optware/S50smartdns +++ b/package/optware/S50smartdns @@ -234,6 +234,28 @@ clear_rule() fi } +get_tz() +{ + if [ -e "/etc/localtime" ]; then + return + fi + + for tzfile in /etc/TZ /var/etc/TZ + do + if [ ! -e "$tzfile" ]; then + continue + fi + + tz="`cat $tzfile 2>/dev/null`" + done + + if [ -z "$tz" ]; then + return + fi + + export TZ=$tz +} + case "$1" in start) set_rule @@ -242,6 +264,7 @@ case "$1" in fi set_smartdns_port + get_tz $SMARTDNS_BIN -c $SMARTDNS_CONF -p $SMARTDNS_PID if [ $? -ne 0 ]; then clear_rule