From: Joe MacDonald <Joe_MacDonald@mentor.com>
To: <rongqing.li@windriver.com>
Cc: openembedded-devel@lists.openembedded.org
Subject: Re: [PATCH 2/2] ntp: get parameters from dhcp
Date: Thu, 30 Jul 2015 12:59:02 -0400 [thread overview]
Message-ID: <20150730165902.GE6457@mentor.com> (raw)
In-Reply-To: <1438050989-15233-2-git-send-email-rongqing.li@windriver.com>
[-- Attachment #1: Type: text/plain, Size: 4647 bytes --]
[[oe] [PATCH 2/2] ntp: get parameters from dhcp] On 15.07.28 (Tue 10:36) rongqing.li@windriver.com wrote:
> From: Li Wang <li.wang@windriver.com>
>
> the script ntp.sh is called by dhcp client,
> it can get some parameters from dhcp.
>
> Signed-off-by: Li Wang <li.wang@windriver.com>
> Signed-off-by: Roy Li <rongqing.li@windriver.com>
> ---
> meta-networking/recipes-support/ntp/files/ntp.sh | 61 ++++++++++++++++++++++
> meta-networking/recipes-support/ntp/ntp_4.2.8p2.bb | 5 ++
> 2 files changed, 66 insertions(+)
> create mode 100755 meta-networking/recipes-support/ntp/files/ntp.sh
>
> diff --git a/meta-networking/recipes-support/ntp/files/ntp.sh b/meta-networking/recipes-support/ntp/files/ntp.sh
> new file mode 100755
> index 0000000..ca53a97
> --- /dev/null
> +++ b/meta-networking/recipes-support/ntp/files/ntp.sh
> @@ -0,0 +1,61 @@
> +#!/bin/sh
> +#
> +# ntp.sh: dhclient-script plugin for NTP settings,
> +# place in /etc/dhcp/dhclient.d and 'chmod +x ntp.sh' to enable
> +#
> +# Copyright (C) 2008 Red Hat, Inc.
> +#
> +# This program is free software; you can redistribute it and/or modify
> +# it under the terms of the GNU General Public License as published by
> +# the Free Software Foundation; either version 2 of the License, or
> +# (at your option) any later version.
> +#
> +# This program is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program. If not, see <http://www.gnu.org/licenses/>.
> +#
> +# Author(s): David Cantrell <dcantrell@redhat.com>
> +# Miroslav Lichvar <mlichvar@redhat.com>
> +#
> +
> +CONF=/etc/ntp.conf
Same comment here about the hard-coded CONF location rather than having
it reflect ${sysconfdir}.
-J.
> +SAVECONF=${SAVEDIR}/${CONF##*/}.predhclient.${interface}
> +
> +ntp_replace_conf() {
> + echo "$1" | diff -q ${CONF} - > /dev/null 2>&1
> + if [ $? -eq 1 ]; then
> + echo "$1" > ${CONF}
> + if [ -x /sbin/restorecon ]; then
> + restorecon ${CONF} >/dev/null 2>&1
> + fi
> + service ntpd restart >/dev/null 2>&1
> + fi
> +}
> +
> +ntp_config() {
> + if [ ! "${PEERNTP}" = "no" ] && [ -n "${new_ntp_servers}" ] &&
> + [ -e ${CONF} ] && [ -d ${SAVEDIR} ]; then
> + local conf=$(grep -v '^server .* # added by /sbin/dhclient-script$' < ${CONF})
> +
> + conf=$(echo "$conf"
> + for s in ${new_ntp_servers}; do
> + echo "server ${s} ${NTPSERVERARGS} # added by /sbin/dhclient-script"
> + done)
> +
> + [ -f ${SAVECONF} ] || touch ${SAVECONF}
> + ntp_replace_conf "$conf"
> + fi
> +}
> +
> +ntp_restore() {
> + if [ -e ${CONF} ] && [ -f ${SAVECONF} ]; then
> + local conf=$(grep -v '^server .* # added by /sbin/dhclient-script$' < ${CONF})
> +
> + ntp_replace_conf "$conf"
> + rm -f ${SAVECONF}
> + fi
> +}
> diff --git a/meta-networking/recipes-support/ntp/ntp_4.2.8p2.bb b/meta-networking/recipes-support/ntp/ntp_4.2.8p2.bb
> index c54da43..b963584 100644
> --- a/meta-networking/recipes-support/ntp/ntp_4.2.8p2.bb
> +++ b/meta-networking/recipes-support/ntp/ntp_4.2.8p2.bb
> @@ -21,6 +21,7 @@ SRC_URI = "http://www.eecis.udel.edu/~ntp/ntp_spool/ntp4/ntp-4.2/ntp-${PV}.tar.g
> file://sntp.service \
> file://sntp \
> file://ntpd.list \
> + file://ntp.sh \
> "
>
> SRC_URI[md5sum] = "fa37049383316322d060ec9061ac23a9"
> @@ -93,6 +94,9 @@ do_install_append() {
>
> install -d ${D}${systemd_unitdir}/ntp-units.d
> install -m 0644 ${WORKDIR}/ntpd.list ${D}${systemd_unitdir}/ntp-units.d/60-ntpd.list
> +
> + install -d ${D}/${sysconfdir}/dhcp/dhclient.d
> + install -m 755 ${WORKDIR}/ntp.sh ${D}/${sysconfdir}/dhcp/dhclient.d/
> }
>
> PACKAGES += "ntpdate sntp ${PN}-tickadj ${PN}-utils"
> @@ -124,6 +128,7 @@ RSUGGESTS_${PN} = "iana-etc"
> FILES_${PN} = "${sbindir}/ntpd ${sysconfdir}/ntp.conf ${sysconfdir}/init.d/ntpd ${libdir} \
> ${NTP_USER_HOME} \
> ${systemd_unitdir}/ntp-units.d/60-ntpd.list \
> + ${sysconfdir}/dhcp/dhclient.d/ntp.sh \
> "
> FILES_${PN}-tickadj = "${sbindir}/tickadj"
> FILES_${PN}-utils = "${sbindir} ${datadir}/ntp/lib"
> --
> 2.1.4
>
--
-Joe MacDonald.
:wq
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 484 bytes --]
next prev parent reply other threads:[~2015-07-30 16:59 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-28 2:36 [PATCH 1/2] ypbind-mt: get parameters from dhcp rongqing.li
2015-07-28 2:36 ` [PATCH 2/2] ntp: " rongqing.li
2015-07-30 16:59 ` Joe MacDonald [this message]
2015-07-30 16:57 ` [PATCH 1/2] ypbind-mt: " Joe MacDonald
2015-07-31 1:04 ` Rongqing Li
2015-08-03 0:53 ` Joe MacDonald
2015-09-06 5:44 ` Rongqing Li
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150730165902.GE6457@mentor.com \
--to=joe_macdonald@mentor.com \
--cc=openembedded-devel@lists.openembedded.org \
--cc=rongqing.li@windriver.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox