Skip to content

Commit

Permalink
Fix TimeZone issue when static compile
Browse files Browse the repository at this point in the history
  • Loading branch information
pymumu committed Dec 14, 2019
1 parent 7746ecb commit 4db61f2
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
29 changes: 29 additions & 0 deletions package/openwrt/files/etc/init.d/smartdns
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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}
Expand Down
23 changes: 23 additions & 0 deletions package/optware/S50smartdns
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 4db61f2

Please sign in to comment.