[OpenWrt-Devel] [PATCH] use NTP server received via DHCP
Bastian Bittorf
bittorf at bluebottle.com
Tue Dec 22 12:09:20 EST 2015
* amine ahd <amine.ahd at gmail.com> [22.12.2015 17:40]:
> + #get the list of ntp servers from DHCP using ubus.
> + ntpservers=`ubus call network.interface dump | grep "ntpserver" | cut -d":" -f2 | tr -d '"'`
remove the comment, it's obvious what you are doing.
when using comment, use a space e.g. # mycomment
when speaking with ubus/parsing json do this:
ubus list network.interface -> interfaces
. /usr/share/libubox/jshn.sh
json_load "$( ubus call network.interface.wan2 status )"
...
@jow: can you say more about that?
> validate_ntp_section ntp || {
> echo "validation failed"
> return 1
> @@ -22,12 +24,20 @@ start_service() {
>
> [ $enabled = 0 ] && return
>
> - [ -z "$server" ] && return
> + [ -z "$server" ] && [ "$ntpservers" == "" ] && return
please do
[ -z "$ntpservers" ]
> +handle_default_ntp_servers() {
> + local server="$1"
> + # append the server to the list
> + new_ntp_servers="$new_ntp_servers $server"
> +}
this comment also does not help 8-)
> +local proto=`uci get network.$INTERFACE.proto`
please use OpenWrt-style: "$(...)"
> +#get the list of ntp servers returned from DHCP, remote leading and trailing whitespaces as well as string quotes
> +dhcp_ntp_servers=`ubus call network.interface dump | grep "ntpserver" | cut -d":" -f2 | sed 's/\"//g;s/^[ \t]*//;s/[ \t]*$//'`
same as on top, dont parse JSON like this.
> +#get the current list of ntp servers in the running instance
> +current_ntp_servers=`ubus call service get_data '{"name":"sysntpd"}' | grep "ntp_servers" | cut -d":" -f2 | sed 's/\"//g;s/^[ \t]*//;s/[ \t]*$//'`
same as on top
bye, bastian
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
More information about the openwrt-devel
mailing list