<div dir="ltr">Hi,<div>Can you elaborate more on why you prefer uci state? I am just starting with OpenWRT and the first thing I found was procd.</div><div><br></div><div>Regards,</div><div>Amine.<br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Dec 24, 2015 at 2:35 PM, Yousong Zhou <span dir="ltr"><<a href="mailto:yszhou4tech@gmail.com" target="_blank">yszhou4tech@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi, amine<br>
<div><div class="h5"><br>
On 23 December 2015 at 00:00, amine ahd <<a href="mailto:amine.ahd@gmail.com">amine.ahd@gmail.com</a>> wrote:<br>
> The current state of NTP is to load the list of NTP servers<br>
> from the static file /etc/config/system.<br>
> This patch allows ntpd to get NTP servers from DHCP.<br>
> ntpd will restart whenever the list of NTP servers is changed.<br>
><br>
> Signed-off-by: amine hamed <<a href="mailto:amine.ahd@gmail.com">amine.ahd@gmail.com</a>><br>
> ---<br>
>  package/utils/busybox/Makefile             |  3 +++<br>
>  package/utils/busybox/files/sysntpd        | 15 +++++++++--<br>
>  .../package/utils/busybox/files/sysntpd.hotplug    | 31 ++++++++++++++++++++++<br>
>  3 files changed, 47 insertions(+), 2 deletions(-)<br>
>  create mode 100755 package/utils/busybox/files/sysntpd.hotplug<br>
><br>
> diff --git a/package/utils/busybox/Makefile b/package/utils/busybox/Makefile<br>
> index 9571d48..3c33246 100644<br>
> --- a/package/utils/busybox/Makefile<br>
> +++ b/package/utils/busybox/Makefile<br>
> @@ -112,6 +112,9 @@ define Package/busybox/install<br>
>         $(INSTALL_BIN) ./files/cron $(1)/etc/init.d/cron<br>
>         $(INSTALL_BIN) ./files/telnet $(1)/etc/init.d/telnet<br>
>         $(INSTALL_BIN) ./files/sysntpd $(1)/etc/init.d/sysntpd<br>
> +       $(INSTALL_DIR) $(1)/etc/hotplug.d<br>
> +       $(INSTALL_DIR) $(1)/etc/hotplug.d/iface<br>
> +       $(INSTALL_BIN) ./files/sysntpd.hotplug $(1)/etc/hotplug.d/iface/30-sysntpd<br>
>         $(INSTALL_BIN) ./files/ntpd-hotplug $(1)/usr/sbin/ntpd-hotplug<br>
>         -rm -rf $(1)/lib64<br>
>  endef<br>
> diff --git a/package/utils/busybox/files/sysntpd b/package/utils/busybox/files/sysntpd<br>
> index f73bb83..fbe1838 100755<br>
> --- a/package/utils/busybox/files/sysntpd<br>
> +++ b/package/utils/busybox/files/sysntpd<br>
> @@ -1,12 +1,12 @@<br>
>  #!/bin/sh /etc/rc.common<br>
>  # Copyright (C) 2011 OpenWrt.org<br>
><br>
> +. /lib/functions.sh<br>
>  START=98<br>
><br>
>  USE_PROCD=1<br>
>  PROG=/usr/sbin/ntpd<br>
>  HOTPLUG_SCRIPT=/usr/sbin/ntpd-hotplug<br>
> -<br>
>  validate_ntp_section() {<br>
>         uci_validate_section system timeserver "${1}" \<br>
>                 'server:list(host)' 'enabled:bool:1' 'enable_server:bool:0'<br>
> @@ -15,6 +15,8 @@ validate_ntp_section() {<br>
>  start_service() {<br>
>         local server enabled enable_server peer<br>
><br>
> +       #get the list of ntp servers from DHCP using ubus.<br>
> +       ntpservers=`ubus call network.interface dump | grep "ntpserver" | cut -d":" -f2 | tr -d '"'`<br>
<br>
</div></div>This can be done with help from jsonfilter<br>
<br>
        ubus call network.interface dump | jsonfilter -e<br>
'$["interface"][*]["data"]["ntpserver"]'<br>
<br>
It should also be possible for users to specify sources of timeserver<br>
settings, whether it be static list of servers in uci configs or dhcp<br>
settings from some network interfaces.<br>
<span class=""><br>
>         validate_ntp_section ntp || {<br>
>                 echo "validation failed"<br>
>                 return 1<br>
> @@ -22,12 +24,20 @@ start_service() {<br>
><br>
>         [ $enabled = 0 ] && return<br>
><br>
> -       [ -z "$server" ] && return<br>
> +       [ -z "$server" ] && [ "$ntpservers" == "" ] && return<br>
><br>
>         procd_open_instance<br>
>         procd_set_param command "$PROG" -n<br>
>         [ "$enable_server" = "1" ] && procd_append_param command -l<br>
>         [ -x "$HOTPLUG_SCRIPT" ] && procd_append_param command -S "$HOTPLUG_SCRIPT"<br>
> +<br>
> +       #add this data so we can use it in the sysntpd hotplug script.<br>
> +       procd_set_param data ntp_servers="$ntpservers $server"<br>
> +<br>
<br>
</span>Not quite sure about this, but are we going to replace uci_set_state<br>
with procd data param?  Personally I prefer uci state for such<br>
"dynamic" data store<br>
<br>
Regards,<br>
<br>
                yousong<br>
<div><div class="h5"><br>
> +       for ntpserver in $ntpservers; do<br>
> +               procd_append_param command -p $ntpserver<br>
> +       done<br>
> +<br>
>         for peer in $server; do<br>
>                 procd_append_param command -p $peer<br>
>         done<br>
> @@ -38,5 +48,6 @@ start_service() {<br>
>  service_triggers()<br>
>  {<br>
>         procd_add_reload_trigger "system"<br>
> +<br>
>         procd_add_validation validate_ntp_section<br>
>  }<br>
> diff --git a/package/utils/busybox/files/sysntpd.hotplug b/package/utils/busybox/files/sysntpd.hotplug<br>
> new file mode 100755<br>
> index 0000000..de2946a<br>
> --- /dev/null<br>
> +++ b/package/utils/busybox/files/sysntpd.hotplug<br>
> @@ -0,0 +1,31 @@<br>
> +#!/bin/sh<br>
> +<br>
> +. /lib/functions.sh<br>
> +<br>
> +[ "$ACTION" = ifup ] || exit 0<br>
> +<br>
> +handle_default_ntp_servers() {<br>
> +       local server="$1"<br>
> +       # append the server to the list<br>
> +       new_ntp_servers="$new_ntp_servers $server"<br>
> +}<br>
> +<br>
> +local proto=`uci get network.$INTERFACE.proto`<br>
> +<br>
> +#get the list of ntp servers returned from DHCP, remote leading and trailing whitespaces as well as string quotes<br>
> +dhcp_ntp_servers=`ubus call network.interface dump | grep "ntpserver" | cut -d":" -f2 | sed 's/\"//g;s/^[ \t]*//;s/[ \t]*$//'`<br>
> +<br>
> +new_ntp_servers="$dhcp_ntp_servers"<br>
> +<br>
> +#get the default list of ntp servers from the config file and append it to the new list<br>
> +config_load system<br>
> +config_list_foreach "ntp" "server" handle_default_ntp_servers<br>
> +<br>
> +#get the current list of ntp servers in the running instance<br>
> +current_ntp_servers=`ubus call service get_data '{"name":"sysntpd"}' | grep "ntp_servers" | cut -d":" -f2 | sed 's/\"//g;s/^[ \t]*//;s/[ \t]*$//'`<br>
> +<br>
> +#if its an up action, the iface uses DHCP and the new list of ntp servers is different from the old, restart sysntpd<br>
> +[ "$proto" == "dhcp" ]  && [ "$current_ntp_servers" != "$new_ntp_servers" ] || exit 0<br>
> +<br>
> +logger -t sysntpd "Reloading sysntpd due to $ACTION of interface $INTERFACE and a change of NTP servers"<br>
> +/etc/init.d/sysntpd enabled && /etc/init.d/sysntpd reload<br>
> \ No newline at end of file<br>
> --<br>
> 2.5.0<br>
</div></div>> _______________________________________________<br>
> openwrt-devel mailing list<br>
> <a href="mailto:openwrt-devel@lists.openwrt.org">openwrt-devel@lists.openwrt.org</a><br>
> <a href="https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel" rel="noreferrer" target="_blank">https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel</a><br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt;text-align:justify"><span style="font-size:12px;font-family:Verdana;color:#4d4f53;background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline">Amine Hamed</span><span style="font-size:12px;font-family:Verdana;color:#ff850c;background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline"> | Software Engineer</span></p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt;text-align:justify"><span style="font-size:12px;font-family:Verdana;color:#ff850c;background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline"><br></span></p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt;text-align:justify"><span style="font-size:11.333333333333332px;font-family:Verdana;color:#ff850c;background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline"> </span></p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt;text-align:justify"><span style="font-size:10px;font-family:Verdana;color:#ff9900;background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline"><img src="https://lh4.googleusercontent.com/8B5yxCEN2oollZXecK9eKNXuC75Ixe1z_o1_utaFMisiaEIuyeHpB1Ue751mhA10jB1AqcU3Jd7h1E5Pmg5FK6nNggia3w4xNbeeK7X1mISuaf8vdvLuhs4uFHyAHp0_=s1600" style="border:none" height="16px;" width="85px;"></span></p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt;text-align:justify"><br><span style="font-size:10px;font-family:Verdana;color:#ff9900;background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline"></span></p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt;text-align:justify"><span style="font-size:10px;font-family:Verdana;color:#4d4f53;background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline"> </span></p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt;text-align:justify"><span style="font-size:12px;font-family:Verdana;color:#4d4f53;background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline">Ocedo GmbH | Hirschstrasse 7 | 76133 Karlsruhe | Germany</span></p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt;text-align:justify"><span style="font-size:12px;font-family:Verdana;color:#4d4f53;background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline">Email</span><span style="font-size:12px;font-family:Verdana;color:#444444;background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline"> </span><span style="font-size:12px;font-family:Verdana;color:#ff850c;background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline"><a href="mailto:ahamed@ocedo.com" target="_blank">ahamed@ocedo.com</a></span></p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt;text-align:justify"><span style="font-size:12px;font-family:Verdana;color:#ff850c;background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline"><a href="mailto:ahamed@ocedo.com" target="_blank"><br></a></span></p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt;text-align:justify"><span style="font-size:9.333333333333332px;font-family:Verdana;color:#4d4f53;background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline"> </span></p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt;text-align:justify"><span style="font-size:9.333333333333332px;font-family:Verdana;color:#4d4f53;background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline">REGISTERED OFFICE: KARLSRUHE | DISTRICT COURT: MANNHEIM | REGISTER NUMBER: HRB 717873   </span></p><span style="font-size:9.333333333333332px;font-family:Verdana;color:#4d4f53;background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline">MANAGING DIRECTOR: MARKUS HENNIG|JAN HICHERT</span></div></div></div></div></div></div>
</div></div></div>